@@ -432,33 +432,46 @@ MemoryError
432432
433433====
434434
435- ## [ Storage alternatives ] ( https://zarr.readthedocs.io/en/stable/tutorial.html#storage-alternatives )
435+ ## [ Pluggable storage ] ( https://zarr.readthedocs.io/en/stable/tutorial.html#storage-alternatives )
436436
437- * ` zarr.DirectoryStore `
438- * ` zarr.DictStore ` (in-memory)
439- * ` zarr.ZipStore `
440- * ` zarr.DBMStore ` , ` zarr.LMDBStore ` , ` zarr.SQLiteStore `
441- * ` zarr.MongoDBStore ` , ` zarr.RedisStore `
442- * ` zarr.ABSStore ` , ` s3fs.S3Map ` , ` gcsfs.GCSMap `
437+ ` zarr.DirectoryStore ` , ` zarr.ZipStore ` , ` zarr.DBMStore ` ,
438+ ` zarr.LMDBStore ` , ` zarr.SQLiteStore ` , ` zarr.MongoDBStore ` ,
439+ ` zarr.RedisStore ` , ` zarr.ABSStore ` , ` s3fs.S3Map ` , ` gcsfs.GCSMap ` , ...
443440
444441===
445442
446- ### Local file system ( DirectoryStore)
443+ ### DirectoryStore
447444
448445``` python
449446>> > store = zarr.DirectoryStore(' example.zarr' )
450447>> > root = zarr.group(store)
451- >> > root.tree()
452- /
453- ├── big (100000000 , 100000000 ) int32
454- └── x (10000 , 10000 ) int32
455- >> > root[' big' ]
448+ >> > big = root[' big' ]
449+ >> > big
456450< zarr.core.Array ' /big' (100000000 , 100000000 ) int32>
457451```
458452
459453===
460454
461- ### Local file system (ZipStore)
455+ ### DirectoryStore
456+
457+ ``` bash
458+ $ tree -a example.zarr
459+ example.zarr
460+ ├── big
461+ │ ├── 0.0
462+ │ ├── 0.1
463+ │ ├── 1.0
464+ │ └── .zarray
465+ ├── x
466+ │ └── .zarray
467+ └── .zgroup
468+
469+ 2 directories, 6 files
470+ ```
471+
472+ ===
473+
474+ ### ZipStore
462475
463476``` bash
464477$ cd example.zarr && zip -r0v ../example.zip ./*
@@ -467,11 +480,8 @@ $ cd example.zarr && zip -r0v ../example.zip ./*
467480``` python
468481>> > store = zarr.ZipStore(' example.zip' )
469482>> > root = zarr.group(store)
470- >> > root.tree()
471- /
472- ├── big (100000000 , 100000000 ) int32
473- └── x (10000 , 10000 ) int32
474- >> > root[' big' ]
483+ >> > big = root[' big' ]
484+ >> > big
475485< zarr.core.Array ' /big' (100000000 , 100000000 ) int32>
476486```
477487
@@ -489,11 +499,8 @@ $ gsutil rsync -ru example.zarr/ gs://zarr-demo/example.zarr/
489499>> > gcs = gcsfs.GCSFileSystem(token = ' anon' , access = ' read_only' )
490500>> > store = gcsfs.GCSMap(' zarr-demo/example.zarr' , gcs = gcs, check = False )
491501>> > root = zarr.group(store)
492- >> > root.tree()
493- /
494- ├── big (100000000 , 100000000 ) int32
495- └── x (10000 , 10000 ) int32
496- >> > root[' big' ]
502+ >> > big = root[' big' ]
503+ >> > big
497504< zarr.core.Array ' /big' (100000000 , 100000000 ) int32>
498505```
499506
@@ -503,6 +510,51 @@ $ gsutil rsync -ru example.zarr/ gs://zarr-demo/example.zarr/
503510
504511<p class =" stretch " ><img src =" scipy-2019-files/gcs.png " ></p >
505512
513+ ===
514+
515+ <p class =" stretch " ><img src =" scipy-2019-files/storage.png " ></p >
516+
517+ ===
518+
519+ ### Store interface
520+
521+ * Any storage system can be used with Zarr if it can provide a
522+ key/value interface.
523+
524+ * Keys are strings, values are bytes.
525+
526+ * In Python, we use the MutableMapping interface.
527+
528+ * ` __getitem__ `
529+ * ` __setitem__ `
530+ * ` __iter__ `
531+
532+ * I.e., anything dict-like can be used as a Zarr store.
533+
534+ ===
535+
536+ ### E.g., ZipStore implementation
537+
538+ ``` python
539+ class ZipStore (MutableMapping ):
540+
541+ def __init__ (self , path , ...):
542+ self .zf = zipfile.ZipFile(path, ... )
543+
544+ def __getitem__ (self , key ):
545+ with self .zf.open(key) as f:
546+ return f.read()
547+
548+ def __setitem__ (self , key , value ):
549+ self .zf.writestr(key, value)
550+
551+ def __iter__ (self ):
552+ for key in self .zf.namelist():
553+ yield key
554+ ```
555+
556+ <small >(Actual implementation is slightly more complicated, but this is the essence.)</small >
557+
506558====
507559
508560## Compressors
0 commit comments