From 98f07e3bf3548ec7c1275cb409cebeed66aaf4e7 Mon Sep 17 00:00:00 2001 From: Nicolas Patry Date: Sun, 15 Jun 2025 10:27:13 +0000 Subject: [PATCH] Adding data_len as public API for metadata (to fetch the size of the (#620) data buffer). --- safetensors/src/tensor.rs | 9 +++++++++ 1 file changed, 9 insertions(+) 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 -- 2.43.0