From 3811b1dd5e1fafc69a3b018dcecc8751c9c22fd8 Mon Sep 17 00:00:00 2001 From: Arsham Arya Date: Tue, 25 Jun 2024 17:18:50 +0330 Subject: [PATCH] feat: download to writer for medias. --- bot.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/bot.go b/bot.go index 3062705a..1acefb71 100644 --- a/bot.go +++ b/bot.go @@ -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)