diff --git a/zarr/storage.py b/zarr/storage.py index 8b387ed1f8..670fd62a3e 100644 --- a/zarr/storage.py +++ b/zarr/storage.py @@ -34,6 +34,8 @@ from threading import Lock, RLock import uuid +import numpy + from numcodecs.compat import ensure_bytes, ensure_contiguous_ndarray from numcodecs.registry import codec_registry @@ -740,8 +742,7 @@ def __init__(self, path): def __getitem__(self, key): filepath = os.path.join(self.path, key) if os.path.isfile(filepath): - with open(filepath, 'rb') as f: - return f.read() + return numpy.fromfile(filepath, dtype='u1') else: raise KeyError(key) @@ -773,8 +774,7 @@ def __setitem__(self, key, value): temp_name = file_name + '.' + uuid.uuid4().hex + '.partial' temp_path = os.path.join(dir_path, temp_name) try: - with open(temp_path, mode='wb') as f: - f.write(value) + value.tofile(temp_path) # move temporary file into place replace(temp_path, file_path)