@@ -67,7 +67,10 @@ def _do_request(self, request, url, **kwargs):
67
67
return response .text
68
68
else :
69
69
# This might be a file, so return it.
70
- return response .raw
70
+ if kwargs .get ('params' , {}).get ('raw' , True ):
71
+ return response .raw
72
+ else :
73
+ return response
71
74
72
75
def _request (self , method , endpoint , id = None , ** kwargs ):
73
76
"Handles retrying failed requests and error handling."
@@ -145,14 +148,19 @@ def upload(self, filename, fileobj):
145
148
arg = (filename , fileobj )
146
149
return self .post ('/path/data/' , file = arg )
147
150
148
- def download (self , file_to_be_downloaded ):
151
+ def download (self , file_to_be_downloaded , perform_download = True ):
149
152
""" file_to_be_downloaded is a file-like object that has already
150
153
been uploaded, you cannot download folders """
154
+ response = self .get (
155
+ '/path/data/' , file_to_be_downloaded , raw = False )
156
+ if not perform_download :
157
+ # The caller can decide how to process the download of the data
158
+ return response
159
+
151
160
# download uses shutil.copyfileobj to download, which copies
152
161
# the data in chunks
153
162
o = open (file_to_be_downloaded , 'wb' )
154
- return shutil .copyfileobj (self .get ('/path/data/' ,
155
- file_to_be_downloaded ), o )
163
+ return shutil .copyfileobj (response .raw , o )
156
164
157
165
def move (self , src_path , dst_path ):
158
166
# check destination folder for / at end
0 commit comments