package gcsfs

import "golang.org/x/build/internal/gcsfs"

gcsfs implements io/fs for GCS, adding writability.

Index

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.

Source Files

gcsfs.go osfs.go

Version
v0.0.0-20250421191922-3619c213cff3 (latest)
Published
Apr 21, 2025
Platform
linux/amd64
Imports
13 packages
Last checked
3 months ago

Tools for package owners.