gs

package
v0.1.26 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package gs provides a thin wrapper around the Google Cloud Storage client that mirrors the surface of the internal/azblob and internal/s3 packages, so that bbb can treat Google Cloud Storage as a first-class backend addressed via gs://bucket/object paths.

Index

Constants

View Source
const (
	// Scheme is the path prefix that identifies Google Cloud Storage paths.
	Scheme = "gs://"
)

Variables

This section is empty.

Functions

func CopyServerSide

func CopyServerSide(ctx context.Context, src, dst GSPath, _ int, sizeHint int64, onProgress func(copied, total int64)) error

CopyServerSide performs a server-side copy from src to dst within GCS using the rewrite API, which handles objects of any size. sizeHint, when > 0, avoids an attribute lookup. onProgress, when non-nil, receives (copied, total) updates.

func Delete

func Delete(ctx context.Context, gp GSPath) error

Delete removes a single object.

func DeletePrefix

func DeletePrefix(ctx context.Context, gp GSPath) error

DeletePrefix deletes every object under the path's prefix.

func DownloadFile

func DownloadFile(ctx context.Context, gp GSPath, file *os.File, concurrency int, onProgress func(int64)) (int64, error)

DownloadFile downloads the object into file using parallel ranged reads (a single full read for gzip-encoded objects), returning the bytes written.

func DownloadStream

func DownloadStream(ctx context.Context, gp GSPath) (io.ReadCloser, error)

DownloadStream opens the object for streaming reads.

func Endpoint

func Endpoint() string

Endpoint returns the configured custom GCS endpoint (BBB_GS_ENDPOINT or STORAGE_EMULATOR_HOST), or an empty string when targeting Google Cloud.

func HeadObject

func HeadObject(ctx context.Context, gp GSPath) (int64, error)

HeadObject returns the size of the object, or an error if it does not exist.

func ListRecursiveStream

func ListRecursiveStream(ctx context.Context, gp GSPath, cb func(ObjectMeta) error) error

ListRecursiveStream lists every object under the path (no delimiter), invoking cb with the object name relative to the path prefix.

func ListStream

func ListStream(ctx context.Context, gp GSPath, cb func(ObjectMeta) error) error

ListStream lists the immediate children (objects and virtual directories) under the path, invoking cb for each. Directories are reported with a trailing '/'.

func MkBucket

func MkBucket(ctx context.Context, bucket string) error

MkBucket creates a bucket. Conflicts are preserved because read access to an existing bucket does not establish ownership in the requested project.

func Project

func Project() string

Project returns the Google Cloud project used for operations that require one (currently bucket creation).

func SetHTTPClient

func SetHTTPClient(c *http.Client)

SetHTTPClient installs a shared *http.Client used when talking to a custom endpoint (emulator). Against real Google Cloud Storage the SDK builds its own authenticated client on top of http.DefaultTransport, which bbb already replaces with the DNS-pinning/logging transport, so the override is only needed for unauthenticated endpoints. Passing nil clears the override. It must be called before the client is first constructed.

func Touch

func Touch(ctx context.Context, gp GSPath) error

Touch creates an empty object at the path.

func UploadFile

func UploadFile(ctx context.Context, gp GSPath, file *os.File, _ int, onProgress func(int64)) error

UploadFile uploads a local file to the object, reporting cumulative bytes via onProgress.

func UploadStream

func UploadStream(ctx context.Context, gp GSPath, reader io.Reader, _ int) error

UploadStream uploads the contents of reader to the object. GCS commits a single resumable upload session per object, so concurrency is accepted for API symmetry with the other backends but unused.

Types

type GSPath

type GSPath struct {
	Bucket string
	Object string // may be empty or end with '/' for a virtual directory
}

GSPath represents a gs:// path (bucket/object).

func Parse

func Parse(raw string) (GSPath, error)

Parse parses a gs://bucket[/object] path.

func (GSPath) Child

func (p GSPath) Child(rel string) GSPath

Child returns the path of a relative child of this path.

func (GSPath) IsDirLike

func (p GSPath) IsDirLike() bool

IsDirLike reports whether the path refers to a bucket root or a virtual directory (empty object name or one ending in '/').

func (GSPath) String

func (p GSPath) String() string

String renders the path back into its gs://bucket/object form.

func (GSPath) WithDir

func (p GSPath) WithDir() GSPath

WithDir returns a copy of the path whose object name is guaranteed to end with '/'.

type ObjectMeta

type ObjectMeta struct {
	Name string
	Size int64
}

ObjectMeta is minimal object metadata used for listing.

func List

func List(ctx context.Context, gp GSPath) ([]ObjectMeta, error)

List returns the immediate children under the path.

Jump to

Keyboard shortcuts

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