Skip to content

Commit

Permalink
Updated get object to have specifiable buffer stream
Browse files Browse the repository at this point in the history
  • Loading branch information
RachelTucker committed May 17, 2018
1 parent 1ec096a commit 35b8dab
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions ds3/ds3.py
Original file line number Diff line number Diff line change
Expand Up @@ -8015,15 +8015,18 @@ def process_response(self, response):


class GetObjectResponse(AbstractResponse):
def __init__(self, response, request, buffer_size=None):
self.buffer_size = buffer_size
super(GetObjectResponse, self).__init__(response, request)

def process_response(self, response):
self.__check_status_codes__([200, 206])
stream = self.request.stream
try:
bytes_read = response.read()
bytes_read = response.read(self.buffer_size)
while bytes_read:
stream.write(bytes_read)
bytes_read = response.read()
bytes_read = response.read(self.buffer_size)
finally:
stream.close()
response.close()
Expand Down Expand Up @@ -11333,10 +11336,10 @@ def get_service(self, request):
raise TypeError('request for get_service should be of type GetServiceRequest but was ' + request.__class__.__name__)
return GetServiceResponse(self.net_client.get_response(request), request)

def get_object(self, request):
def get_object(self, request, buffer_size=1048576):
if not isinstance(request, GetObjectRequest):
raise TypeError('request for get_object should be of type GetObjectRequest but was ' + request.__class__.__name__)
return GetObjectResponse(self.net_client.get_response(request), request)
return GetObjectResponse(self.net_client.get_response(request), request, buffer_size)

def head_bucket(self, request):
if not isinstance(request, HeadBucketRequest):
Expand Down

0 comments on commit 35b8dab

Please sign in to comment.