summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorMax Sperlich <max.sperlich@livingsocial.com>2013-12-08 17:57:25 -0500
committerMax Sperlich <max.sperlich@livingsocial.com>2013-12-08 17:57:25 -0500
commit3ba1d94e0b4f6665a594f5664c706782eda22d6e (patch)
tree4a8f1d477cdda47a2265d01ddbb108a61c0dedb4 /numpy
parent3aa76bac67882f29901640f73cdb1b9d9e0c9029 (diff)
downloadnumpy-3ba1d94e0b4f6665a594f5664c706782eda22d6e.tar.gz
BUG: fix loading from compressed .npz (Issue 4093)
In Python 2.6.x the number of bytes read from a zip file is 2^16, which is less than the 2^18 requested by lib.format.py. This change handles the case where fp.read() returns fewer than the requested number of bytes.
Diffstat (limited to 'numpy')
-rw-r--r--numpy/lib/format.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/numpy/lib/format.py b/numpy/lib/format.py
index 4ac1427b4..c667273bc 100644
--- a/numpy/lib/format.py
+++ b/numpy/lib/format.py
@@ -476,13 +476,16 @@ def read_array(fp):
max_read_count = BUFFER_SIZE // min(BUFFER_SIZE, dtype.itemsize)
array = numpy.empty(count, dtype=dtype)
-
- for i in range(0, count, max_read_count):
+ extra_data = ''
+ i = 0
+ while i < count:
read_count = min(max_read_count, count - i)
-
- data = fp.read(int(read_count * dtype.itemsize))
- array[i:i+read_count] = numpy.frombuffer(data, dtype=dtype,
- count=read_count)
+ data = extra_data + fp.read(int(read_count * dtype.itemsize))
+ actual_count = len(data) // dtype.itemsize
+ extra_data = data[actual_count*dtype.itemsize:]
+ array[i:i+actual_count] = numpy.frombuffer(data, dtype=dtype,
+ count=actual_count)
+ i += actual_count
if fortran_order:
array.shape = shape[::-1]