New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ZipStore arguments: 'w' vs 'x' #1057
Comments
These are related to python's
It won't really, if you only intend to access the zip using zarr. I'd suggest leaving it as the default, unless you intend to unzip it into a file system with opinions on how many files should be in a directory.
Yes, just like regular files: use it with a context manager ( |
@clbarnes, thank you very much. Regarding 'r' mode: what could happen if store is not closed after reading? I am not introducing any modifications to it. |
Unlike most stores, the ZipStore obeys normal python file-opening semantics. Just like a python file (or zipfile), , the file is automatically closed when the object is garbage collected, but you're not in control of when that happens (and it can be dependent on how your script/ package is structured) so for certain usage patterns it can lead to unpredictable numbers of files being open at once. Also like python files/ zipfiles, there's a try:
store = zarr.ZipStore("some/path.zip")
... # whatever else you want to do
finally:
store.close() but that's less ergonomic than the tl;dr in real life it's unlikely that anything disastrous would happen if you left the file closure up the garbage collector, but it is generally good practice to handle these kinds of resources using the context manager. For the sake of explicitness and "one-- and preferably only one --obvious way to do it", I would highly recommend using the context manager wherever possible. If you have a large amount of code which would need to be indented here, I would recommend either factoring that inner code into a function which takes an open ZipStore (then it would be generic over any other store too!), or possibly a wrapper class which itself is a context manager which closes the inner ZipStore on |
Dear all,
Could you tell me what is the exact difference between 'w' and 'x' mode for ZipStore creation?
Also, what does it mean "truncate" here?
Two related questions:
https://zarr.readthedocs.io/en/stable/api/storage.html#zarr.storage.ZipStore
Best regards,
Aliaksei
zarr.__version__
: 2.10.3numcodecs.__version__
: 0.9.1The text was updated successfully, but these errors were encountered: