X Tutup
Skip to content
Closed
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions telegram/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,13 @@ def download(self, custom_path=None):
filename = basename(url)

self.bot.request.download(url, filename)

def download_to(self, file_object):
"""
Args:
file_object (file-like):

"""
url = self.file_path

self.bot.request.download_to(url, file_object)
16 changes: 14 additions & 2 deletions telegram/utils/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,18 @@ def download(self, url, filename):
The filename within the path to download the file.

"""
buf = self._request_wrapper('GET', url)
with open(filename, 'wb') as fobj:
fobj.write(buf)
self.download_to(url, fobj)

def download_to(self, url, file_object):
"""Downloads a file by its URL using an existing file object.
Args:
url:
The web location we want to retrieve.

file_object:
A file-like object that supports write().

"""
buf = self._request_wrapper('GET', url)
file_object.write(buf)
X Tutup