2015-02-01 13:57:57 +00:00
|
|
|
package tusd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
2015-10-01 17:40:56 +00:00
|
|
|
"errors"
|
2015-02-01 13:57:57 +00:00
|
|
|
)
|
|
|
|
|
2015-10-01 17:40:56 +00:00
|
|
|
// Error indicating that the data store has locked the file for further edits.
|
|
|
|
// This error is not a part of the official tus specification. Implementers of
|
|
|
|
// tusd.DataStore have the option to return this error to signal a file is
|
|
|
|
// locked for writing, and cannot be written to by another HTTP request.
|
|
|
|
var ErrFileLocked = errors.New("file currently locked")
|
|
|
|
|
2015-02-01 13:57:57 +00:00
|
|
|
type MetaData map[string]string
|
|
|
|
|
|
|
|
type FileInfo struct {
|
2015-03-23 16:58:13 +00:00
|
|
|
ID string
|
2015-02-01 15:17:56 +00:00
|
|
|
// Total file size in bytes specified in the NewUpload call
|
2015-02-03 18:01:22 +00:00
|
|
|
Size int64
|
2015-02-01 15:17:56 +00:00
|
|
|
// Offset in bytes (zero-based)
|
2015-02-01 13:57:57 +00:00
|
|
|
Offset int64
|
|
|
|
MetaData MetaData
|
2015-02-17 13:19:56 +00:00
|
|
|
// Indicates that this is a partial upload which will later be used to form
|
|
|
|
// a final upload by concatenation. Partial uploads should not be processed
|
|
|
|
// when they are finished since they are only incomplete chunks of files.
|
2015-02-17 14:44:12 +00:00
|
|
|
IsPartial bool
|
2015-02-17 13:19:56 +00:00
|
|
|
// Indicates that this is a final upload
|
2015-02-17 14:44:12 +00:00
|
|
|
IsFinal bool
|
2015-02-17 13:19:56 +00:00
|
|
|
// If the upload is a final one (see IsFinal) this will be a non-empty
|
|
|
|
// ordered slice containing the ids of the uploads of which the final upload
|
|
|
|
// will consist after concatenation.
|
|
|
|
PartialUploads []string
|
2015-02-01 13:57:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type DataStore interface {
|
2015-02-01 15:17:56 +00:00
|
|
|
// Create a new upload using the size as the file's length. The method must
|
|
|
|
// return an unique id which is used to identify the upload. If no backend
|
|
|
|
// (e.g. Riak) specifes the id you may want to use the uid package to
|
2015-02-16 16:53:50 +00:00
|
|
|
// generate one. The properties Size and MetaData will be filled.
|
|
|
|
NewUpload(info FileInfo) (id string, err error)
|
2015-02-01 15:17:56 +00:00
|
|
|
// Write the chunk read from src into the file specified by the id at the
|
|
|
|
// given offset. The handler will take care of validating the offset and
|
|
|
|
// limiting the size of the src to not overflow the file's size. It may
|
|
|
|
// return an os.ErrNotExist which will be interpretet as a 404 Not Found.
|
|
|
|
// It will also lock resources while they are written to ensure only one
|
|
|
|
// write happens per time.
|
2015-03-23 18:02:12 +00:00
|
|
|
// The function call must return the number of bytes written.
|
|
|
|
WriteChunk(id string, offset int64, src io.Reader) (int64, error)
|
2015-02-01 15:17:56 +00:00
|
|
|
// Read the fileinformation used to validate the offset and respond to HEAD
|
|
|
|
// requests. It may return an os.ErrNotExist which will be interpretet as a
|
|
|
|
// 404 Not Found.
|
2015-02-01 13:57:57 +00:00
|
|
|
GetInfo(id string) (FileInfo, error)
|
2015-02-06 21:05:33 +00:00
|
|
|
// Get an io.Reader to allow downloading the file. This feature is not
|
|
|
|
// part of the official tus specification. If this additional function
|
|
|
|
// should not be enabled any call to GetReader should return
|
|
|
|
// tusd.ErrNotImplemented. The length of the resource is determined by
|
|
|
|
// retrieving the offset using GetInfo.
|
2015-07-28 12:58:52 +00:00
|
|
|
// If the returned reader also implements the io.Closer interface, the
|
|
|
|
// Close() method will be invoked once everything has been read.
|
2015-02-06 21:05:33 +00:00
|
|
|
GetReader(id string) (io.Reader, error)
|
2015-02-28 13:47:39 +00:00
|
|
|
// Terminate an upload so any further requests to the resource, both reading
|
|
|
|
// and writing, must return os.ErrNotExist or similar.
|
|
|
|
Terminate(id string) error
|
2015-02-01 13:57:57 +00:00
|
|
|
}
|