Documentation
¶
Overview ¶
Package uploads receives a file from a client in chunks. A session carries the bytes; a purpose, registered by the feature that wants the file, owns the rules: how large it may be, where it is staged and what it must hold. The feature then takes the finished file by its upload ID.
Index ¶
- Constants
- Variables
- type Info
- type Manager
- func (m *Manager) Begin(purposeName, owner string, size int64, sha256Hex string) (Info, error)
- func (m *Manager) Cancel(id, owner string) error
- func (m *Manager) Chunk(id, owner string, offset int64, data []byte) (Info, error)
- func (m *Manager) Finish(id, owner string) (Info, error)
- func (m *Manager) Purpose(name string) (Purpose, bool)
- func (m *Manager) Ready(id, owner, purposeName string) error
- func (m *Manager) Register(purpose Purpose)
- func (m *Manager) Status(id, owner string) (Info, error)
- func (m *Manager) Take(id, owner, purposeName string, use func(path string) error) error
- type Purpose
Constants ¶
const ( // ChunkBytes is the largest chunk a session accepts, and the size a // client is told to send. ChunkBytes = 128 << 10 // MaxSessions caps the uploads in flight at once. MaxSessions = 4 // IdleTimeout ends a session no chunk or request has touched. IdleTimeout = 10 * time.Minute )
Variables ¶
var ( ErrUnknownPurpose = errors.New("unknown upload purpose") ErrTooLarge = errors.New("upload is larger than its purpose allows") ErrInvalidSize = errors.New("upload size must be greater than zero") ErrInvalidHash = errors.New("upload sha256 must be 64 hex characters") ErrTooManySessions = errors.New("too many uploads in progress") ErrNotFound = errors.New("upload not found") ErrWrongOffset = errors.New("chunk offset is not the next byte of the upload") ErrChunkTooLarge = errors.New("chunk is larger than the upload's chunk size") ErrEmptyChunk = errors.New("chunk is empty") ErrOverrun = errors.New("chunk runs past the upload's declared size") ErrIncomplete = errors.New("upload is not complete") ErrHashMismatch = errors.New("upload does not match its sha256") ErrFinished = errors.New("upload is already finished") ErrNotFinished = errors.New("upload is not finished") ErrWrongPurpose = errors.New("upload was made for another purpose") )
Functions ¶
This section is empty.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager holds the upload sessions of one Core process. Sessions live in memory: a restart ends them, and CleanStaging removes what they left.
func NewManager ¶
NewManager returns a manager with no purposes registered.
func (*Manager) Begin ¶
Begin opens a session for size bytes whose SHA-256 is sha256Hex. owner names the client; only it may continue the session.
func (*Manager) Chunk ¶
Chunk appends data at offset, which must be the next byte the session expects: chunks arrive in order, and a client that lost its place asks Status.
func (*Manager) Finish ¶
Finish checks a fully received upload against its size, its SHA-256 and its purpose's content rule. An upload that fails a check is discarded.
func (*Manager) Ready ¶
Ready reports whether Take would hand over the upload: a finished upload of owner for the given purpose. It does not use the upload up.
func (*Manager) Register ¶
Register adds a purpose and removes staging files a previous run left in its folder.
func (*Manager) Status ¶
Status reports a session, so a client that lost its connection can resume from Received.
type Purpose ¶
type Purpose struct {
// Validate checks a complete staged file before the upload may finish.
// Nil accepts any content.
Validate func(fs afero.Fs, path string) error
Name string
// StagingDir is where chunks are written. It should be on the volume the
// finished file will live on, so taking it is a rename.
StagingDir string
MaxBytes int64
// AdminOnly limits the purpose to local and admin clients. The API
// layer enforces it.
AdminOnly bool
}
Purpose is one kind of upload and its rules.