Documentation ¶
Overview ¶
Package tus provides a client to tus protocol version 1.0.0.
tus is a protocol based on HTTP for resumable file uploads. Resumable means that an upload can be interrupted at any moment and can be resumed without re-uploading the previous data again. An interruption may happen willingly, if the user wants to pause, or by accident in case of an network issue or server outage (http://tus.io).
Index ¶
- Constants
- Variables
- type ChunkUploader
- type Client
- func (c *Client) CreateOrResumeUpload(u *Upload) (*Uploader, error)
- func (c *Client) CreateUpload(u *Upload) (*Uploader, error)
- func (c *Client) Do(req *http.Request) (*http.Response, error)
- func (c *Client) GetConfig() *Config
- func (c *Client) ResumeUpload(u *Upload) (*Uploader, error)
- func (c *Client) UploadChunck(url string, body io.Reader, size int64, offset int64) (int64, error)
- type ClientError
- type Config
- type Metadata
- type Store
- type Upload
- type Uploader
Constants ¶
const (
ProtocolVersion = "1.0.0"
)
Variables ¶
var ( ErrChuckSize = errors.New("chunk size must be greater than zero.") ErrNilLogger = errors.New("logger can't be nil.") ErrNilStore = errors.New("store can't be nil if Resume is enable.") ErrNilUpload = errors.New("upload can't be nil.") ErrLargeUpload = errors.New("upload body is to large.") ErrVersionMismatch = errors.New("protocol version mismatch.") ErrOffsetMismatch = errors.New("upload offset mismatch.") ErrUploadNotFound = errors.New("upload not found.") ErrResumeNotEnabled = errors.New("resuming not enabled.") ErrFingerprintNotSet = errors.New("fingerprint not set.") ErrUrlNotRecognized = errors.New("url not recognized") )
Functions ¶
This section is empty.
Types ¶
type ChunkUploader ¶
type ChunkUploader interface { GetConfig() *Config UploadChunck(url string, body io.Reader, size int64, offset int64) (int64, error) }
ChunkUploader is an interface that wraps the UploadChunck method. It includes the GetConfig() method as well.
type Client ¶
type Client struct { Config *Config Url string Version string Header http.Header // contains filtered or unexported fields }
Client represents the tus client. You can use it in goroutines to create parallels uploads.
func (*Client) CreateOrResumeUpload ¶
CreateOrResumeUpload resumes the upload if already created or creates a new upload in the server.
func (*Client) CreateUpload ¶
CreateUpload creates a new upload in the server.
func (*Client) ResumeUpload ¶
ResumeUpload resumes the upload if already created, otherwise it will return an error.
type ClientError ¶
func (ClientError) Error ¶
func (c ClientError) Error() string
type Config ¶
type Config struct { // ChunkSize divide the file into chunks. ChunkSize int64 // Resume enables resumable upload. Resume bool // OverridePatchMethod allow to by pass proxies sendind a POST request instead of PATCH. OverridePatchMethod bool // Store map an upload's fingerprint with the corresponding upload URL. // If Resume is true the Store is required. Store Store // Set custom header values used in all requests. Header http.Header // HTTP Client HttpClient *http.Client }
Config provides a way to configure the Client depending on your needs.
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig return the default Client configuration.
type Upload ¶
type Upload struct { Fingerprint string Metadata Metadata // contains filtered or unexported fields }
func NewUploadFromBytes ¶
NewUploadFromBytes creates a new upload from a byte array.
func NewUploadFromFile ¶
NewUploadFromFile creates a new Upload from an os.File.
func (*Upload) EncodedMetadata ¶
EncodedMetadata encodes the upload metadata.
type Uploader ¶
type Uploader struct { Client ChunkUploader // contains filtered or unexported fields }
func NewUploader ¶
func NewUploader(client ChunkUploader, url string, upload *Upload, offset int64) *Uploader
NewUploader creates a new Uploader.
func (*Uploader) Abort ¶
func (u *Uploader) Abort()
Abort aborts the upload process. It doens't abort the current chunck, only the remaining.
func (*Uploader) NotifyUploadProgress ¶
Subscribes to progress updates.
func (*Uploader) UploadChunck ¶
UploadChunck uploads a single chunck.