diff options
Diffstat (limited to 'numpy/lib/npyio.py')
-rw-r--r-- | numpy/lib/npyio.py | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py index fbcb5a46e..d400b4d30 100644 --- a/numpy/lib/npyio.py +++ b/numpy/lib/npyio.py @@ -244,12 +244,14 @@ class NpzFile(object): member = 1 key += '.npy' if member: - bytes = self.zip.read(key) - if bytes.startswith(format.MAGIC_PREFIX): - value = BytesIO(bytes) - return format.read_array(value) + bytes = self.zip.open(key) + magic = bytes.read(len(format.MAGIC_PREFIX)) + bytes.close() + if magic == format.MAGIC_PREFIX: + bytes = self.zip.open(key) + return format.read_array(bytes) else: - return bytes + return self.zip.read(key) else: raise KeyError("%s is not a file in the archive" % key) |