]> khamidou — GitHub mirrors - safetensors.git/commitdiff
Adding data_len as public API for metadata (to fetch the size of the (#620)
authorNicolas Patry <patry.nicolas@protonmail.com>
Sun, 15 Jun 2025 10:27:13 +0000 (10:27 +0000)
committerGitHub <noreply@github.com>
Sun, 15 Jun 2025 10:27:13 +0000 (12:27 +0200)
data buffer).

safetensors/src/tensor.rs

index 6f28d46561b2ed963db536fd99bdd3b5bd0b0b85..e2a1b0ff32ce0324137535e2b0f984c174ab39f2 100644 (file)
@@ -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<HashMap<String, String>> {
         &self.metadata