Skip to content

Commit 98f07e3

Browse files
authored
Adding data_len as public API for metadata (to fetch the size of the (#620)
data buffer).
1 parent fa6a19c commit 98f07e3

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

safetensors/src/tensor.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,15 @@ impl Metadata {
629629
index_vec.into_iter().map(|a| a.0.clone()).collect()
630630
}
631631

632+
/// Gives the size of the content buffer in bytes.
633+
pub fn data_len(&self) -> usize {
634+
if let Some(tensor) = self.tensors.last() {
635+
tensor.data_offsets.1
636+
} else {
637+
0
638+
}
639+
}
640+
632641
/// Gives back the tensor metadata
633642
pub fn metadata(&self) -> &Option<HashMap<String, String>> {
634643
&self.metadata

0 commit comments

Comments
 (0)