@@ -29,7 +29,7 @@ class DictStore:
2929 """
3030 Directory-based storage for compressed data using Blosc2.
3131
32- Manages arrays in a directory (.b2d) or zip (.b2z) format.
32+ Manages arrays in a directory or zip-file backed format.
3333
3434 Supports the following types:
3535
@@ -46,10 +46,11 @@ class DictStore:
4646 Parameters
4747 ----------
4848 localpath : str
49- Local path for the directory (".b2d") or file (".b2z"); other extensions
50- are not supported. If a directory is specified, it will be treated as
51- a Blosc2 directory format (B2DIR). If a file is specified, it
52- will be treated as a Blosc2 zip format (B2ZIP).
49+ Local path for the directory or zip file. Paths ending in ``.b2d`` and
50+ ``.b2z`` remain the recommended conventions. If the path already exists,
51+ directories are treated as Blosc2 directory format (B2DIR) and files as
52+ Blosc2 zip format (B2ZIP). For new extensionless paths, directory-backed
53+ storage is used by default.
5354 mode : str, optional
5455 File mode ('r', 'w', 'a'). Default is 'a'.
5556 mmap_mode : str or None, optional
@@ -117,8 +118,6 @@ def __init__(
117118 See :class:`DictStore` for full documentation of parameters.
118119 """
119120 self .localpath = localpath if isinstance (localpath , str | bytes ) else str (localpath )
120- if not self .localpath .endswith ((".b2z" , ".b2d" )):
121- raise ValueError (f"localpath must have a .b2z or .b2d extension; you passed: { self .localpath } " )
122121 if mode not in ("r" , "w" , "a" ):
123122 raise ValueError ("For DictStore containers, mode must be 'r', 'w', or 'a'" )
124123 if mmap_mode not in (None , "r" ):
@@ -152,7 +151,16 @@ def __init__(
152151
153152 def _setup_paths_and_dirs (self , tmpdir : str | None ):
154153 """Set up working directories and paths."""
155- self .is_zip_store = self .localpath .endswith (".b2z" )
154+ localpath_exists = os .path .exists (self .localpath )
155+ if localpath_exists :
156+ self .is_zip_store = os .path .isfile (self .localpath )
157+ elif self .localpath .endswith (".b2z" ):
158+ self .is_zip_store = True
159+ elif self .localpath .endswith (".b2d" ):
160+ self .is_zip_store = False
161+ else :
162+ # Default extensionless new stores to directory-backed layout.
163+ self .is_zip_store = False
156164 if self .is_zip_store :
157165 if tmpdir is None :
158166 self ._temp_dir_obj = tempfile .TemporaryDirectory ()
@@ -161,11 +169,14 @@ def _setup_paths_and_dirs(self, tmpdir: str | None):
161169 self .working_dir = tmpdir
162170 os .makedirs (tmpdir , exist_ok = True )
163171 self .b2z_path = self .localpath
164- else : # .b2d
172+ else :
165173 self .working_dir = self .localpath
166174 if self .mode in ("w" , "a" ):
167175 os .makedirs (self .working_dir , exist_ok = True )
168- self .b2z_path = self .localpath [:- 4 ] + ".b2z"
176+ if self .localpath .endswith (".b2d" ):
177+ self .b2z_path = self .localpath [:- 4 ] + ".b2z"
178+ else :
179+ self .b2z_path = self .localpath + ".b2z"
169180
170181 self .estore_path = os .path .join (self .working_dir , "embed.b2e" )
171182
0 commit comments