Documentation ¶
Overview ¶
Package bucket is a representation of a bucket endpoint.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bucket ¶
type Bucket interface { // Upload File(s) to the bucket. // // Implementor must check if File.Data() implements io.Closer and call Close() on it after the upload is complete. // // Whether the upload is successful or not, the implementor must call File.Close() on all files received. // // UploadResult.File must be filled with File of the same index and UploadResult.Error must be filled with error if // upload operation fails. // // The number of UploadResult must be the same as the number of files in the parameter. Upload(ctx context.Context, files []File) []UploadResult }
type File ¶
type File interface { Data() io.Reader Filename() string ContentType() string Read(p []byte) (n int, err error) Pretext() string Size() int Close() error }
func NewFile ¶
func NewFile(data io.Reader, mimetype string, opts ...FileOption) File
NewFile is a built-in constructor for File implementor.
if data implements io.Closer, it will be closed when the file is uploaded by the Bucket.
If WithFilename option is not provided, a randomly generated snowflake ID will be used.
if data is a reader that have method .Len() int it will be used to set the file size. (e.g. bytes.Buffer). Otherwise, the size will be set to -1. You may use WithFilesize to set the size manually.
type FileOption ¶
type FileOption interface {
// contains filtered or unexported methods
}
func WithFilename ¶
func WithFilename(filename string) FileOption
WithFilename sets the filename of the file. Default is a randomly generated snowflake ID.
func WithPretext ¶
func WithPretext(pretext string) FileOption
WithPretext sets a description for the file.
type FileOptionFunc ¶
type FileOptionFunc func(*file)
type LengthHint ¶
type LengthHint interface {
Len() int
}
type UploadResult ¶
type UploadResult struct { // The URL of the uploaded file, if successful. URL string // The file instance used to upload the file. // The body of this file may have already been garbage collected. // So do not consume this file content again and only use the remaining metadata. File File // If Error is not nil, the upload is considered failed. Error error }
Click to show internal directories.
Click to hide internal directories.