chunkyUploads

package module
v0.0.0-...-a69bb48 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2021 License: MIT Imports: 13 Imported by: 0

README

Chunky Uploads

An abstraction layer for handling file uploads by breaking them up into chunks.

Documentation

Index

Constants

View Source
const (
	StatusUnkown Status = iota
	StatusUploading
	StatusCancelled
	StatusError
	StatusComplete
	StatusDeleted

	QueryOrderByUnknown QueryOrder = iota
	QueryOrderByStatus
	QueryOrderBySize
	QueryOrderByCreated
	QueryOrderByUpdated
	QueryOrderByDeleted
)

Variables

View Source
var (
	ErrIncompleteCopy = errors.New("failed to copy all the bytes")
	ErrStorageFull    = errors.New("storage is overwhelmed")
)
View Source
var (
	ErrContentTypeNotAllowed = errors.New("detected content type is not allowed")
)

Functions

This section is empty.

Types

type Chunk

type Chunk struct {
	UUID    UUID
	Hash    Hash
	Content []byte
}

type ChunkAttachment

type ChunkAttachment struct {
	File  UUID
	Chunk UUID
	Start int64
	End   int64
}

type ChunkRepository

type ChunkRepository interface {
	ChunkCreate(context.Context, *File, *Chunk) error
	ChunkRetrieve(context.Context, UUID) (*Chunk, error)
	ChunkDelete(context.Context, UUID) error

	ChunkAttachmentList(context.Context, UUID) ([]*ChunkAttachment, error)
	ChunkStorageUsage(context.Context) (uint64, error)
}

type ContentTypeDetector

type ContentTypeDetector func(io.ReadSeeker) (string, error)

ContentTypeDetector reads the head of a ReadSeeker and attempts to determine the underlying content type.

func NewContentTypeDetector

func NewContentTypeDetector(allowed ...string) ContentTypeDetector

NewContentTypeDetector returns a function that returns a content type, if it is in the allowed list. If the allowed list is `nil`, all content types are accepted. Inherits "application/octet-stream" as default.

type File

type File struct {
	UUID                            UUID
	Hash                            Hash
	Path                            string
	Title                           string
	Description                     string
	ContentType                     string
	Status                          Status
	Size                            int64
	CreatedAt, UpdatedAt, DeletedAt time.Time
}

type FileQuery

type FileQuery struct {
	Page       uint32
	PerPage    uint32
	OrderBy    QueryOrder
	Descending bool
	Status     Status
	Path       string
	Size       *Range
	CreatedAt  *Range
	UpdatedAt  *Range
	DeletedAt  *Range
}

type FileQueryResult

type FileQueryResult struct {
	Files             []*File
	Start, End, Total uint64
}

type FileRepository

type FileRepository interface {
	FileCreate(context.Context, *File) error
	FileRetrieve(context.Context, UUID) (*File, error)
	FileUpdate(context.Context, UUID, func(*File) error) error
	FileDelete(context.Context, UUID) error

	FileQuery(context.Context, *FileQuery) (*FileQueryResult, error)
}

type HTTPFileLocator

type HTTPFileLocator func(*http.Request) (*File, error)

type HTTPHandler

type HTTPHandler func(http.ResponseWriter, *http.Request) error

type Hash

type Hash []byte

type QueryOrder

type QueryOrder uint8

type Range

type Range struct{ Start, End int64 }

type Reader

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

func (*Reader) Close

func (r *Reader) Close() error

func (*Reader) Read

func (r *Reader) Read(b []byte) (n int, err error)

func (*Reader) Seek

func (r *Reader) Seek(offset int64, whence int) (n int64, err error)

SeekStart means relative to the start of the file, SeekCurrent means relative to the current offset, and SeekEnd means relative to the end. Seek returns the new offset relative to the start of the file and an error, if any.

type Status

type Status uint8

type UUID

type UUID []byte

type Uploads

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

func (*Uploads) Copy

func (u *Uploads) Copy(ctx context.Context, w io.Writer, uuid UUID) error

func (*Uploads) CopyRange

func (u *Uploads) CopyRange(ctx context.Context, w io.Writer, uuid UUID, ra Range) error

func (*Uploads) Delete

func (u *Uploads) Delete(ctx context.Context, file *File) error

func (*Uploads) Download

func (u *Uploads) Download(using HTTPFileLocator) HTTPHandler

func (*Uploads) FileByUUID

func (u *Uploads) FileByUUID() HTTPFileLocator

func (*Uploads) Reader

func (u *Uploads) Reader(ctx context.Context, file *File) (*Reader, error)

Reader satisfies ReadSeekCloser interface.

func (*Uploads) Save

func (u *Uploads) Save(ctx context.Context, f *File, r io.ReadSeeker) (err error)

func (*Uploads) Upload

func (u *Uploads) Upload(field string, sizeLimit int64) HTTPHandler

func (*Uploads) Writer

func (u *Uploads) Writer(ctx context.Context, file *File) (*writer, error)

Writer satisfies io.WriteCloser interface.

Directories

Path Synopsis
repositories
aes

Jump to

Keyboard shortcuts

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