forked from mirrors/gotosocial
5318054808
* media processor consolidation and reformatting, reduce amount of required syscalls Signed-off-by: kim <grufwub@gmail.com> * update go-store library, stream jpeg/png encoding + use buffer pools, improved media processing AlreadyExists error handling Signed-off-by: kim <grufwub@gmail.com> * fix duration not being set, fix mp4 test expecting error Signed-off-by: kim <grufwub@gmail.com> * fix test expecting media files with different extension Signed-off-by: kim <grufwub@gmail.com> * remove unused code Signed-off-by: kim <grufwub@gmail.com> * fix expected storage paths in tests, update expected test thumbnails Signed-off-by: kim <grufwub@gmail.com> * remove dead code Signed-off-by: kim <grufwub@gmail.com> * fix cached presigned s3 url fetching Signed-off-by: kim <grufwub@gmail.com> * fix tests Signed-off-by: kim <grufwub@gmail.com> * fix test models Signed-off-by: kim <grufwub@gmail.com> * update media processing to use sync.Once{} for concurrency protection Signed-off-by: kim <grufwub@gmail.com> * shutup linter Signed-off-by: kim <grufwub@gmail.com> * fix passing in KVStore GetStream() as stream to PutStream() Signed-off-by: kim <grufwub@gmail.com> * fix unlocks of storage keys Signed-off-by: kim <grufwub@gmail.com> * whoops, return the error... Signed-off-by: kim <grufwub@gmail.com> * pour one out for tobi's code <3 Signed-off-by: kim <grufwub@gmail.com> * add back the byte slurping code Signed-off-by: kim <grufwub@gmail.com> * check for both ErrUnexpectedEOF and EOF Signed-off-by: kim <grufwub@gmail.com> * add back links to file format header information Signed-off-by: kim <grufwub@gmail.com> Signed-off-by: kim <grufwub@gmail.com>
54 lines
1.7 KiB
Go
54 lines
1.7 KiB
Go
package storage
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
)
|
|
|
|
// Storage defines a means of storing and accessing key value pairs
|
|
type Storage interface {
|
|
// ReadBytes returns the byte value for key in storage
|
|
ReadBytes(ctx context.Context, key string) ([]byte, error)
|
|
|
|
// ReadStream returns an io.ReadCloser for the value bytes at key in the storage
|
|
ReadStream(ctx context.Context, key string) (io.ReadCloser, error)
|
|
|
|
// WriteBytes writes the supplied value bytes at key in the storage
|
|
WriteBytes(ctx context.Context, key string, value []byte) (int, error)
|
|
|
|
// WriteStream writes the bytes from supplied reader at key in the storage
|
|
WriteStream(ctx context.Context, key string, r io.Reader) (int64, error)
|
|
|
|
// Stat checks if the supplied key is in the storage
|
|
Stat(ctx context.Context, key string) (bool, error)
|
|
|
|
// Remove attempts to remove the supplied key-value pair from storage
|
|
Remove(ctx context.Context, key string) error
|
|
|
|
// Close will close the storage, releasing any file locks
|
|
Close() error
|
|
|
|
// Clean removes unused values and unclutters the storage (e.g. removing empty folders)
|
|
Clean(ctx context.Context) error
|
|
|
|
// WalkKeys walks the keys in the storage
|
|
WalkKeys(ctx context.Context, opts WalkKeysOptions) error
|
|
}
|
|
|
|
// Entry represents a key in a Storage{} implementation,
|
|
// with any associated metadata that may have been set.
|
|
type Entry struct {
|
|
// Key is this entry's unique storage key.
|
|
Key string
|
|
|
|
// Size is the size of this entry in storage.
|
|
// Note that size < 0 indicates unknown.
|
|
Size int64
|
|
}
|
|
|
|
// WalkKeysOptions defines how to walk the keys in a storage implementation
|
|
type WalkKeysOptions struct {
|
|
// WalkFn is the function to apply on each StorageEntry
|
|
WalkFn func(context.Context, Entry) error
|
|
}
|