Documentation ¶
Index ¶
- Variables
- func AddFileIndexes(catalog *coal.Catalog)
- func DownloadTo(download Download, writer io.Writer) error
- func UploadFrom(upload Upload, reader io.Reader) (int64, error)
- type Blob
- type ClaimKey
- type CleanupJob
- type Download
- type File
- type GridFS
- func (g *GridFS) Cleanup(_ context.Context) error
- func (g *GridFS) Delete(ctx context.Context, handle Handle) (bool, error)
- func (g *GridFS) Download(ctx context.Context, handle Handle) (Download, error)
- func (g *GridFS) Initialize(ctx context.Context) error
- func (g *GridFS) Prepare(_ context.Context) (Handle, error)
- func (g *GridFS) Upload(ctx context.Context, handle Handle, _ string) (Upload, error)
- type Handle
- type Link
- type Memory
- func (m *Memory) Cleanup(_ context.Context) error
- func (m *Memory) Delete(_ context.Context, handle Handle) (bool, error)
- func (m *Memory) Download(_ context.Context, handle Handle) (Download, error)
- func (m *Memory) Prepare(_ context.Context) (Handle, error)
- func (m *Memory) Upload(_ context.Context, handle Handle, contentType string) (Upload, error)
- type Service
- type State
- type Storage
- func (s *Storage) Claim(ctx context.Context, link *Link) error
- func (s *Storage) Cleanup(ctx context.Context, retention time.Duration) error
- func (s *Storage) CleanupTask(lifetime, timeout, periodicity, retention time.Duration) *axe.Task
- func (s *Storage) Decorate(link *Link) error
- func (s *Storage) Decorator(fields ...string) *fire.Callback
- func (s *Storage) Download(ctx context.Context, viewKey string) (Download, *File, error)
- func (s *Storage) DownloadAction() *fire.Action
- func (s *Storage) Release(ctx context.Context, link *Link) error
- func (s *Storage) Upload(ctx context.Context, contentType string, cb func(Upload) (int64, error)) (string, *File, error)
- func (s *Storage) UploadAction(limit int64) *fire.Action
- func (s *Storage) Validator(fields ...string) *fire.Callback
- type Upload
- type ViewKey
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidHandle = errors.New("invalid handle")
ErrInvalidHandle is returned if the provided handle is invalid.
var ErrNotFound = errors.New("not found")
ErrNotFound is returned if there is no blob for the provided handle.
var ErrUsedHandle = errors.New("used handle")
ErrUsedHandle is returned if the provided handle has already been used.
Functions ¶
func AddFileIndexes ¶ added in v0.26.0
AddFileIndexes will add files indexes to the specified catalog.
func DownloadTo ¶ added in v0.28.1
DownloadTo will download a blob to the provided writer.
Types ¶
type Blob ¶ added in v0.26.0
Blob may be used instead of a bytes slice for inline storage if the type needs be stored as well.
type ClaimKey ¶ added in v0.26.0
type ClaimKey struct { heat.Base `json:"-" heat:"fire/blaze.claim,1h"` // The uploaded file. File coal.ID }
ClaimKey is used to authorize file claims.
type CleanupJob ¶ added in v0.28.0
type CleanupJob struct { axe.Base `json:"-" axe:"fire/blaze.cleanup"` stick.NoValidation }
CleanupJob is the periodic job enqueued to cleanup a storage.
type Download ¶ added in v0.28.1
type Download interface { // Seek(offset int64, whence int) (int64, error) Read(buf []byte) (int, error) Close() error }
Download handles the download of a blob.
type File ¶ added in v0.26.0
type File struct { coal.Base `json:"-" bson:",inline" coal:"files"` // The current state of the file e.g. "uploading". State State `json:"state"` // The last time the file was updated. Updated time.Time `json:"updated-at" bson:"updated_at"` // The MIME type of the file e.g. "image/png". Type string `json:"type"` // The total length of the file. Length int64 `json:"length"` // The service specific blob handle. Handle Handle `json:"handle"` }
File tracks uploaded files and their state.
type GridFS ¶ added in v0.26.0
type GridFS struct {
// contains filtered or unexported fields
}
GridFS stores blobs in a GridFs bucket.
func (*GridFS) Initialize ¶ added in v0.28.2
Initialize implements the Service interface.
type Handle ¶ added in v0.26.0
type Handle map[string]interface{}
Handle is a reference to a blob stored in a service.
type Link ¶ added in v0.26.0
type Link struct { // The type of the linked file. Type string `json:"type"` // The length of the linked file. Length int64 `json:"length"` // The key for claiming the linked file. ClaimKey string `json:"claim-key" bson:"-"` // The key for viewing the linked file. ViewKey string `json:"view-key" bson:"-"` // The reference to the linked file. File *coal.ID `json:"-" bson:"file_id"` }
Link is used to link a file to a model.
type Memory ¶ added in v0.26.0
Memory is a service for testing purposes that stores blobs in memory.
func NewMemory ¶ added in v0.26.0
func NewMemory() *Memory
NewMemory will create a new memory service.
type Service ¶ added in v0.26.0
type Service interface { // Prepare should return a new handle for uploading a blob. Prepare(ctx context.Context) (Handle, error) // Upload should initiate the upload of a blob. Upload(ctx context.Context, handle Handle, contentType string) (Upload, error) // Download should initiate the download of a blob. Download(ctx context.Context, handle Handle) (Download, error) // Delete should delete the blob. Delete(ctx context.Context, handle Handle) (bool, error) // Cleanup is called periodically and allows the service to cleanup its // storage until the context is cancelled. Cleanup(ctx context.Context) error }
Service is responsible for managing blobs.
type State ¶ added in v0.26.0
type State string
State describes the current state of a file. Usually, the state of a file always moves forward by one step but it may also jump directly to "deleting".
type Storage ¶ added in v0.26.0
type Storage struct {
// contains filtered or unexported fields
}
Storage provides file storage services.
func NewStorage ¶ added in v0.26.0
NewStorage creates a new storage.
func (*Storage) Claim ¶ added in v0.28.1
Claim will claim the provided link. The claimed link must be persisted in the same transaction as the claim to prevent loosing files.
func (*Storage) Cleanup ¶ added in v0.26.0
Cleanup will remove obsolete files and remove their blobs. Files in the states "uploading" or "uploaded" are removed after the specified retention which defaults to 1 hour if zero. Files in the states "released" and "deleting" are removed immediately. It will also allow the service to cleanup.
func (*Storage) CleanupTask ¶ added in v0.26.0
CleanupTask will return a periodic task that can be run to periodically cleanup obsolete files.
func (*Storage) Decorate ¶ added in v0.28.1
Decorate will populate the view key of the provided link if a file is available.
func (*Storage) Decorator ¶ added in v0.26.0
Decorator will generate view keys for all or just the specified link fields on the returned model or models.
func (*Storage) Download ¶ added in v0.28.1
Download will initiate a download for the file referenced by the provided view key.
func (*Storage) DownloadAction ¶ added in v0.26.0
DownloadAction returns an action that allows downloading files using view keys.
func (*Storage) Upload ¶ added in v0.28.1
func (s *Storage) Upload(ctx context.Context, contentType string, cb func(Upload) (int64, error)) (string, *File, error)
Upload will uploaded the provided stream using the configured service and return a claim key and the uploaded file.
func (*Storage) UploadAction ¶ added in v0.26.0
UploadAction returns an action that provides an upload service that stores files and returns claim keys.
type Upload ¶ added in v0.28.1
type Upload interface { // Resume() (int64, error) Write(data []byte) (int, error) // Suspend() (int64, error) Abort() error Close() error }
Upload handles the upload of a blob.