Documentation ¶
Overview ¶
Package sup provides helpers for streaming uploads and downloads of files.
Index ¶
Constants ¶
This section is empty.
Variables ¶
ErrFileNotFound is returned when a File is requested and can't be found.
ErrIncorrectSHA is returned when the assertion about a file's SHA doesn't match the contents of the file.
Functions ¶
func Download ¶
Download writes the file at the provided path inside the provided Storer to the provided io.Writer, returning an ErrFileNotFound error if the path does not exist inside the Storer.
If the provided io.Writer is also an io.WriteCloser, its Close method will be called by Download.
Types ¶
type File ¶
File represents an uploaded file.
func Upload ¶
func Upload(ctx context.Context, s Storer, source io.Reader, sha string, opts UploadOptions) (File, bool, error)
Upload performs a streaming upload of the data in the provided io.Reader, writing to the provided Storer with the provided SHA-256 hash. If the provided SHA-256 hash is exists in the Storer already, the File is returned, with the returned boolean set to false. If the hash does not exist in the provided Storer yet, the file is uploaded, and its File metadata returned, with the return boolean set to true.
If the provided UploadOptions has AcceptedMIMEs set, any file uploaded will have its MIME type checked, and only be accepted if its MIME matches one of the MIME types in AcceptedMIMEs.
If source is also an io.ReadCloser, its Close method will be called by Upload.
type Storer ¶
type Storer interface { Upload(ctx context.Context, sha string) (io.WriteCloser, error) Download(ctx context.Context, sha string) (io.ReadCloser, error) Delete(ctx context.Context, sha string) error Stat(ctx context.Context, sha string) (File, error) }
Storer represents a destination for uploaded files.