Skip to content

Commit 14c223a

Browse files
committed
Avoid an unnecessary tempdir creation when opening a .b2d/.b2z in 'r'ead mode
1 parent e1ad478 commit 14c223a

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/blosc2/dict_store.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,17 @@ def _setup_paths_and_dirs(self, tmpdir: str | None):
164164
# Default extensionless new stores to directory-backed layout.
165165
self.is_zip_store = False
166166
if self.is_zip_store:
167-
if tmpdir is None:
167+
if self.mode == "r":
168+
# Read mode only needs working_dir as a path namespace for relative↔absolute
169+
# key arithmetic. No files are ever written, so no real directory is needed.
170+
self._temp_dir_obj = None
171+
self.working_dir = os.path.splitext(os.path.abspath(self.localpath))[0]
172+
elif tmpdir is None:
168173
b2z_parent = os.path.dirname(os.path.abspath(self.localpath))
169174
self._temp_dir_obj = tempfile.TemporaryDirectory(dir=b2z_parent)
170175
self.working_dir = self._temp_dir_obj.name
171176
else:
177+
self._temp_dir_obj = None
172178
self.working_dir = tmpdir
173179
os.makedirs(tmpdir, exist_ok=True)
174180
self.b2z_path = self.localpath

0 commit comments

Comments
 (0)