From: Nicolas Patry Date: Sun, 15 Jun 2025 10:27:13 +0000 (+0000) Subject: Adding data_len as public API for metadata (to fetch the size of the (#620) X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=98f07e3bf3548ec7c1275cb409cebeed66aaf4e7;p=safetensors.git Adding data_len as public API for metadata (to fetch the size of the (#620) data buffer). --- diff --git a/safetensors/src/tensor.rs b/safetensors/src/tensor.rs index 6f28d46..e2a1b0f 100644 --- a/safetensors/src/tensor.rs +++ b/safetensors/src/tensor.rs @@ -629,6 +629,15 @@ impl Metadata { index_vec.into_iter().map(|a| a.0.clone()).collect() } + /// Gives the size of the content buffer in bytes. + pub fn data_len(&self) -> usize { + if let Some(tensor) = self.tensors.last() { + tensor.data_offsets.1 + } else { + 0 + } + } + /// Gives back the tensor metadata pub fn metadata(&self) -> &Option> { &self.metadata