pub struct SwmrFileReader { /* private fields */ }Expand description
SWMR reader for monitoring a streaming HDF5 file.
Opens a file being written by a concurrent SwmrFileWriter and
periodically calls refresh to pick up new data.
use rust_hdf5::swmr::SwmrFileReader;
let mut reader = SwmrFileReader::open("stream.h5").unwrap();
loop {
reader.refresh().unwrap();
let names = reader.dataset_names();
if let Some(shape) = reader.dataset_shape("frames").ok() {
println!("frames shape: {:?}", shape);
if shape[0] > 0 {
let data = reader.read_dataset_raw("frames").unwrap();
println!("got {} bytes", data.len());
break;
}
}
std::thread::sleep(std::time::Duration::from_millis(100));
}Implementations§
Source§impl SwmrFileReader
impl SwmrFileReader
Sourcepub fn open<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>
Open an HDF5 file for SWMR reading using the env-var-derived
locking policy. Takes a shared lock so it coexists with the
downgraded shared lock held by SwmrFileWriter after
start_swmr, and with other concurrent SWMR readers.
Sourcepub fn open_with_locking<P: AsRef<Path>>(
path: P,
locking: FileLocking,
) -> Result<Self>
pub fn open_with_locking<P: AsRef<Path>>( path: P, locking: FileLocking, ) -> Result<Self>
Open an HDF5 file for SWMR reading with an explicit locking policy.
Sourcepub fn refresh(&mut self) -> Result<()>
pub fn refresh(&mut self) -> Result<()>
Re-read the superblock and dataset metadata from disk.
Call this periodically to pick up new data written by the concurrent SWMR writer.
Sourcepub fn dataset_names(&self) -> Vec<String>
pub fn dataset_names(&self) -> Vec<String>
Return the names of all datasets.
Sourcepub fn dataset_shape(&self, name: &str) -> Result<Vec<u64>>
pub fn dataset_shape(&self, name: &str) -> Result<Vec<u64>>
Return the current shape of a dataset.
Sourcepub fn read_dataset_raw(&mut self, name: &str) -> Result<Vec<u8>>
pub fn read_dataset_raw(&mut self, name: &str) -> Result<Vec<u8>>
Read the raw bytes of a dataset.
Sourcepub fn read_dataset<T: H5Type>(&mut self, name: &str) -> Result<Vec<T>>
pub fn read_dataset<T: H5Type>(&mut self, name: &str) -> Result<Vec<T>>
Read a dataset as a typed vector.
Sourcepub fn read_slice_raw(
&mut self,
name: &str,
starts: &[u64],
counts: &[u64],
) -> Result<Vec<u8>>
pub fn read_slice_raw( &mut self, name: &str, starts: &[u64], counts: &[u64], ) -> Result<Vec<u8>>
Read a slice (hyperslab) of a dataset as raw bytes.
starts[d] is the first index along dimension d, counts[d] is how
many. For a streaming dataset this reads only the chunks the slice
overlaps — the efficient way for a live viewer to fetch the latest
frame without re-reading the whole stream.
Sourcepub fn read_slice<T: H5Type>(
&mut self,
name: &str,
starts: &[u64],
counts: &[u64],
) -> Result<Vec<T>>
pub fn read_slice<T: H5Type>( &mut self, name: &str, starts: &[u64], counts: &[u64], ) -> Result<Vec<T>>
Read a slice (hyperslab) of a dataset as a typed vector.
See read_slice_raw.
Sourcepub fn read_vlen_strings(&mut self, name: &str) -> Result<Vec<String>>
pub fn read_vlen_strings(&mut self, name: &str) -> Result<Vec<String>>
Read a variable-length string dataset.
Sourcepub fn dataset_element_size(&self, name: &str) -> Result<usize>
pub fn dataset_element_size(&self, name: &str) -> Result<usize>
Element size of a dataset’s datatype, in bytes — enough to size a read buffer without knowing the concrete element type at compile time.
Sourcepub fn group_paths(&self) -> Vec<String>
pub fn group_paths(&self) -> Vec<String>
All group paths in the file.
Sourcepub fn has_group(&self, group_path: &str) -> bool
pub fn has_group(&self, group_path: &str) -> bool
Whether a group exists. A leading / is tolerated.
Sourcepub fn dataset_attr_names(&self, name: &str) -> Result<Vec<String>>
pub fn dataset_attr_names(&self, name: &str) -> Result<Vec<String>>
Names of the attributes on a dataset.
Sourcepub fn dataset_attr_string(
&mut self,
dataset: &str,
attr: &str,
) -> Result<String>
pub fn dataset_attr_string( &mut self, dataset: &str, attr: &str, ) -> Result<String>
Read a dataset’s attribute as a string (e.g. units, NX_class).
Sourcepub fn group_attr_names(&self, group_path: &str) -> Vec<String>
pub fn group_attr_names(&self, group_path: &str) -> Vec<String>
Names of the attributes on a group, or on the root group when
group_path is "/". A leading / is tolerated.