|
3 | 3 | import warnings
|
4 | 4 | from numcodecs.compat import ensure_bytes
|
5 | 5 | from zarr.util import normalize_storage_path
|
6 |
| -from zarr._storage.store import Store |
| 6 | +from zarr._storage.store import _get_metadata_suffix, data_root, meta_root, Store, StoreV3 |
7 | 7 |
|
8 | 8 | __doctest_requires__ = {
|
9 | 9 | ('ABSStore', 'ABSStore.*'): ['azure.storage.blob'],
|
@@ -209,3 +209,57 @@ def getsize(self, path=None):
|
209 | 209 |
|
210 | 210 | def clear(self):
|
211 | 211 | self.rmdir()
|
| 212 | + |
| 213 | + |
| 214 | +class ABSStoreV3(ABSStore, StoreV3): |
| 215 | + |
| 216 | + def list(self): |
| 217 | + return list(self.keys()) |
| 218 | + |
| 219 | + def __eq__(self, other): |
| 220 | + return ( |
| 221 | + isinstance(other, ABSStoreV3) and |
| 222 | + self.client == other.client and |
| 223 | + self.prefix == other.prefix |
| 224 | + ) |
| 225 | + |
| 226 | + def __setitem__(self, key, value): |
| 227 | + self._validate_key(key) |
| 228 | + super().__setitem__(key, value) |
| 229 | + |
| 230 | + def rmdir(self, path=None): |
| 231 | + |
| 232 | + if not path: |
| 233 | + # Currently allowing clear to delete everything as in v2 |
| 234 | + |
| 235 | + # If we disallow an empty path then we will need to modify |
| 236 | + # TestABSStoreV3 to have the create_store method use a prefix. |
| 237 | + ABSStore.rmdir(self, '') |
| 238 | + return |
| 239 | + |
| 240 | + meta_dir = meta_root + path |
| 241 | + meta_dir = meta_dir.rstrip('/') |
| 242 | + ABSStore.rmdir(self, meta_dir) |
| 243 | + |
| 244 | + # remove data folder |
| 245 | + data_dir = data_root + path |
| 246 | + data_dir = data_dir.rstrip('/') |
| 247 | + ABSStore.rmdir(self, data_dir) |
| 248 | + |
| 249 | + # remove metadata files |
| 250 | + sfx = _get_metadata_suffix(self) |
| 251 | + array_meta_file = meta_dir + '.array' + sfx |
| 252 | + if array_meta_file in self: |
| 253 | + del self[array_meta_file] |
| 254 | + group_meta_file = meta_dir + '.group' + sfx |
| 255 | + if group_meta_file in self: |
| 256 | + del self[group_meta_file] |
| 257 | + |
| 258 | + # TODO: adapt the v2 getsize method to work for v3 |
| 259 | + # For now, calling the generic keys-based _getsize |
| 260 | + def getsize(self, path=None): |
| 261 | + from zarr.storage import _getsize # avoid circular import |
| 262 | + return _getsize(self, path) |
| 263 | + |
| 264 | + |
| 265 | +ABSStoreV3.__doc__ = ABSStore.__doc__ |
0 commit comments