Skip to content

Commit

Permalink
Add Group::{async_}erase_metadata()
Browse files Browse the repository at this point in the history
  • Loading branch information
LDeakin committed Mar 4, 2024
1 parent 875298c commit a92ff2d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Implement `Deserialize` for `DataType`
- A convenience for `zarrs` consumers. `ArrayMetadata` continues to use `Metadata` to parse unknown data types.
- Add `Array::{async_}erase_metadata()` and `storage::{async_}erase_metadata()`
- Add `{Array,Group}::{async_}erase_metadata()` and `storage::{async_}erase_metadata()`

### Fixed
- Fixed various errors in storage docs
Expand Down
26 changes: 20 additions & 6 deletions src/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,25 +197,39 @@ impl<TStorage: ?Sized + WritableStorageTraits + 'static> Group<TStorage> {
/// Store metadata.
///
/// # Errors
///
/// Returns [`StorageError`] if there is an underlying store error.
pub fn store_metadata(&self) -> Result<(), StorageError> {
let storage_handle = StorageHandle::new(self.storage.clone());
crate::storage::create_group(&storage_handle, self.path(), &self.metadata())
}

/// Erase the metadata.
///
/// Succeeds if the metadata does not exist.
///
/// # Errors
/// Returns a [`StorageError`] if there is an underlying store error.
pub fn erase_metadata(&self) -> Result<(), StorageError> {
let storage_handle = StorageHandle::new(self.storage.clone());
crate::storage::erase_metadata(&storage_handle, self.path())
}
}

#[cfg(feature = "async")]
impl<TStorage: ?Sized + AsyncWritableStorageTraits> Group<TStorage> {
/// Store metadata.
///
/// # Errors
///
/// Returns [`StorageError`] if there is an underlying store error.
/// Async variant of [`store_metadata`](Group::store_metadata).
#[allow(clippy::missing_errors_doc)]
pub async fn async_store_metadata(&self) -> Result<(), StorageError> {
let storage_handle = StorageHandle::new(self.storage.clone());
crate::storage::async_create_group(&storage_handle, self.path(), &self.metadata()).await
}

/// Async variant of [`erase_metadata`](Group::erase_metadata).
#[allow(clippy::missing_errors_doc)]
pub async fn async_erase_metadata(&self) -> Result<(), StorageError> {
let storage_handle = StorageHandle::new(self.storage.clone());
crate::storage::async_erase_metadata(&storage_handle, self.path()).await
}
}

#[cfg(test)]
Expand Down

0 comments on commit a92ff2d

Please sign in to comment.