pub struct PuffinReader<R: Read + Seek> { /* private fields */ }Expand description
Reader for Puffin files — parses the footer once, lazily loads blob payloads.
§Examples
use std::io::Cursor;
use samkhya_core::puffin::{Blob, PuffinReader, PuffinWriter};
// Write a file in memory, then read it back.
let mut w = PuffinWriter::new(Cursor::new(Vec::<u8>::new()));
w.add_blob(Blob::new("samkhya.hll-v1", vec![1], b"sketch bytes")).unwrap();
let bytes = w.finish().unwrap().into_inner();
let mut reader = PuffinReader::open(Cursor::new(bytes)).unwrap();
let (idx, meta) = reader.find_blob("samkhya.hll-v1").unwrap();
assert_eq!(meta.kind, "samkhya.hll-v1");
assert_eq!(reader.read_blob(idx).unwrap(), b"sketch bytes");Implementations§
Source§impl<R: Read + Seek> PuffinReader<R>
impl<R: Read + Seek> PuffinReader<R>
pub fn open(inner: R) -> Result<Self>
pub fn blobs(&self) -> &[BlobMetadata]
Sourcepub fn read_blob_decompressed(&mut self, idx: usize) -> Result<Vec<u8>>
pub fn read_blob_decompressed(&mut self, idx: usize) -> Result<Vec<u8>>
Read a blob’s payload by index and decompress it according to the
blob’s compression_codec metadata.
Falls back to the raw bytes when the codec is None / unset. Returns
an error if the recorded codec is unsupported in the current build
(e.g. zstd without the zstd feature).
Sourcepub fn find_blob(&self, kind: &str) -> Option<(usize, &BlobMetadata)>
pub fn find_blob(&self, kind: &str) -> Option<(usize, &BlobMetadata)>
Find the first blob whose type (kind) matches kind.
§Examples
use std::io::Cursor;
use samkhya_core::puffin::{Blob, PuffinReader, PuffinWriter};
let mut w = PuffinWriter::new(Cursor::new(Vec::<u8>::new()));
w.add_blob(Blob::new("samkhya.hll-v1", vec![0], b"x")).unwrap();
let bytes = w.finish().unwrap().into_inner();
let reader = PuffinReader::open(Cursor::new(bytes)).unwrap();
assert!(reader.find_blob("samkhya.hll-v1").is_some());
assert!(reader.find_blob("absent.kind").is_none());Auto Trait Implementations§
impl<R> Freeze for PuffinReader<R>where
R: Freeze,
impl<R> RefUnwindSafe for PuffinReader<R>where
R: RefUnwindSafe,
impl<R> Send for PuffinReader<R>where
R: Send,
impl<R> Sync for PuffinReader<R>where
R: Sync,
impl<R> Unpin for PuffinReader<R>where
R: Unpin,
impl<R> UnsafeUnpin for PuffinReader<R>where
R: UnsafeUnpin,
impl<R> UnwindSafe for PuffinReader<R>where
R: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more