zarr-python
zarr-python copied to clipboard
Read only array default upon opening
For bug reports, please follow the template below. For enhancement proposals, feel free to use whatever template makes sense (major new features should be discussed in the Zarr specifications repository https://github.com/zarr-developers/zarr-specs).
Minimal, reproducible code sample, a copy-pastable example if possible
src = 'path/to/dir'
z = zarr.open(src)
z.create('array',shape=(1, 1, 1, 1, 2048, 2048),
chunks=(1, 1, 1, 1, 2048, 2048),
compressor=Blosc('zstd', clevel=3, shuffle=Blosc.BITSHUFFLE),
read_only=True)
z['array'][0,4] = 1
## Reload the array after restarting kernel
z_array = zarr.open(src)['array'] ## no longer read_only
Problem description
I am trying to create a zarr store containing an array that is by default read_only. We are moving our raw microscopy data to zarr format and we do not want the user to be able to easily edit the zarr arrays. The default zarr.open(mode='a') overrides any sort of read_only setting put onto the array during creation. This is troublesome because some of our users will not remember to specify mode='r' when browsing the raw data.
Is there a way to have the zarr store/array be read_only by default upon opening?
Version and installation information
Please provide the following:
- Value of
zarr.__version__= 2.8.3 - Value of
numcodecs.__version__= 0.7.3 - python 3.7
- Mac
- pip install zarr
Hi @camFoltz. I don't know of a zarr-specific mechanism for recording the read-only setting. As a workaround, have you looked at making it read-only at the underlying storage level?
Hi @joshmoore , thanks for the response. If zarr has no specific mechanism then we will move to dealing with it at the permission level.
While there isn't (and probably shouldn't be, for simplicity purposes) a mechanism for storing the default access mode on individual containers/ groups/ arrays, would changing the global default mode to "r" be considered in the next major version? h5py did that (somewhat) recently; it would more closely match python's built-in open, and in a post-v3 world where different stores may be readable, writable, and listable, the read-only variant is likely to be the most fundamental and therefore be the simplest assumption to make.
@clbarnes : nods and I seem to remember a store (FSStore) recently switching its local default. I'll try to find that commit/PR.
Edit: https://github.com/zarr-developers/zarr-python/pull/546#discussion_r410047224
This issue may be fixed by https://github.com/zarr-developers/zarr-python/pull/916