filestore

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FileName

func FileName(filename string) func(*StoreFileParams) error

FileName provides an arbitrary file name to the NewStoreFileParams() method.

func Format

func Format(format string) func(*StoreFileParams) error

Format provides an arbitrary file format (e.g. json, txt) to the NewStoreFileParams() method.

Types

type FileInfo

type FileInfo struct {
	// The id by which the file can be accessed.
	ID string
	// The size of the file.
	Size int64
	// The file format (e.g. json, txt)
	Format string
	// The filename.
	Filename string
	// The MD5 of the file. May be nil if the backend service does not provide an MD5 - for
	// example many S3 upload methods. Always provided for a store file operation.
	MD5 *values.MD5
	// The time the file was stored.
	Stored time.Time
}

FileInfo contains information about a file.

type FileStore

type FileStore interface {
	// Store a file. In this case the MD5 is always provided.
	StoreFile(le *logrus.Entry, p *StoreFileParams) (*FileInfo, error)
	// Get a file by the ID of the file.
	// seek and length determine the byte range of the file returned.
	// Passing 0 for length implies the remainder of the file should be returned.
	// seeking beyond the file length will return an error, but requesting a file longer than the
	// actual length is accepted and will return the remainder of the file.
	// Returns NoFileError if there is no file by the given ID.
	GetFile(id string, seek uint64, length uint64) (*GetFileOutput, error)
	// DeleteFile deletes a file. Deleting a file that does not exist is not an error.
	DeleteFile(id string) error
	// CopyFile copies a file from one ID to another.
	// Returns NoFileError if there is no file by the source ID.
	CopyFile(sourceID string, targetID string) (*FileInfo, error)
}

FileStore an interface to a file storage system that allows storing and retrieving files by ID.

type GetFileOutput

type GetFileOutput struct {
	// The id by which the file can be accessed.
	ID string
	// The size of the file.
	Size int64
	// The file format (e.g. json, txt)
	Format string
	// The filename.
	Filename string
	// The MD5 of the file. May be nil if the backend service does not provide an MD5 - for
	// example many S3 upload methods.
	MD5 *values.MD5
	// The time the file was stored.
	Stored time.Time
	// The file's contents.
	Data io.ReadCloser
}

GetFileOutput the output when getting a file. The user is responsible for closing the reader.

type NoFileError

type NoFileError string

NoFileError is returned when a file that doesn't exist is requested.

func NewNoFileError

func NewNoFileError(err string) *NoFileError

NewNoFileError creates a new NoFileError.

func (*NoFileError) Error

func (e *NoFileError) Error() string

type S3FileStore

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

S3FileStore is a file store that stores files in an S3 API compatible storage system. It impelements FileStore.

func NewS3FileStore

func NewS3FileStore(
	s3client *s3.S3,
	minioClient *minio.Client,
	bucket string,
	httpClient *http.Client,
) (*S3FileStore, error)

NewS3FileStore creates a new S3 based file store. Files will be stored in the provided bucket, which will be created if it doesn't exist. The provided clients must have write privileges for the bucket. Three clients are currently required because they are better at different operations: s3client: an aws-sdk s3 client minioClient: a minio-go client httpClient: an http.Client client (used directly for faster PUTs) This may change in a future version if one client provides all the necessary operations.

func (*S3FileStore) CopyFile

func (fs *S3FileStore) CopyFile(sourceID string, targetID string) (*FileInfo, error)

CopyFile copies the file with the source ID to the target ID.

func (*S3FileStore) DeleteFile

func (fs *S3FileStore) DeleteFile(id string) error

DeleteFile deletes the file with the given ID. Deleting an ID that does not exist is not an error

func (*S3FileStore) GetBucket

func (fs *S3FileStore) GetBucket() string

GetBucket returns the bucket in which files are stored.

func (*S3FileStore) GetFile

func (fs *S3FileStore) GetFile(
	id string,
	seek uint64,
	length uint64,
) (out *GetFileOutput, err error)

GetFile Get a file by the ID of the file. seek and length determine the byte range of the file returned. Passing 0 for length implies the remainder of the file should be returned. seeking beyond the file length will return an error, but requesting a file longer than the actual length is accepted and will return the remainder of the file. The user is responsible for closing the reader.

func (*S3FileStore) StoreFile

func (fs *S3FileStore) StoreFile(le *logrus.Entry, p *StoreFileParams) (out *FileInfo, err error)

StoreFile stores a file.

type StoreFileParams

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

StoreFileParams input parameters for storing a file.

func NewStoreFileParams

func NewStoreFileParams(
	id string,
	size int64,
	data io.Reader,
	options ...func(*StoreFileParams) error) (*StoreFileParams, error)

NewStoreFileParams creates parameters for storing a file. The ID must be unique - providing the same ID twice will cause the file to be overwritten. To set the file format and name (both optional and arbitrary) use the Format() and FileName() functions in the options argument. The ID, format, and name will be whitespace-trimmed. The user is responsible for closing the reader, if closable.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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