Skip to content

Commit

Permalink
fix: implement soft delete by replacing key with empty byte literal
Browse files Browse the repository at this point in the history
Signed-off-by: asim <aktech701@gmail.com>
  • Loading branch information
asimchoudhary committed Feb 14, 2025
1 parent feeb08f commit 15fcc89
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/zarr/storage/_zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,12 @@ async def delete_dir(self, prefix: str) -> None:

async def delete(self, key: str) -> None:
# docstring inherited
# we choose to only raise NotImplementedError here if the key exists
# this allows the array/group APIs to avoid the overhead of existence checks
# If key is present it is replaced by an empty byte literal as a way of representing it as deleted
self._check_writable()
if await self.exists(key):
raise NotImplementedError
with self._lock:
empty_buffer = Buffer.from_bytes(b"")
self._set(key, empty_buffer)

Check warning on line 249 in src/zarr/storage/_zip.py

View check run for this annotation

Codecov / codecov/patch

src/zarr/storage/_zip.py#L249

Added line #L249 was not covered by tests

async def exists(self, key: str) -> bool:
# docstring inherited
Expand Down

0 comments on commit 15fcc89

Please sign in to comment.