Commit ee845653 authored by Klaus Wölfel's avatar Klaus Wölfel

array http range request: convert ranges to indexes instead of using byte view of array

reason: previous way did not work for all kind of arrays
parent 95322131
......@@ -138,8 +138,8 @@ class DataArray(BigFile):
if range is not None:
ranges = HTTPRangeSupport.parseRange(range)
# get byte view of array because we interpret ranges in bytes
data = self.getArray()[:].view("uint8").ravel()
array = self.getArray()
factor = array.nbytes / array.shape[0]
if if_range is not None:
# Only send ranges if the data isn't modified, otherwise send
......@@ -201,7 +201,8 @@ class DataArray(BigFile):
'bytes %d-%d/%d' % (start, end - 1, self.getSize()))
RESPONSE.setStatus(206) # Partial content
RESPONSE.write(data[start:end].tobytes())
# convert ranges from bytes to array indices
RESPONSE.write(array[start/factor:end/factor].tobytes())
else:
boundary = choose_boundary()
......@@ -235,7 +236,8 @@ class DataArray(BigFile):
'Content-Range: bytes %d-%d/%d\r\n\r\n' % (
start, end - 1, self.getSize()))
RESPONSE.write(data[start:end].tobytes())
# convert ranges from bytes to array indices
RESPONSE.write(array[start/factor:end/factor].tobytes())
RESPONSE.write('\r\n--%s--\r\n' % boundary)
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