objectstore

package module
v0.0.0-...-7fc7d99 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2019 License: AGPL-3.0 Imports: 10 Imported by: 0

README

objectstore

License Documentation Build Status Maintainability Test Coverage Go Report Card

An object store that supports local file system and Google Cloud Storage objects.

Documentation

Overview

Package objectstore provides an object store utility that supports local file system and Google Cloud Storage objects.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Object

type Object struct {
	ContentType     string
	ContentEncoding string
	// contains filtered or unexported fields
}

Object provides methods to create new Readers and Writers of an object. Use Store.NewObject to get an Object. ContentType and ContentEncoding must be set as desired before calling Object.NewReader or Object.NewWriter, in order to read and write properly, based on those attributes.

func (*Object) Delete

func (o *Object) Delete(ctx context.Context) error

Delete removes the object from storage.

func (*Object) NewReader

func (o *Object) NewReader(ctx context.Context) (*Reader, error)

NewReader creates a new Reader of Object's data, handling gzip decoding if applicable based on Object.ContentEncoding and storage behavior.

The caller must call Close on the returned Reader.

func (*Object) NewWriter

func (o *Object) NewWriter(ctx context.Context) (*Writer, error)

NewWriter creates a new Writer of Object's data, handling gzip encoding based on Object.ContentEncoding and setting Object.ContentType in storage, if applicable. Any existing data in the object will be truncated.

The caller must call Close on the returned Writer.

func (*Object) URL

func (o *Object) URL() *url.URL

URL returns the read-only url.URL of an Object.

type Option

type Option func(*Store)

Option is a function that modifies a Store during initialization.

func WithGCS

func WithGCS(cs *storage.Client) Option

WithGCS is an Option that adds Google Cloud Storage functionality to a Store using the passed client.

type Reader

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

Reader is a reader of Object data that meets the io.ReadCloser interface. Use Object.NewReader to get a Reader.

func (*Reader) Close

func (r *Reader) Close() error

Close closes the Reader. It must be called when done reading.

type Store

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

Store is used to initialize new Objects. Use New to get a Store.

Stores should be reused instead of created as needed. The methods of Store are safe for concurrent use by multiple goroutines.

func New

func New(opts ...Option) *Store

New is the Store initialization function.

func (*Store) NewObject

func (s *Store) NewObject(ctx context.Context, uri string) (*Object, error)

NewObject initializes a new Object from the Store. The uri extension is used to guess at the correct ContentType and ContentEncoding to set on the Object. If the uri scheme is empty, a local file system object is created.

type Writer

type Writer struct {
	io.Writer
	// contains filtered or unexported fields
}

Writer is a writer of Object data that meets the io.WriteCloser interface. Use Object.NewWriter to get a Writer.

func (*Writer) Close

func (w *Writer) Close() error

Close closes the Writer. It must be called when done writing and the returned error should be inspected to determine whether the write was successful.

Jump to

Keyboard shortcuts

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