Skip to content

Commit 89a816a

Browse files
committed
Adds the download_to_path keyword argument to the download method.
Edits smartfile/__init__.py - Adds a download_to_path keyword argument to explicitly specify a path to write the downloaded file contents , if not given the file will be written under the CWD + the file to download name.
1 parent c04d475 commit 89a816a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

‎smartfile/__init__.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,19 @@ def upload(self, filename, fileobj):
148148
arg= (filename, fileobj)
149149
returnself.post('/path/data/', file=arg)
150150

151-
defdownload(self, file_to_be_downloaded, perform_download=True):
151+
defdownload(self, file_to_be_downloaded, perform_download=True, download_to_path=None):
152152
""" file_to_be_downloaded is a file-like object that has already
153153
been uploaded, you cannot download folders """
154154
response=self.get(
155155
'/path/data/', file_to_be_downloaded, raw=False)
156156
ifnotperform_download:
157157
# The caller can decide how to process the download of the data
158158
returnresponse
159-
159+
ifnotdownload_to_path:
160+
download_to_path=file_to_be_downloaded.split("/")[-1]
160161
# download uses shutil.copyfileobj to download, which copies
161162
# the data in chunks
162-
o=open(file_to_be_downloaded, 'wb')
163+
o=open(download_to_path, 'wb')
163164
returnshutil.copyfileobj(response.raw, o)
164165

165166
defmove(self, src_path, dst_path):

0 commit comments

Comments
(0)