Skip to main content

PuffinReader

Struct PuffinReader 

Source
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>

Source

pub fn open(inner: R) -> Result<Self>

Source

pub fn footer(&self) -> &FooterPayload

Source

pub fn blobs(&self) -> &[BlobMetadata]

Source

pub fn read_blob(&mut self, idx: usize) -> Result<Vec<u8>>

Read a blob’s payload by index.

Source

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).

Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V