use hdf5_pure::{File, FileBuilder};
fn main() {
let dir = tempfile::tempdir().expect("temp dir");
let path = dir.path().join("log.h5");
let initial: Vec<i32> = (0..8).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])
.with_shuffle()
.with_deflate(6);
builder.write(&path).expect("write initial file");
{
let file = File::open(&path).expect("reopen for introspection");
let ds = file.dataset("samples").expect("open dataset");
assert!(ds.is_chunked());
assert_eq!(ds.maxshape().unwrap(), Some(vec![u64::MAX])); assert_eq!(ds.chunk_shape().unwrap(), Some(vec![4]));
assert_eq!(ds.filters(), vec![2, 1]); println!(
"eligible: chunked={}, maxshape={:?}, chunks={:?}, filters={:?}",
ds.is_chunked(),
ds.maxshape().unwrap(),
ds.chunk_shape().unwrap(),
ds.filters(),
);
}
{
let session = File::open_rw(&path).expect("open for editing");
session
.dataset("samples")
.unwrap()
.append_staged(|b| {
b.append_i32(&[8, 9, 10, 11, 12, 13, 14, 15]);
})
.unwrap();
session.commit().expect("commit aligned append");
}
{
let session = File::open_rw(&path).expect("open for editing");
session
.dataset("samples")
.unwrap()
.append_staged(|b| {
b.append_i32(&[16, 17, 18, 19, 20]);
})
.unwrap();
session.commit().expect("commit unaligned append");
}
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..21).collect::<Vec<_>>());
println!("in-place append verified");
}