Skip to main content

entrenar/hf_pipeline/export/gguf_verify/
mod.rs

1//! GGUF file verification
2//!
3//! Parses and validates GGUF v3 files, returning a summary of their contents.
4
5mod parsing;
6mod types;
7
8#[cfg(test)]
9mod tests;
10
11use crate::hf_pipeline::error::FetchError;
12use parsing::{parse_all_tensor_info, parse_header, skip_all_metadata};
13
14pub use types::{GgufSummary, GgufTensorInfo};
15
16/// Verify a GGUF file and return a summary
17///
18/// Parses the header and tensor info sections, validating:
19/// - Magic bytes ("GGUF")
20/// - Version (must be 3)
21/// - Tensor count consistency
22/// - No truncation (file large enough for declared tensors)
23pub fn verify_gguf(data: &[u8]) -> Result<GgufSummary, FetchError> {
24    let header = parse_header(data)?;
25    let pos = skip_all_metadata(data, 24, header.metadata_count)?;
26    let tensors = parse_all_tensor_info(data, pos, header.tensor_count)?;
27
28    Ok(GgufSummary {
29        version: header.version,
30        tensor_count: header.tensor_count,
31        metadata_count: header.metadata_count,
32        file_size: data.len(),
33        tensors,
34    })
35}