Skip to content

Instantly share code, notes, and snippets.

@Poolitzer
Created January 31, 2020 05:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Poolitzer/81051f87b614d5cd5f1953ab89e1d8cf to your computer and use it in GitHub Desktop.
Save Poolitzer/81051f87b614d5cd5f1953ab89e1d8cf to your computer and use it in GitHub Desktop.
Ever wanted to download something and send it via telegram without having to save it to a file? Fear not!
import io
def downloader(bot, url, timeout=None):
# if you receive a timeout error, pass an increasing timeout until you don't
buf = bot.request.retrieve(url, timeout=timeout)
# turning the byte stream into a file_like object without actually writing it to a file
file_like = io.BytesIO(buf)
# and returning it
return file_like
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment