gs

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2018 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Google Cloud Storage VFS implementation.

See: https://github.com/GoogleCloudPlatform/google-cloud-go.

Index

Constants

View Source
const Scheme = "gs"

Scheme defines the filesystem type.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	// contains filtered or unexported fields
}

func (*File) Close

func (f *File) Close() (rerr error)

Close cleans up underlying mechanisms for reading from and writing to the file. Closes and removes the local temp file, and triggers a write to GCS of anything in the f.writeBuffer if it has been created.

func (*File) CopyToFile

func (f *File) CopyToFile(targetFile vfs.File) error

CopyToFile puts the contents of File into the targetFile passed. Uses the GCS CopierFrom method if the target file is also on GCS, otherwise uses io.Copy.

func (*File) CopyToLocation

func (f *File) CopyToLocation(location vfs.Location) (vfs.File, error)

CopyToLocation creates a copy of *File, using the file's current name as the new file's name at the given location. If the given location is also GCS, the GCS API for copying files will be utilized, otherwise, standard io.Copy will be done to the new file.

func (*File) Delete

func (f *File) Delete() error

Delete clears any local temp file, or write buffer from read/writes to the file, then makes a DeleteObject call to s3 for the file. Returns any error returned by the API.

func (*File) Exists

func (f *File) Exists() (bool, error)

Exists returns a boolean of whether or not the object exists in GCS.

func (*File) LastModified

func (f *File) LastModified() (*time.Time, error)

LastModified returns the 'Updated' property from the GCS attributes.

func (*File) Location

func (f *File) Location() vfs.Location

Location returns a Location instance for the file's current location.

TODO should this be including trailing slash?

func (*File) MoveToFile

func (f *File) MoveToFile(targetFile vfs.File) error

MoveToFile puts the contents of File into the targetFile passed using File.CopyToFile. If the copy succeeds, the source file is deleted. Any errors from the copy or delete are returned.

func (*File) MoveToLocation

func (f *File) MoveToLocation(location vfs.Location) (vfs.File, error)

MoveToLocation works by first calling File.CopyToLocation(vfs.Location) then, if that succeeds, it deletes the original file, returning the new file. If the copy process fails the error is returned, and the Delete isn't called. If the call to Delete fails, the error and the file generated by the copy are both returned.

func (*File) Name

func (f *File) Name() string

Name returns the file name.

func (*File) Path

func (f *File) Path() string

Path returns full path with leading slash of the GCS file key.

func (*File) Read

func (f *File) Read(p []byte) (n int, err error)

Read implements the standard for io.Reader. For this to work with an GCS file, a temporary local copy of the file is created, and reads work on that. This file is closed and removed upon calling f.Close()

func (*File) Seek

func (f *File) Seek(offset int64, whence int) (int64, error)

Seek implements the standard for io.Seeker. A temporary local copy of the GCS file is created (the same one used for Reads) which Seek() acts on. This file is closed and removed upon calling f.Close()

func (*File) Size

func (f *File) Size() (uint64, error)

LastModified returns the 'Size' property from the GCS attributes.

func (*File) String

func (f *File) String() string

String returns the file URI string.

func (*File) URI

func (f *File) URI() string

URI returns a full GCS URI string of the file.

func (*File) Write

func (f *File) Write(data []byte) (n int, err error)

Write implements the standard for io.Writer. A buffer is added to with each subsequent write. Calling Close() will write the contents back to GCS.

type FileSystem

type FileSystem struct {
	// contains filtered or unexported fields
}

FileSystem implements vfs.Filesystem for the GCS filesystem.

func NewFileSystem

func NewFileSystem(ctx context.Context, client *storage.Client) *FileSystem

NewFileSystem intializer for FileSystem struct accepts google cloud storage client and returns Filesystem or error.

func (*FileSystem) Name

func (fs *FileSystem) Name() string

Name returns "Google Cloud Storage"

func (*FileSystem) NewFile

func (fs *FileSystem) NewFile(volume string, name string) (vfs.File, error)

NewFile function returns the gcs implementation of vfs.File.

func (*FileSystem) NewLocation

func (fs *FileSystem) NewLocation(volume string, path string) (loc vfs.Location, err error)

NewLocation function returns the s3 implementation of vfs.Location.

func (*FileSystem) Scheme

func (fs *FileSystem) Scheme() string

Scheme return "gs" as the initial part of a file URI ie: gs://

type Location

type Location struct {
	// contains filtered or unexported fields
}

Implements vfs.Location

func (*Location) ChangeDir

func (l *Location) ChangeDir(relativePath string) error

ChangeDir changes the current location's path to the new, relative path.

func (*Location) DeleteFile

func (l *Location) DeleteFile(fileName string) error

DeleteFile deletes the file at the given path, relative to the current location.

func (*Location) Exists

func (l *Location) Exists() (bool, error)

Exists returns whether the location exists or not. In the case of an error, false is returned.

func (*Location) FileSystem

func (l *Location) FileSystem() vfs.FileSystem

FileSystem returns the GCS file system instance.

func (*Location) List

func (l *Location) List() ([]string, error)

List returns a list of file name strings for the current location.

func (*Location) ListByPrefix

func (l *Location) ListByPrefix(filenamePrefix string) ([]string, error)

ListByPrefix returns a slice of file base names and any error, if any prefix means filename prefix and therefore should not have slash List functions return only files List functions return only basenames

func (*Location) ListByRegex

func (l *Location) ListByRegex(regex *regexp.Regexp) ([]string, error)

ListByPrefix returns a list of file names at the location which match the provided regular expression.

func (*Location) NewFile

func (l *Location) NewFile(filePath string) (vfs.File, error)

NewFile returns a new file instance at the given path, relative to the current location.

func (*Location) NewLocation

func (l *Location) NewLocation(relativePath string) (vfs.Location, error)

NewLocation creates a new location instance relative to the current location's path.

func (*Location) Path

func (l *Location) Path() string

Path returns the path of the file at the current location, starting with a leading '/'

func (*Location) String

func (l *Location) String() string

String returns the full URI of the file.

func (*Location) URI

func (l *Location) URI() string

URI returns a URI string for the GCS file.

func (*Location) Volume

func (l *Location) Volume() string

Volume returns the GCS bucket name.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL