pub struct SwmrFileWriter { /* private fields */ }Expand description
SWMR writer for streaming frame-based data to an HDF5 file.
Usage:
use rust_hdf5::swmr::SwmrFileWriter;
let mut writer = SwmrFileWriter::create("stream.h5").unwrap();
let ds = writer.create_streaming_dataset::<f32>("frames", &[256, 256]).unwrap();
writer.start_swmr().unwrap();
// Write frames
let frame_data = vec![0.0f32; 256 * 256];
let raw: Vec<u8> = frame_data.iter()
.flat_map(|v| v.to_le_bytes())
.collect();
writer.append_frame(ds, &raw).unwrap();
writer.flush().unwrap();
writer.close().unwrap();Implementations§
Source§impl SwmrFileWriter
impl SwmrFileWriter
Sourcepub fn create<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn create<P: AsRef<Path>>(path: P) -> Result<Self>
Create a new HDF5 file for SWMR streaming using the env-var-derived locking policy.
Sourcepub fn create_with_locking<P: AsRef<Path>>(
path: P,
locking: FileLocking,
) -> Result<Self>
pub fn create_with_locking<P: AsRef<Path>>( path: P, locking: FileLocking, ) -> Result<Self>
Create a new HDF5 file for SWMR streaming with an explicit locking
policy. The writer holds an exclusive lock until Self::start_swmr
is called, at which point the lock is downgraded to shared so
concurrent SWMR readers can attach.
Sourcepub fn create_streaming_dataset<T: H5Type>(
&mut self,
name: &str,
frame_dims: &[u64],
) -> Result<usize>
pub fn create_streaming_dataset<T: H5Type>( &mut self, name: &str, frame_dims: &[u64], ) -> Result<usize>
Create a streaming dataset.
The dataset will have shape [0, frame_dims...] initially, with
chunk dimensions [1, frame_dims...] and unlimited first dimension.
Returns the dataset index for use with append_frame.
Sourcepub fn create_streaming_dataset_compressed<T: H5Type>(
&mut self,
name: &str,
frame_dims: &[u64],
pipeline: FilterPipeline,
) -> Result<usize>
pub fn create_streaming_dataset_compressed<T: H5Type>( &mut self, name: &str, frame_dims: &[u64], pipeline: FilterPipeline, ) -> Result<usize>
Create a streaming dataset whose frames are compressed.
Like create_streaming_dataset but
each appended frame is run through pipeline (e.g.
FilterPipeline::deflate(4)). SWMR appends and in-place header
updates work the same as for uncompressed streaming datasets.
Sourcepub fn start_swmr(&mut self) -> Result<()>
pub fn start_swmr(&mut self) -> Result<()>
Signal the start of SWMR mode.
Sourcepub fn append_frame(&mut self, ds_index: usize, data: &[u8]) -> Result<()>
pub fn append_frame(&mut self, ds_index: usize, data: &[u8]) -> Result<()>
Append a frame of raw data to a streaming dataset.
The data size must match one frame (product of frame_dims * element_size).