uploader

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2021 License: MIT Imports: 16 Imported by: 30

Documentation

Overview

Package uploader contains uploading files helpers.

Index

Constants

View Source
const (

	// `524288 % part_size = 0` (512KB must be evenly divisible by part_size)
	MaximumPartSize = 524288
)

https://core.telegram.org/api/files#uploading-files

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File interface {
	Name() string
	Stat() (os.FileInfo, error)

	io.Reader
	io.ReaderAt
}

File is file abstraction.

type Progress

type Progress interface {
	Chunk(ctx context.Context, state ProgressState) error
}

Progress is interface of upload process tracker.

type ProgressState

type ProgressState struct {
	Part     int
	PartSize int
	Uploaded int
	Total    int
}

ProgressState represents upload state change.

type Reader

type Reader interface {
	io.Reader
	io.ReaderAt
}

Reader is a file upload reader.

type Upload

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

Upload represents Telegram file upload.

func FromFile

func FromFile(f File) (*Upload, error)

FromFile creates new Upload struct using given File.

func FromPath

func FromPath(path string) (*Upload, error)

FromPath creates new Upload struct using given path.

func FromReader

func FromReader(name string, from io.Reader, total int64) *Upload

FromReader creates new Upload struct using given io.Reader. Note: Upload created with this builder will not be seekable, so upload can't be repeatable.

func NewUpload

func NewUpload(name string, from Reader, total int64) *Upload

NewUpload creates new Upload struct using given name and reader.

type Uploader

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

Uploader is Telegram file uploader.

func NewUploader

func NewUploader(rpc *tg.Client) *Uploader

NewUploader creates new Uploader.

func (*Uploader) Upload

func (u *Uploader) Upload(ctx context.Context, upload *Upload) (tg.InputFileClass, error)

Upload uploads data from Upload object.

func (*Uploader) WithIDGenerator

func (u *Uploader) WithIDGenerator(cb func() (int64, error)) *Uploader

WithIDGenerator sets id generator.

func (*Uploader) WithPartSize

func (u *Uploader) WithPartSize(partSize int) *Uploader

WithPartSize sets part size. Should be divisible by 1024. 524288 should be divisible by partSize.

See https://core.telegram.org/api/files#uploading-files.

func (*Uploader) WithProgress

func (u *Uploader) WithProgress(progress Progress) *Uploader

WithProgress sets progress callback.

func (*Uploader) WithThreads

func (u *Uploader) WithThreads(limit int) *Uploader

WithThreads sets uploading goroutines limit per upload.

Jump to

Keyboard shortcuts

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