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>
impl<R: AsyncRead + AsyncSeek + Unpin> FileReader<R>
Sourcepub async fn open(inner: R) -> Result<Self>
pub async fn open(inner: R) -> Result<Self>
Opens a Hurray file: reads the header, trailer, index, and KV section.
§Errors
Error::InvalidFileMagic— first 8 bytes are notHRRYFILEError::UnsupportedContainerVersion— major version > 1Error::ReservedFileFlagBits— headerfile_flagshas unknown bits setError::InvalidTrailerMagic— trailertrailer_magicis notHRRYError::IndexOverrunsTrailer— index section overlaps the trailerError::IndexCrc32cMismatch— CRC-32C verification failedError::DuplicateTensorName— index contains duplicate namesError::Io/Error::UnexpectedEof— I/O failures
Sourcepub fn with_max_composite_depth(self, max_composite_depth: usize) -> Self
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.
Sourcepub fn tensor_names(&self) -> impl Iterator<Item = &str>
pub fn tensor_names(&self) -> impl Iterator<Item = &str>
Returns the names of all tensors in the file, in index order.
Sourcepub async fn read_descriptor(&mut self, name: &str) -> Result<TensorDescriptor>
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.
Sourcepub async fn read_tensor(&mut self, name: &str) -> Result<FileTensor>
pub async fn read_tensor(&mut self, name: &str) -> Result<FileTensor>
Reads and returns a complete tensor (descriptor + all buffers).
Sourcepub async fn read_composite(&mut self, head_name: &str) -> Result<FileComposite>
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
Error::TensorNotFound— no tensor namedhead_nameError::NotAComposite—head_nameexists but is not a composite headError::TornComposite— fewer members follow the head than it declaresError::CompositeNestingTooDeep— nesting exceededmax_composite_depthError::Core— composite validation failed
Sourcepub fn into_inner(self) -> R
pub fn into_inner(self) -> R
Returns the underlying reader.