Skip to content

Commit

Permalink
refactor: Rename get_size -> size in wnfs crate
Browse files Browse the repository at this point in the history
  • Loading branch information
matheus23 committed Feb 28, 2024
1 parent 26c185a commit 591556b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
18 changes: 5 additions & 13 deletions wnfs/src/private/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,21 +617,17 @@ impl PrivateFile {
/// )
/// .await?;
///
/// let mut size = file.get_size(forest, store).await?;
/// let mut size = file.size(forest, store).await?;
///
/// assert_eq!(content.len(), size);
/// assert_eq!(content.len() as u64, size);
///
/// Ok(())
/// }
/// ```
pub async fn get_size(
&self,
forest: &impl PrivateForest,
store: &impl BlockStore,
) -> Result<u64> {
pub async fn size(&self, forest: &impl PrivateForest, store: &impl BlockStore) -> Result<u64> {
match &self.content.content {
FileContent::Inline { data } => Ok(data.len() as u64),
FileContent::External(forest_content) => forest_content.get_size(forest, store).await,
FileContent::External(forest_content) => forest_content.size(forest, store).await,
}
}

Expand Down Expand Up @@ -1088,11 +1084,7 @@ impl PrivateForestContent {
}

/// Gets the exact size of the content.
pub async fn get_size(
&self,
forest: &impl PrivateForest,
store: &impl BlockStore,
) -> Result<u64> {
pub async fn size(&self, forest: &impl PrivateForest, store: &impl BlockStore) -> Result<u64> {
let size_without_last_block =
std::cmp::max(0, self.block_count - 1) * self.block_content_size;

Expand Down
6 changes: 3 additions & 3 deletions wnfs/src/public/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,14 +335,14 @@ impl PublicFile {
/// )
/// .await?;
///
/// let mut size = file.get_size(store).await?;
/// let mut size = file.size(store).await?;
///
/// assert_eq!(content.len(), size);
/// assert_eq!(content.len() as u64, size);
///
/// Ok(())
/// }
/// ```
pub async fn get_size(&self, store: &impl BlockStore) -> Result<u64> {
pub async fn size(&self, store: &impl BlockStore) -> Result<u64> {
let value = self.userland.resolve_value(store).await?;
Ok(value.filesize().unwrap_or(0))
}
Expand Down

0 comments on commit 591556b

Please sign in to comment.