Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: download to writer for medias. #704

Open
wants to merge 1 commit into
base: v3
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,25 @@ func (b *Bot) Download(file *File, localFilename string) error {
return nil
}

// DownloadToWriter stream the file from Telegram servers to an io.Writer interface,
// This can be used for cases that you want to get the file from one server,
// and directly upload it to another server without saving it locally.
// Maximum file size to download is 20 MB.
func (b *Bot) DownloadToWriter(file *File, writer io.Writer) error {
reader, err := b.File(file)
if err != nil {
return err
}
defer reader.Close()

_, err = io.Copy(writer, reader)
if err != nil {
return wrapError(err)
}

return nil
}

// File gets a file from Telegram servers.
func (b *Bot) File(file *File) (io.ReadCloser, error) {
f, err := b.FileByID(file.FileID)
Expand Down