Commit d0cfeea0 authored by Eteri's avatar Eteri

erp5_wendelin: fix byte size calculation of data array

parent 81c776d0
...@@ -179,7 +179,6 @@ class DataArray(BigFile): ...@@ -179,7 +179,6 @@ class DataArray(BigFile):
ranges = HTTPRangeSupport.parseRange(range) ranges = HTTPRangeSupport.parseRange(range)
array = self.getArray() array = self.getArray()
factor = array.nbytes / array.shape[0]
if if_range is not None: if if_range is not None:
# Only send ranges if the data isn't modified, otherwise send # Only send ranges if the data isn't modified, otherwise send
...@@ -241,8 +240,10 @@ class DataArray(BigFile): ...@@ -241,8 +240,10 @@ class DataArray(BigFile):
'bytes %d-%d/%d' % (start, end - 1, self.getSize())) 'bytes %d-%d/%d' % (start, end - 1, self.getSize()))
RESPONSE.setStatus(206) # Partial content RESPONSE.setStatus(206) # Partial content
# convert ranges from bytes to array indices # convert array to bytes
RESPONSE.write(array[start/factor:end/factor].tobytes()) data = array[:].view('<b').reshape((-1,))[start:end].tobytes()
RESPONSE.setBody(data, lock=True)
else: else:
boundary = choose_boundary() boundary = choose_boundary()
...@@ -268,16 +269,19 @@ class DataArray(BigFile): ...@@ -268,16 +269,19 @@ class DataArray(BigFile):
draftprefix, boundary)) draftprefix, boundary))
RESPONSE.setStatus(206) # Partial content RESPONSE.setStatus(206) # Partial content
data = ''
for start, end in ranges: for start, end in ranges:
RESPONSE.write('\r\n--%s\r\n' % boundary) data = '{data}\r\n--{boundary}\r\n'\
RESPONSE.write('Content-Type: %s\r\n' % 'Content-Type: {content_type}\r\n'\
self.content_type) 'Content-Range: bytes {start:d}-{end:d}/{size:d}\r\n\r\n'\
RESPONSE.write( '{array}'.format(data=data,
'Content-Range: bytes %d-%d/%d\r\n\r\n' % ( boundary=boundary,
start, end - 1, self.getSize())) content_type=self.content_type,
start=start,
# convert ranges from bytes to array indices end=end-1,
RESPONSE.write(array[start/factor:end/factor].tobytes()) size=self.getSize(),
array=array[:].view('<b').reshape((-1,))[start:end].tobytes())
RESPONSE.write('\r\n--%s--\r\n' % boundary)
data = '{}\r\n--{}--\r\n'.format(data, boundary)
RESPONSE.setBody(data, lock=True)
return True return True
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment