tusd/datastore.go

36 lines
1.2 KiB
Go
Raw Normal View History

package tusd
import (
"io"
)
type MetaData map[string]string
type FileInfo struct {
2015-02-03 18:01:22 +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)
Offset int64
MetaData MetaData
}
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
// generate one.
NewUpload(size int64, metaData MetaData) (id string, err error)
// 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.
WriteChunk(id string, offset int64, src io.Reader) 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.
GetInfo(id string) (FileInfo, error)
}