uploader

package
v0.167.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 22 Imported by: 65 modules, 48 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package uploader contains uploading files helpers.

Index

Constants

View Source
const (

	// MaximumPartSize is maximum size of single part.
	MaximumPartSize = constant.UploadMaxPartSize
)

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

Variables

This section is empty.

Functions

This section is empty.

Types

type Client added in v0.24.0

type Client interface {
	UploadSaveFilePart(ctx context.Context, request *tg.UploadSaveFilePartRequest) (bool, error)
	UploadSaveBigFilePart(ctx context.Context, request *tg.UploadSaveBigFilePartRequest) (bool, error)
}

Client represents Telegram RPC client.

type File

type File interface {
	Stat() (os.FileInfo, error)
	io.Reader
}

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 {
	// ID of upload.
	ID int64
	// Name of uploading file.
	Name string
	// Part is an ID of uploaded part.
	Part int
	// PartSize is a size of uploaded part.
	PartSize int
	// Uploaded is a total sum of uploaded bytes.
	Uploaded int64
	// Total is a total size of uploading file.
	// May be equal to -1, in case when Upload created without size (stream upload).
	Total int64
}

ProgressState represents upload state change.

type Upload

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

Upload represents Telegram file upload.

func NewUpload

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

NewUpload creates new Upload struct using given name and reader. Set total to the remaining byte count, or -1 for a streaming upload of unknown size.

type Uploader

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

Uploader is Telegram file uploader.

func NewUploader

func NewUploader(rpc Client) *Uploader

NewUploader creates new Uploader.

func (*Uploader) FromBytes added in v0.26.0

func (u *Uploader) FromBytes(ctx context.Context, name string, b []byte) (tg.InputFileClass, error)

FromBytes uploads file from given byte slice.

func (*Uploader) FromFS added in v0.26.0

func (u *Uploader) FromFS(ctx context.Context, filesystem fs.FS, path string) (_ tg.InputFileClass, err error)

FromFS uploads file from fs using given path.

func (*Uploader) FromFile added in v0.23.0

func (u *Uploader) FromFile(ctx context.Context, f File) (tg.InputFileClass, error)

FromFile uploads given File. NB: FromFile does not close given file.

func (*Uploader) FromPath added in v0.23.0

func (u *Uploader) FromPath(ctx context.Context, path string) (tg.InputFileClass, error)

FromPath uploads file from given path.

func (*Uploader) FromReader added in v0.24.0

func (u *Uploader) FromReader(ctx context.Context, name string, f io.Reader) (tg.InputFileClass, error)

FromReader uploads the remaining bytes in f. For a bytes.Buffer, bytes.Reader or strings.Reader, the remaining length selects the small or big upload path. Other readers stream as inputFileBig, even when the file is small. Use Upload with NewUpload if the size of a different reader is known.

func (*Uploader) FromSource added in v0.38.0

func (u *Uploader) FromSource(ctx context.Context, src source.Source, rawURL string) (_ tg.InputFileClass, rerr error)

FromSource uses given source and URL to fetch data and upload it to Telegram.

func (*Uploader) FromURL added in v0.38.0

func (u *Uploader) FromURL(ctx context.Context, rawURL string) (_ tg.InputFileClass, rerr error)

FromURL uses given source to upload to Telegram.

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.

Setting part size explicitly disables automatic part size computation.

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) WithSource added in v0.38.0

func (u *Uploader) WithSource(src source.Source) *Uploader

WithSource sets URL resolver to use.

func (*Uploader) WithThreads

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

WithThreads sets how many parts of an upload are sent at a time.

By default, as many parts as fit into 8 MiB, like Telegram for Android (FileUploadOperation): the speed of an upload is about the bytes in flight divided by the round-trip time, so one part at a time over a connection with a ping of 100 ms gives at most 1 MiB/s with 128 KiB parts.

Directories

Path Synopsis
Package source contains remote source interface and implementations for uploader.
Package source contains remote source interface and implementations for uploader.

Jump to

Keyboard shortcuts

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