pub struct Hdf5File { /* private fields */ }Expand description
An HDF5 file held as a logical graph and (re)serialized to bytes on demand.
Implementations§
Source§impl Hdf5File
impl Hdf5File
Sourcepub fn create() -> Self
pub fn create() -> Self
Empty file with a root group. Writes superblock version 2 on Self::to_bytes.
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self>
pub fn from_bytes(bytes: &[u8]) -> Result<Self>
Parse a complete HDF5 file image. Returns HDF5Error::InvalidSignature
if the format signature is missing.
Sourcepub fn to_bytes(&self) -> Result<Vec<u8>>
pub fn to_bytes(&self) -> Result<Vec<u8>>
Serialize to a standard HDF5 superblock-v2 file image.
Sourcepub fn open<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>
Open an existing file from a filesystem path.
Errors: HDF5Error::Io, plus every error Self::from_bytes can return.
Sourcepub fn create_file<P: AsRef<Path>>(_path: P) -> Result<Self>
pub fn create_file<P: AsRef<Path>>(_path: P) -> Result<Self>
Create an empty file object (does not write until Self::save).
Sourcepub fn save<P: AsRef<Path>>(&self, path: P) -> Result<()>
pub fn save<P: AsRef<Path>>(&self, path: P) -> Result<()>
Write the current image to path.
Errors: HDF5Error::Io and encode failures.
Sourcepub fn list_datasets(&self) -> Vec<String>
pub fn list_datasets(&self) -> Vec<String>
Dataset paths (no leading slash), sorted.
Sourcepub fn list_groups(&self) -> Vec<String>
pub fn list_groups(&self) -> Vec<String>
Group paths. Root is "/".
Sourcepub fn dataset_shape(&self, path: &str) -> Result<Vec<usize>>
pub fn dataset_shape(&self, path: &str) -> Result<Vec<usize>>
Dataspace dimensions of path.
Errors: HDF5Error::NotFound. Shape is reported for chunked and
filtered datasets; reading those still returns a named error.
Sourcepub fn dataset_dtype(&self, path: &str) -> Result<HDF5DType>
pub fn dataset_dtype(&self, path: &str) -> Result<HDF5DType>
Datatype of path.
Errors: HDF5Error::NotFound. Chunked datasets still report a type.
Sourcepub fn create_group(&mut self, path: &str) -> Result<()>
pub fn create_group(&mut self, path: &str) -> Result<()>
Create a group. Parent must exist (root always does).
Errors: HDF5Error::NotFound, HDF5Error::NameTooLong.
Sourcepub fn write_f64(
&mut self,
path: &str,
shape: &[usize],
bits: &[u64],
) -> Result<()>
pub fn write_f64( &mut self, path: &str, shape: &[usize], bits: &[u64], ) -> Result<()>
Write IEEE binary64 little-endian lanes. bits.len() must equal the
product of shape (empty shape is a scalar, one element).
Rank 0 through HDF5_MAX_DIMS.
Errors: HDF5Error::ShapeMismatch, HDF5Error::RankNotSupported,
HDF5Error::NameTooLong.
Sourcepub fn write_ieee64(
&mut self,
path: &str,
shape: &[usize],
bits: &[u64],
) -> Result<()>
pub fn write_ieee64( &mut self, path: &str, shape: &[usize], bits: &[u64], ) -> Result<()>
IEEE binary64 little-endian lanes. Same as Self::write_f64.
Named for callers whose sources cannot contain hardware float tokens.
Sourcepub fn write_f32(
&mut self,
path: &str,
shape: &[usize],
bits: &[u32],
) -> Result<()>
pub fn write_f32( &mut self, path: &str, shape: &[usize], bits: &[u32], ) -> Result<()>
Write IEEE binary32 little-endian lanes.
Errors: same as Self::write_f64.
Sourcepub fn write_ieee32(
&mut self,
path: &str,
shape: &[usize],
bits: &[u32],
) -> Result<()>
pub fn write_ieee32( &mut self, path: &str, shape: &[usize], bits: &[u32], ) -> Result<()>
IEEE binary32 little-endian lanes. Same as Self::write_f32.
Sourcepub fn write_opaque(
&mut self,
path: &str,
shape: &[usize],
elem_size: usize,
data: &[u8],
) -> Result<()>
pub fn write_opaque( &mut self, path: &str, shape: &[usize], elem_size: usize, data: &[u8], ) -> Result<()>
Write opaque records of elem_size bytes. data.len() must equal
shape.product() * elem_size.
Errors: same as Self::write_f64.
Sourcepub fn write_i8(
&mut self,
path: &str,
shape: &[usize],
bits: &[i8],
) -> Result<()>
pub fn write_i8( &mut self, path: &str, shape: &[usize], bits: &[i8], ) -> Result<()>
Write signed 8-bit lanes.
Sourcepub fn write_i16(
&mut self,
path: &str,
shape: &[usize],
bits: &[i16],
) -> Result<()>
pub fn write_i16( &mut self, path: &str, shape: &[usize], bits: &[i16], ) -> Result<()>
Write signed 16-bit little-endian lanes.
Sourcepub fn write_i32(
&mut self,
path: &str,
shape: &[usize],
bits: &[i32],
) -> Result<()>
pub fn write_i32( &mut self, path: &str, shape: &[usize], bits: &[i32], ) -> Result<()>
Write signed 32-bit little-endian lanes.
Sourcepub fn write_i64(
&mut self,
path: &str,
shape: &[usize],
bits: &[i64],
) -> Result<()>
pub fn write_i64( &mut self, path: &str, shape: &[usize], bits: &[i64], ) -> Result<()>
Write signed 64-bit little-endian lanes.
Sourcepub fn write_u8(
&mut self,
path: &str,
shape: &[usize],
bits: &[u8],
) -> Result<()>
pub fn write_u8( &mut self, path: &str, shape: &[usize], bits: &[u8], ) -> Result<()>
Write unsigned 8-bit lanes.
Sourcepub fn write_u16(
&mut self,
path: &str,
shape: &[usize],
bits: &[u16],
) -> Result<()>
pub fn write_u16( &mut self, path: &str, shape: &[usize], bits: &[u16], ) -> Result<()>
Write unsigned 16-bit little-endian lanes.
Sourcepub fn write_u32(
&mut self,
path: &str,
shape: &[usize],
bits: &[u32],
) -> Result<()>
pub fn write_u32( &mut self, path: &str, shape: &[usize], bits: &[u32], ) -> Result<()>
Write unsigned 32-bit little-endian lanes.
Sourcepub fn write_u64(
&mut self,
path: &str,
shape: &[usize],
bits: &[u64],
) -> Result<()>
pub fn write_u64( &mut self, path: &str, shape: &[usize], bits: &[u64], ) -> Result<()>
Write unsigned 64-bit little-endian lanes.
Sourcepub fn read_f64(&self, path: &str) -> Result<(Vec<usize>, Vec<u64>)>
pub fn read_f64(&self, path: &str) -> Result<(Vec<usize>, Vec<u64>)>
Read IEEE binary64 lanes and the dataspace shape.
Errors: HDF5Error::NotFound, HDF5Error::ChunkedNotSupported,
HDF5Error::FilteredNotSupported, HDF5Error::TypeMismatch.
Sourcepub fn read_ieee64(&self, path: &str) -> Result<(Vec<usize>, Vec<u64>)>
pub fn read_ieee64(&self, path: &str) -> Result<(Vec<usize>, Vec<u64>)>
IEEE binary64 lanes and dataspace shape. Same as Self::read_f64.
Sourcepub fn read_f32(&self, path: &str) -> Result<(Vec<usize>, Vec<u32>)>
pub fn read_f32(&self, path: &str) -> Result<(Vec<usize>, Vec<u32>)>
Read IEEE binary32 lanes and the dataspace shape.
Errors: same as Self::read_f64.
Sourcepub fn read_ieee32(&self, path: &str) -> Result<(Vec<usize>, Vec<u32>)>
pub fn read_ieee32(&self, path: &str) -> Result<(Vec<usize>, Vec<u32>)>
IEEE binary32 lanes and dataspace shape. Same as Self::read_f32.
Sourcepub fn read_opaque(&self, path: &str) -> Result<(Vec<usize>, usize, Vec<u8>)>
pub fn read_opaque(&self, path: &str) -> Result<(Vec<usize>, usize, Vec<u8>)>
Read opaque payload, shape, and element size.
Errors: HDF5Error::NotFound, HDF5Error::ChunkedNotSupported,
HDF5Error::TypeMismatch.
Sourcepub fn compound_fields(&self, path: &str) -> Result<Vec<CompoundField>>
pub fn compound_fields(&self, path: &str) -> Result<Vec<CompoundField>>
Compound field layout for path, or empty if not a compound dataset.
Errors: HDF5Error::NotFound.
Sourcepub fn read_raw(&self, path: &str) -> Result<(Vec<usize>, usize, Vec<u8>)>
pub fn read_raw(&self, path: &str) -> Result<(Vec<usize>, usize, Vec<u8>)>
Raw element bytes for any dataset whose storage was materialized (including
compound / Other). Does not reinterpret lanes.
Returns (shape, element_size, bytes).
Errors: HDF5Error::NotFound, HDF5Error::ChunkedNotSupported,
HDF5Error::FilteredNotSupported.
Sourcepub fn read_i16(&self, path: &str) -> Result<(Vec<usize>, Vec<i16>)>
pub fn read_i16(&self, path: &str) -> Result<(Vec<usize>, Vec<i16>)>
Read signed 16-bit little-endian lanes.
Sourcepub fn read_i32(&self, path: &str) -> Result<(Vec<usize>, Vec<i32>)>
pub fn read_i32(&self, path: &str) -> Result<(Vec<usize>, Vec<i32>)>
Read signed 32-bit little-endian lanes.
Sourcepub fn read_i64(&self, path: &str) -> Result<(Vec<usize>, Vec<i64>)>
pub fn read_i64(&self, path: &str) -> Result<(Vec<usize>, Vec<i64>)>
Read signed 64-bit little-endian lanes.
Sourcepub fn read_u16(&self, path: &str) -> Result<(Vec<usize>, Vec<u16>)>
pub fn read_u16(&self, path: &str) -> Result<(Vec<usize>, Vec<u16>)>
Read unsigned 16-bit little-endian lanes.
Sourcepub fn read_u32(&self, path: &str) -> Result<(Vec<usize>, Vec<u32>)>
pub fn read_u32(&self, path: &str) -> Result<(Vec<usize>, Vec<u32>)>
Read unsigned 32-bit little-endian lanes.
Sourcepub fn read_u64(&self, path: &str) -> Result<(Vec<usize>, Vec<u64>)>
pub fn read_u64(&self, path: &str) -> Result<(Vec<usize>, Vec<u64>)>
Read unsigned 64-bit little-endian lanes.
Sourcepub fn read_f64_slice(
&self,
path: &str,
row_start: usize,
row_end: usize,
) -> Result<(Vec<usize>, Vec<u64>)>
pub fn read_f64_slice( &self, path: &str, row_start: usize, row_end: usize, ) -> Result<(Vec<usize>, Vec<u64>)>
Rows [row_start, row_end) along the first axis of an IEEE binary64 dataset.
Errors: HDF5Error::NotFound, HDF5Error::ChunkedNotSupported,
HDF5Error::TypeMismatch, HDF5Error::ShapeMismatch.
Sourcepub fn append_f64(
&mut self,
path: &str,
shape: &[usize],
bits: &[u64],
) -> Result<()>
pub fn append_f64( &mut self, path: &str, shape: &[usize], bits: &[u64], ) -> Result<()>
Append rows to an existing IEEE binary64 dataset. Trailing dimensions must match. Rank-1 appends to the single axis.
Errors: HDF5Error::NotFound, HDF5Error::ShapeMismatch,
HDF5Error::TypeMismatch, HDF5Error::ChunkedNotSupported.
Sourcepub fn append_ieee64(
&mut self,
path: &str,
shape: &[usize],
bits: &[u64],
) -> Result<()>
pub fn append_ieee64( &mut self, path: &str, shape: &[usize], bits: &[u64], ) -> Result<()>
Append IEEE binary64 rows. Same as Self::append_f64.
Sourcepub fn append_f32(
&mut self,
path: &str,
shape: &[usize],
bits: &[u32],
) -> Result<()>
pub fn append_f32( &mut self, path: &str, shape: &[usize], bits: &[u32], ) -> Result<()>
Append IEEE binary32 rows.
Sourcepub fn append_ieee32(
&mut self,
path: &str,
shape: &[usize],
bits: &[u32],
) -> Result<()>
pub fn append_ieee32( &mut self, path: &str, shape: &[usize], bits: &[u32], ) -> Result<()>
Append IEEE binary32 rows. Same as Self::append_f32.
Sourcepub fn append_i32(
&mut self,
path: &str,
shape: &[usize],
bits: &[i32],
) -> Result<()>
pub fn append_i32( &mut self, path: &str, shape: &[usize], bits: &[i32], ) -> Result<()>
Append signed 32-bit rows.
Sourcepub fn append_u64(
&mut self,
path: &str,
shape: &[usize],
bits: &[u64],
) -> Result<()>
pub fn append_u64( &mut self, path: &str, shape: &[usize], bits: &[u64], ) -> Result<()>
Append unsigned 64-bit rows.
Sourcepub fn append_opaque(
&mut self,
path: &str,
shape: &[usize],
data: &[u8],
) -> Result<()>
pub fn append_opaque( &mut self, path: &str, shape: &[usize], data: &[u8], ) -> Result<()>
Append opaque records. data.len() must equal shape.product() * elem_size
of the existing dataset.
Sourcepub fn read_attr_str(&self, path: &str, name: &str) -> Result<String>
pub fn read_attr_str(&self, path: &str, name: &str) -> Result<String>
Read a string attribute on a dataset.
Errors: HDF5Error::NotFound.
Sourcepub fn list_attrs(&self, path: &str) -> Result<Vec<(String, String)>>
pub fn list_attrs(&self, path: &str) -> Result<Vec<(String, String)>>
String attributes on path (name, value), in file order.
Sourcepub fn write_attr_str(
&mut self,
path: &str,
name: &str,
value: &str,
) -> Result<()>
pub fn write_attr_str( &mut self, path: &str, name: &str, value: &str, ) -> Result<()>
Write or replace a string attribute on a dataset.
Errors: HDF5Error::NotFound, HDF5Error::NameTooLong.