Documentation ¶
Overview ¶
Package blobstore implements a blob storage system with pluggable backends.
In most cases, users will want to use the gnd.la/app.App.Blobstore and gnd.la/app.Context.Blobstore helper methods to obtain a connection to the default blobstore. The default blobstore can be set using gnd.la/config.
There might be additional considerations for the backend you want to use. Please, see this package's subpackages for the available backends and the documentation about them.
File metadata must be a struct and is serialized using BSON. For more information about the BSON format and struct tags that you might use to control the serialization, see gnd.la/internal/bson.
Index ¶
- Variables
- type Blobstore
- func (s *Blobstore) Close() error
- func (s *Blobstore) Create() (*WFile, error)
- func (s *Blobstore) CreateId(id string) (*WFile, error)
- func (s *Blobstore) Driver() driver.Driver
- func (s *Blobstore) Iter() (Iter, error)
- func (s *Blobstore) Open(id string) (*RFile, error)
- func (s *Blobstore) ReadAll(id string) (data []byte, err error)
- func (s *Blobstore) Remove(id string) error
- func (s *Blobstore) Serve(w http.ResponseWriter, id string, rng *Range) error
- func (s *Blobstore) Store(b []byte, meta interface{}) (string, error)
- func (s *Blobstore) StoreId(id string, b []byte, meta interface{}) (string, error)
- type Iter
- type RFile
- func (r *RFile) Check() error
- func (r *RFile) Close() error
- func (r *RFile) GetMeta(meta interface{}) error
- func (r *RFile) Id() string
- func (r *RFile) Read(p []byte) (int, error)
- func (r *RFile) ReadAll() ([]byte, error)
- func (r *RFile) Seek(offset int64, whence int) (int64, error)
- func (r *RFile) Size() (uint64, error)
- type Range
- type WFile
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidMetadataHash indicates that the metadata hash // does not match the expected value and the file is likely // to be corrupted. ErrInvalidMetadataHash = errors.New("the metadata hash is invalid") // ErrInvalidDataHash indicates that the data hash // does not match the expected value and the file is likely // to be corrupted. ErrInvalidDataHash = errors.New("the data hash is invalid") )
var ( // ErrNotIterable indicates that the current blobstore driver // does not support iteration. ErrNotIterable = errors.New("the blobstore driver does not support iteration") )
Functions ¶
This section is empty.
Types ¶
type Blobstore ¶
type Blobstore struct {
// contains filtered or unexported fields
}
Blobstore represents a connection to a blobstore. Use New() to initialize a Blobsore and Blobstore.Close to close it.
func New ¶
New returns a new *Blobstore using the given url as its configure the URL scheme represents the driver used and the rest of the values in the URL are driver dependent. Please, see the package documentation for the available drivers and each driver sub-package for driver-specific documentation.
func (*Blobstore) Create ¶
Create returns a new file for writing and sets its metadata to meta (which might be nil). Note that the file should be closed by calling WFile.Close.
func (*Blobstore) CreateId ¶
CreateId works like Create, but uses the given id rather than generating a new one. If a file with the same id already exists, it's overwritten.
func (*Blobstore) Iter ¶
Iter returns an iterator which visits all the files available in the blobstore. If the underlying driver does not support iteration, (nil, ErrNotIterable) will be returned.
func (*Blobstore) Open ¶
Open opens the file with the given id for reading. Note that the file should be closed by calling RFile.Close after you're done with it.
func (*Blobstore) Serve ¶
Serve servers the given file by writing it to the given http.ResponseWriter. Some drivers might be able to serve the file directly from their backend. Otherwise, the file will be read from the blobstore and written to w. The rng parameter might be used for sending a partial response to the client.
type Iter ¶
type Iter interface { // Next returns true iff there iterator can fill // the provided string pointer with the next // file id. When the files have been returned, // without any errors, Next() should return false // and Err() should return nil. If the iteration // stopped due to an error, Err() should return // non-nil. Next(id *string) bool // Err() returns any error produced while // iterating the files. Err() error // Close closes the iterator. It must be called in // order to free its associated resources. Close() error }
Iter iterates over all the files available in the blobstore. Note that iteration order is undefined.
type RFile ¶
type RFile struct {
// contains filtered or unexported fields
}
RFile represents a blobstore file opened for reading.
func (*RFile) Check ¶
Check checks the integrity of both the data and the metadata in the file. If this function returns a non-nil error, the file should be considered corrupted.
func (*RFile) GetMeta ¶
GetMeta retrieves the file metadata, previously stored when writing the file, into the meta argument, which must be a pointer.
func (*RFile) Read ¶
Read reads from the file into the p buffer. This method implements the io.Reader interface.
type Range ¶
Range represents given byte range in a file. To obtain a Range from an incoming request, use ParseRange().
func ParseRange ¶
ParseRange returns a *Range from the given *http.Request if it has a well formed Range header, otherwise returns nil.
func (*Range) Set ¶
func (r *Range) Set(w http.ResponseWriter, total uint64)
Set sets the corresponding headers for this Range on the given http.ResponseWriter.
func (*Range) Size ¶
Size returns the number of bytes enclosed by this range. If the range is empty, it returns 0.
func (*Range) StatusCode ¶
StatusCode returns the HTTP response status code which should be using when serving a response with this range.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package chunk includes several data chunking algorithms.
|
Package chunk includes several data chunking algorithms. |
fixed
Package fixed implements a chunker which returns chunks of fixed size (except for the last one).
|
Package fixed implements a chunker which returns chunks of fixed size (except for the last one). |
Package driver includes the interfaces required to implement a blobstore driver.
|
Package driver includes the interfaces required to implement a blobstore driver. |
file
Package file implements the file driver for the blobstore.
|
Package file implements the file driver for the blobstore. |
gcs
Package gcs provides a Google Cloud Storage driver for the Blobstore.
|
Package gcs provides a Google Cloud Storage driver for the Blobstore. |
gridfs
Package gridfs implements a GridFS driver for the blobstore.
|
Package gridfs implements a GridFS driver for the blobstore. |
leveldb
Package leveldb implements the levelb driver for the blobstore.
|
Package leveldb implements the levelb driver for the blobstore. |
s3
Package s3 implements an s3 driver for the blobstore.
|
Package s3 implements an s3 driver for the blobstore. |