tusd

package module
v0.0.0-...-39f919c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2015 License: MIT Imports: 11 Imported by: 0

README

tusd

Build Status Build status

tusd is the official reference implementation of the tus resumable upload protocol.

This means it is meant for client authors to verify their implementations as well as server authors who may look at it for inspiration.

In the future tusd may be extended with additional functionality to make it suitable as a standalone production upload server, but for now this is not a priority.

Protocol version: 1.0.0

Getting started

Requirements:

  • Go (1.2 or newer)

Running tusd from source:

Clone the git repository and cd into it.

git clone git@github.com:tus/tusd.git
cd tusd

Now you can run tusd:

go run tusd/main.go

Running the testsuite

go test -v ./...

License

This project is licensed under the MIT license, see LICENSE.txt.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnsupportedVersion  = errors.New("unsupported version")
	ErrMaxSizeExceeded     = errors.New("maximum size exceeded")
	ErrInvalidEntityLength = errors.New("missing or invalid Entity-Length header")
	ErrInvalidOffset       = errors.New("missing or invalid Offset header")
	ErrNotFound            = errors.New("upload not found")
	ErrFileLocked          = errors.New("file currently locked")
	ErrIllegalOffset       = errors.New("illegal offset")
	ErrSizeExceeded        = errors.New("resource's size exceeded")
	ErrNotImplemented      = errors.New("feature not implemented")
	ErrUploadNotFinished   = errors.New("one of the partial uploads is not finished")
	ErrInvalidConcat       = errors.New("invalid Concat header")
	ErrModifyFinal         = errors.New("modifying a final upload is not allowed")
)

HTTP status codes sent in the response when the specific error is returned.

Functions

This section is empty.

Types

type Config

type Config struct {
	// DataStore implementation used to store and retrieve the single uploads.
	// Must no be nil.
	DataStore DataStore
	// MaxSize defines how many bytes may be stored in one single upload. If its
	// value is is 0 or smaller no limit will be enforced.
	MaxSize int64
	// BasePath defines the URL path used for handling uploads, e.g. "/files/".
	// If no trailing slash is presented it will be added. You may specify an
	// absolute URL containing a scheme, e.g. "http://tus.io"
	BasePath string
}

type DataStore

type DataStore interface {
	// 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. The properties Size and MetaData will be filled.
	NewUpload(info FileInfo) (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
	// 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)
	// 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.
	GetReader(id string) (io.Reader, error)
	// Terminate an upload so any further requests to the resource, both reading
	// and writing, must return os.ErrNotExist or similar.
	Terminate(id string) error
}

type FileInfo

type FileInfo struct {
	Id string
	// Total file size in bytes specified in the NewUpload call
	Size int64
	// Offset in bytes (zero-based)
	Offset   int64
	MetaData MetaData
	// 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.
	IsPartial bool
	// Indicates that this is a final upload
	IsFinal bool
	// 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
}

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

func NewHandler

func NewHandler(config Config) (*Handler, error)

Create a new handler using the given configuration.

func (*Handler) ServeHTTP

func (handler *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

Implement the http.Handler interface.

type MetaData

type MetaData map[string]string

Directories

Path Synopsis
FileStore is a storage backend used as a tusd.DataStore in tusd.NewHandler.
FileStore is a storage backend used as a tusd.DataStore in tusd.NewHandler.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL