storagex

package
v0.1.73 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 7 Imported by: 6

Documentation

Overview

Package storagex extends cloud.google.com/go/storage.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bucket

type Bucket struct {
	*storage.BucketHandle
	// contains filtered or unexported fields
}

Bucket extends storage.BucketHandle operations.

func NewBucket

func NewBucket(b *storage.BucketHandle) *Bucket

NewBucket creates a new Bucket.

func (*Bucket) Dirs added in v0.1.21

func (b *Bucket) Dirs(ctx context.Context, prefix string) ([]string, error)

Dirs returns a slice of strings naming directories found at Prefix. Note: the root starts at "" (empty string) not "/".

func (*Bucket) Walk

func (b *Bucket) Walk(ctx context.Context, pathPrefix string, visit func(o *Object) error) error

Walk visits each GCS object under pathPrefix and calls visit with every object. The given pathPrefix may be a GCS object name, in which case Walk will visit only that object.

Example
ctx := context.Background()
client, err := storage.NewClient(ctx)
rtx.Must(err, "Failed to allocate storage.Client")

bucket := NewBucket(client.Bucket("your-bucket-name"))
bucket.Walk(ctx, "path/in/bucket", func(o *Object) error {
	fmt.Println(o.ObjectName(), o.LocalName())
	return nil
})
Output:

type Object

type Object struct {
	*storage.ObjectHandle
	*storage.ObjectAttrs
	// contains filtered or unexported fields
}

Object extends the storage.ObjectHandle operations on GCS Objects. Objects are generated during a Bucket.Walk.

func (*Object) Copy

func (o *Object) Copy(ctx context.Context, w io.Writer) error

Copy writes the Object data to the given writer.

func (*Object) LocalName

func (o *Object) LocalName() string

LocalName returns a path suitable for creating a local file. The local name may include path components because it is derived from the original GCS Object name with the original Walk pathPrefix removed. If the pathPrefix equals the GCS Object name (such as when pathPrefix is a single object), then the Object base name is returned.

Jump to

Keyboard shortcuts

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