gcsobj

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2024 License: MIT Imports: 5 Imported by: 7

README

Gcsobj - Seekable readers for Google Cloud Storage objects

Go Reference Go Report Card

This is gcsobj, a Go package that wraps the Reader type from cloud.google.com/go/storage, which implements only the io.Reader interface, to add a Seek method, satisfying the io.ReadSeeker interface.

Among other things, this makes Google Cloud Storage objects suitable for use with the standard Go http.ServeContent function.

Usage

bucket := gcsClient.Bucket(bucketName)
obj := bucket.Object(objName)
reader, err := gcsobj.NewReader(ctx, obj)
if err != nil { ... }
defer reader.Close()

// ...use reader as an io.ReadSeeker...

Documentation

Overview

Package gcsobj supplies a seekable Reader type for Google Cloud Storage objects.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Reader

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

Reader is an io.ReadSeeker for objects in Google Cloud Storage buckets.

func NewReader

func NewReader(ctx context.Context, obj *storage.ObjectHandle) (*Reader, error)

NewReader creates a new Reader on the given object. If the object size is already known, use NewReaderWithSize instead. Callers must call the Close method when finished with the Reader.

func NewReaderWithSize added in v0.2.0

func NewReaderWithSize(ctx context.Context, obj *storage.ObjectHandle, size int64) *Reader

NewReaderWithSize creates a new Reader on the given object. Use this in preference to NewReader when the object size is already known (e.g. from an earlier call to storage.ObjectHandle.Attrs). Callers must call the Close method when finished with the Reader.

func (*Reader) Close

func (r *Reader) Close() error

Close closes a Reader and releases its resources.

func (*Reader) NRead

func (r *Reader) NRead() int64

NRead reports the number of bytes that have been read from Reader. This is safe to call concurrently with Read.

func (*Reader) Read

func (r *Reader) Read(dest []byte) (int, error)

Read implements io.Reader.

func (*Reader) Seek

func (r *Reader) Seek(offset int64, whence int) (int64, error)

Seek implements io.Seeker.

Jump to

Keyboard shortcuts

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