Skip to content

Commit

Permalink
Merge pull request #131 from RachelTucker/5_0_fix_buffer_overflow
Browse files Browse the repository at this point in the history
Making buffer size specifiable in get object command
  • Loading branch information
RachelTucker authored May 17, 2018
2 parents 96c6ee1 + 860be87 commit 966412b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions ds3/ds3.py
Original file line number Diff line number Diff line change
Expand Up @@ -8019,15 +8019,19 @@ def process_response(self, response):


class GetObjectResponse(AbstractResponse):

def __init__(self, response, request, buffer_size=None):
self.buffer_size = buffer_size
super(self.__class__, 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 @@ -11336,10 +11340,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 966412b

Please sign in to comment.