From 2172dbd10e41deda0992e8acc1e1da172962fd0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Kr=C3=BCger?= Date: Wed, 3 Jan 2024 19:29:45 +0100 Subject: [PATCH] feat: Add `PublicFile::size` function --- wnfs/src/public/file.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/wnfs/src/public/file.rs b/wnfs/src/public/file.rs index 8720a6da..e296309b 100644 --- a/wnfs/src/public/file.rs +++ b/wnfs/src/public/file.rs @@ -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}; @@ -420,6 +420,15 @@ impl PublicFile { pub fn get_metadata_mut_rc<'a>(self: &'a mut Arc) -> &'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 { + 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)]