Skip to content

Commit

Permalink
feat: Add PublicFile::size function
Browse files Browse the repository at this point in the history
  • Loading branch information
matheus23 committed Jan 3, 2024
1 parent b53805e commit 2172dbd
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion wnfs/src/public/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use super::{PublicFileSerializable, PublicNodeSerializable};
use crate::{error::FsError, is_readable_wnfs_version, traits::Id, WNFS_VERSION};
use anyhow::{bail, Result};
use anyhow::{anyhow, bail, Result};
use async_once_cell::OnceCell;
use async_trait::async_trait;
use chrono::{DateTime, Utc};
Expand Down Expand Up @@ -420,6 +420,15 @@ impl PublicFile {
pub fn get_metadata_mut_rc<'a>(self: &'a mut Arc<Self>) -> &'a mut Metadata {
self.prepare_next_revision().get_metadata_mut()
}

/// Returns the file size in bytes
pub async fn size(&self, store: &impl BlockStore) -> Result<usize> {
self.userland
.resolve_value(store)
.await?
.size()
.ok_or_else(|| anyhow!("Missing size on dag-pb node"))
}
}

#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
Expand Down

0 comments on commit 2172dbd

Please sign in to comment.