Documentation ¶
Overview ¶
Package uploader contains uploading files helpers.
Index ¶
- Constants
- type Client
- type File
- type Progress
- type ProgressState
- type Upload
- type Uploader
- func (u *Uploader) FromBytes(ctx context.Context, name string, b []byte) (tg.InputFileClass, error)
- func (u *Uploader) FromFS(ctx context.Context, filesystem fs.FS, path string) (_ tg.InputFileClass, err error)
- func (u *Uploader) FromFile(ctx context.Context, f File) (tg.InputFileClass, error)
- func (u *Uploader) FromPath(ctx context.Context, path string) (tg.InputFileClass, error)
- func (u *Uploader) FromReader(ctx context.Context, name string, f io.Reader) (tg.InputFileClass, error)
- func (u *Uploader) FromSource(ctx context.Context, src source.Source, rawURL string) (_ tg.InputFileClass, rerr error)
- func (u *Uploader) FromURL(ctx context.Context, rawURL string) (_ tg.InputFileClass, rerr error)
- func (u *Uploader) Upload(ctx context.Context, upload *Upload) (tg.InputFileClass, error)
- func (u *Uploader) WithIDGenerator(cb func() (int64, error)) *Uploader
- func (u *Uploader) WithPartSize(partSize int) *Uploader
- func (u *Uploader) WithProgress(progress Progress) *Uploader
- func (u *Uploader) WithSource(src source.Source) *Uploader
- func (u *Uploader) WithThreads(threads int) *Uploader
Constants ¶
const ( // MaximumPartSize is maximum size of single part. MaximumPartSize = constant.UploadMaxPartSize )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
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 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.
type Uploader ¶
type Uploader struct {
// contains filtered or unexported fields
}
Uploader is Telegram file uploader.
func (*Uploader) FromFS ¶
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) FromReader ¶
func (u *Uploader) FromReader(ctx context.Context, name string, f io.Reader) (tg.InputFileClass, error)
FromReader uploads file from given io.Reader. NB: totally stream should not exceed the limit for small files (10 MB as docs says, may be a bit bigger).
func (*Uploader) FromSource ¶
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) WithIDGenerator ¶
WithIDGenerator sets id generator.
func (*Uploader) WithPartSize ¶
WithPartSize sets part size. Should be divisible by 1024. 524288 should be divisible by partSize.
func (*Uploader) WithProgress ¶
WithProgress sets progress callback.
func (*Uploader) WithSource ¶
WithSource sets URL resolver to use.
func (*Uploader) WithThreads ¶
WithThreads sets uploading goroutines limit per upload.