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 create_streaming_dataset_tiled<T: H5Type>(
&mut self,
name: &str,
frame_dims: &[u64],
frame_chunk: &[u64],
) -> Result<usize>
pub fn create_streaming_dataset_tiled<T: H5Type>( &mut self, name: &str, frame_dims: &[u64], frame_chunk: &[u64], ) -> Result<usize>
Create a streaming dataset whose frames are split into fixed-size chunk tiles.
frame_dims is the per-frame shape (e.g. [1024, 1024]);
frame_chunk is the tile shape within a frame (e.g. [256, 256]),
of the same rank. The on-disk chunk shape becomes
[1, frame_chunk...], so each frame is stored as
product(frame_dims / frame_chunk) chunks instead of one. This
mirrors area-detector tiling controls such as NDFileHDF5’s
nRowChunks / nColChunks: it changes only the partial-read
granularity and compression unit, not the stored data.
append_frame accepts a whole frame and
splits it into tiles automatically.
Sourcepub fn create_streaming_dataset_tiled_compressed<T: H5Type>(
&mut self,
name: &str,
frame_dims: &[u64],
frame_chunk: &[u64],
pipeline: FilterPipeline,
) -> Result<usize>
pub fn create_streaming_dataset_tiled_compressed<T: H5Type>( &mut self, name: &str, frame_dims: &[u64], frame_chunk: &[u64], pipeline: FilterPipeline, ) -> Result<usize>
Create a compressed streaming dataset whose frames are split into
fixed-size chunk tiles. See
create_streaming_dataset_tiled
for the meaning of frame_chunk; each tile is the compression unit.
Sourcepub fn create_streaming_dataset_chunked<T: H5Type>(
&mut self,
name: &str,
frame_dims: &[u64],
chunk: &[u64],
) -> Result<usize>
pub fn create_streaming_dataset_chunked<T: H5Type>( &mut self, name: &str, frame_dims: &[u64], chunk: &[u64], ) -> Result<usize>
Create a streaming dataset with full control over the chunk shape, including the frame axis.
chunk is the complete per-chunk shape, of rank
frame_dims.len() + 1: chunk[0] frames per chunk (the NDFileHDF5
nFramesChunks control) and chunk[1..] the per-frame tile shape
(nRowChunks / nColChunks). When chunk[0] > 1,
append_frame buffers whole frames until a
chunk band fills; the final partial band is written (zero-padded) at
close, and the dataset’s logical frame count always
equals the exact number of frames appended.
Sourcepub fn create_streaming_dataset_chunked_compressed<T: H5Type>(
&mut self,
name: &str,
frame_dims: &[u64],
chunk: &[u64],
pipeline: FilterPipeline,
) -> Result<usize>
pub fn create_streaming_dataset_chunked_compressed<T: H5Type>( &mut self, name: &str, frame_dims: &[u64], chunk: &[u64], pipeline: FilterPipeline, ) -> Result<usize>
Compressed variant of
create_streaming_dataset_chunked;
each chunk is filtered independently through pipeline.
Sourcepub fn create_hard_link(
&mut self,
parent_group_path: &str,
link_name: &str,
target_path: &str,
) -> Result<()>
pub fn create_hard_link( &mut self, parent_group_path: &str, link_name: &str, target_path: &str, ) -> Result<()>
Create a hard link: an additional name for a dataset or group that already exists in the file.
No data is copied — the link and its target share one object header,
exactly as h5py / libhdf5 hard links do. This is the NeXus-style way
to expose a streaming dataset at an aliased path.
parent_group_path— full path of the group that will hold the link ("/"for the root group).link_name— leaf name of the new link within that group.target_path— full path of an existing dataset or group.
§Visibility relative to SWMR mode
A link created before start_swmr is committed
by start_swmr and is visible to SWMR readers for the whole streaming
window. A link created after start_swmr is committed only by
close; it does not appear to readers that attach
during the live SWMR window. Create layout links before start_swmr
when readers must resolve them while streaming.
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).