Skip to main content

FileReader

Struct FileReader 

Source
pub struct FileReader<R> {
    pub index: Vec<IndexEntry>,
    pub kv: Vec<(String, KvValue)>,
    /* private fields */
}
Expand description

Reads tensors from a seekable Hurray file.

Open with FileReader::open, then look up tensors by name with read_tensor or inspect metadata with tensor_names and kv.

§Examples

use hurray_io::file::FileReader;

let file = tokio::fs::File::open("model.hrry").await?;
let mut reader = FileReader::open(file).await?;
println!("tensors: {:?}", reader.tensor_names().collect::<Vec<_>>());
let tensor = reader.read_tensor("embeddings").await?;
println!("buffer[0]: {} bytes", tensor.buffers[0].len());

Fields§

§index: Vec<IndexEntry>

Footer index: one entry per tensor, in file-write order (or sorted if SORTED_INDEX was set by the writer).

§kv: Vec<(String, KvValue)>

File-level KV metadata (empty if the file has no KV section).

Implementations§

Source§

impl<R: AsyncRead + AsyncSeek + Unpin> FileReader<R>

Source

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

Opens a Hurray file: reads the header, trailer, index, and KV section.

§Errors
Source

pub fn with_max_composite_depth(self, max_composite_depth: usize) -> Self

Sets the maximum composite nesting depth accepted by read_composite. Default: DEFAULT_MAX_COMPOSITE_DEPTH.

Source

pub fn tensor_names(&self) -> impl Iterator<Item = &str>

Returns the names of all tensors in the file, in index order.

Source

pub fn kv(&self) -> &[(String, KvValue)]

Returns the file-level KV metadata.

Source

pub async fn read_descriptor(&mut self, name: &str) -> Result<TensorDescriptor>

Decodes and returns the descriptor for name without reading buffer data.

Useful for inspecting dtype, shape, or layout before deciding whether to load the full tensor.

Source

pub async fn read_tensor(&mut self, name: &str) -> Result<FileTensor>

Reads and returns a complete tensor (descriptor + all buffers).

Source

pub async fn read_composite(&mut self, head_name: &str) -> Result<FileComposite>

Reads a composite tensor by its head name, reassembling the head with its members.

Members are recovered by file-offset adjacency: the head’s declared member_count tensors written immediately after it, recursively for nested composites. Recovery keys on the descriptor offset, not index position, so it is correct even when the file used the SORTED_INDEX option (which reorders the index array but not the file layout). The reassembled group is validated with [CompositeValidator].

§Examples
use hurray_io::file::FileReader;

let file = tokio::fs::File::open("model.hrry").await?;
let mut reader = FileReader::open(file).await?;
let composite = reader.read_composite("weight").await?;
println!("{} member(s)", composite.members.len());
§Errors
Source

pub fn into_inner(self) -> R

Returns the underlying reader.

Trait Implementations§

Source§

impl<R: Debug> Debug for FileReader<R>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<R> Freeze for FileReader<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for FileReader<R>
where R: RefUnwindSafe,

§

impl<R> Send for FileReader<R>
where R: Send,

§

impl<R> Sync for FileReader<R>
where R: Sync,

§

impl<R> Unpin for FileReader<R>
where R: Unpin,

§

impl<R> UnsafeUnpin for FileReader<R>
where R: UnsafeUnpin,

§

impl<R> UnwindSafe for FileReader<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.