Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrReadOnly = errors.New("read only")
var ErrWriteOnly = errors.New("write only")
Functions ¶
func Cleanup ¶
Cleanup removes the given file if it was a temporary file stored on disk that was created via a call to New.
func New ¶
New takes the given io.ReadCloser and turns it into an [io.fs.File] with the given name. The contents of the ReadCloser is read into memory. If the size of the data read exceeds 32MB, then a temporary file is created to store the contents. If the ReadCloser is actually an os.File, then no content is read, and the fs.File is returned with the given name.
Types ¶
type MaxSizeError ¶
type MaxSizeError int64
func (MaxSizeError) Error ¶
func (e MaxSizeError) Error() string
type Store ¶
type Store interface {
// Open opens the named file.
Open(name string) (fs.File, error)
// Put stores the given file in the underlying storage backend. This
// returns the newly stored file. The returned file should be reset to the
// starting position for reading.
Put(f fs.File) (fs.File, error)
// Stat returns the [io.fs.FileInfo] for the named file.
Stat(name string) (fs.FileInfo, error)
// Sub returns a new store correspodning with the named dir.
Sub(dir string) (Store, error)
// ReadDir reads the named directory and returns the list of entries.
ReadDir(name string) ([]fs.DirEntry, error)
// Remove the named file from the backend.
Remove(name string) error
}
Store represents a storage backend for a file.
This interface implements the [io.fs.FS], [io.fs.SubFS], [io.fs.ReadDirFS], and [io.fs.StatFS] interfaces.
func HashStore ¶
HashStore returns a stoe that will store all files against the given hash of their content.
Any sub stores returned via Sub will also have the files stored agains the given hash of their content.
func LimitedStore ¶
LimitedStore returns a store that limits the size of files put inside it to n bytes. If any file exceeds this limit then the MaxSizeError is returned.
Any sub stores returned via Sub will also have this limitation imposed upon them.
func ReadOnlyStore ¶
ReadOnlyStore returns a store that prevents any writing. Any calls to Put, or Remove will result in the ErrReadOnly error.
func UniqueStore ¶
UniqueStore returns a store that prevents duplicate files being stored in it. If a duplicate file is placed in the store, then the [io.fs.ErrExist] error is returned.
Any sub stores returned via Sub will also have this limitation imposed upon them.
func WriteOnlyStore ¶
WriteOnlyStore returns a store that prevents any reading. Any calls to Open, Stat, Sub, ReadDir, Remove, will result in the ErrWriteOnly error.