use hdf5_pure::{File, FileBuilder};
fn main() {
let dir = tempfile::tempdir().expect("temp dir");
let path = dir.path().join("stream.h5");
let initial: Vec<i32> = (0..6).collect();
let mut builder = FileBuilder::new();
builder
.create_dataset("samples")
.with_i32_data(&initial)
.with_shape(&[initial.len() as u64])
.with_maxshape(&[u64::MAX])
.with_chunks(&[4]);
builder.write(&path).expect("write initial file");
{
let file = File::open_rw(&path).expect("open for appending");
let mut samples = file.dataset("samples").expect("open dataset handle");
samples.append(&[6i32, 7, 8]).expect("append 1"); samples.append(&[9i32, 10]).expect("append 2"); samples
.append(&(11..20).collect::<Vec<i32>>())
.expect("append 3"); file.close().expect("flush and release the lock");
}
let file = File::open(&path).expect("reopen");
let all = file.dataset("samples").unwrap().read_i32().unwrap();
println!("dataset now holds {} samples: {all:?}", all.len());
assert_eq!(all, (0..20).collect::<Vec<_>>());
println!("streaming in-place append verified");
}