gcsfs

package
v0.0.0-...-a705825 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

gcsfs implements io/fs for GCS, adding writability.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DirFS

func DirFS(dir string) fs.FS

DirFS is a variant of os.DirFS that supports file creation and is a suitable test fake for the GCS FS.

func FromURL

func FromURL(ctx context.Context, client *storage.Client, base string) (fs.FS, error)

FromURL creates a new FS from a file:// or gs:// URL. client is only used for gs:// URLs and can be nil otherwise.

func NewFS

func NewFS(ctx context.Context, client *storage.Client, bucket string) fs.FS

NewFS creates a new fs.FS that uses ctx for all of its operations. Creating a new FS does not access the network, so they can be created and destroyed per-context.

Once the context has finished, all objects created by this FS should be considered invalid. In particular, Writers and Readers will be canceled.

func WriteFile

func WriteFile(fsys fs.FS, filename string, contents []byte) error

WriteFile is like os.WriteFile for CreateFSs.

Types

type CreateFS

type CreateFS interface {
	fs.FS
	Create(string) (WriterFile, error)
}

CreateFS is an fs.FS that supports creating writable files.

type GCSFile

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

GCSFile implements fs.File for GCS. It is also a WriteFile.

func (*GCSFile) Close

func (f *GCSFile) Close() error

func (*GCSFile) Read

func (f *GCSFile) Read(b []byte) (int, error)

func (*GCSFile) ReadDir

func (f *GCSFile) ReadDir(n int) ([]fs.DirEntry, error)

ReadDir implements io/fs.ReadDirFile.

func (*GCSFile) Stat

func (f *GCSFile) Stat() (fs.FileInfo, error)

Stats the file. The returned FileInfo exposes *storage.ObjectAttrs as its Sys() result.

func (*GCSFile) Write

func (f *GCSFile) Write(b []byte) (int, error)

Write writes to the GCS object associated with this File.

A new object will be created unless an object with this name already exists. Otherwise any previous object with the same name will be replaced. The object will not be available (and any previous object will remain) until Close has been called.

type WriterFile

type WriterFile interface {
	fs.File
	io.Writer
}

WriterFile is an fs.File that can be written to. The behavior of writing and reading the same file is undefined.

func Create

func Create(fsys fs.FS, name string) (WriterFile, error)

Create creates a new file on fsys, which must be a CreateFS.

Jump to

Keyboard shortcuts

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