Skip to content

Commit c7fbaa0

Browse files
author
Martin Durant
committed
Allow zarr.open
This demonstrates the purpose of this PR! Now allows, for exmple `zarr.open('http://localhost:8000')`, although there is no way to pass on further args with this method yet.
1 parent babbfd5 commit c7fbaa0

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

zarr/creation.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from zarr.n5 import N5Store
1111
from zarr.storage import (DirectoryStore, ZipStore, contains_array,
1212
contains_group, default_compressor, init_array,
13-
normalize_storage_path)
13+
normalize_storage_path, FSStore)
1414

1515

1616
def create(shape, chunks=True, dtype=None, compressor='default',
@@ -131,8 +131,10 @@ def normalize_store_arg(store, clobber=False, default=dict):
131131
if store is None:
132132
return default()
133133
elif isinstance(store, str):
134+
mode = 'w' if clobber else 'r'
135+
if "://" in store:
136+
return FSStore(store)
134137
if store.endswith('.zip'):
135-
mode = 'w' if clobber else 'r'
136138
return ZipStore(store, mode=mode)
137139
elif store.endswith('.n5'):
138140
return N5Store(store)

zarr/storage.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,13 +949,14 @@ def atexit_rmglob(path,
949949
class FSStore(MutableMapping):
950950

951951
def __init__(self, url, normalize_keys=True, key_separator='.',
952-
**storage_options):
952+
mode='r', **storage_options):
953953
import fsspec
954954
self.path = url
955955
self.normalize_keys = normalize_keys
956956
self.key_separator = key_separator
957957
self.map = fsspec.get_mapper(url, **storage_options)
958958
self.fs = self.map.fs # for direct operations
959+
self.mode = mode
959960

960961
def _normalize_key(self, key):
961962
key = normalize_storage_path(key)
@@ -969,6 +970,8 @@ def __getitem__(self, key):
969970
return self.map[key]
970971

971972
def __setitem__(self, key, value):
973+
if self.mode == 'r':
974+
raise PermissionError
972975
key = self._normalize_key(key)
973976
path = self.dir_path(key)
974977
value = ensure_contiguous_ndarray(value)
@@ -980,6 +983,8 @@ def __setitem__(self, key, value):
980983
raise KeyError(key)
981984

982985
def __delitem__(self, key):
986+
if self.mode == 'r':
987+
raise PermissionError
983988
key = self._normalize_key(key)
984989
path = self.dir_path(key)
985990
if self.fs.isdir(path):

0 commit comments

Comments
 (0)