#![cfg(feature = "deflate")]
use std::path::PathBuf;
use std::sync::atomic::{AtomicU64, Ordering};
use rust_hdf5::H5File;
const MASK1: &[u8] = include_bytes!("fixtures/single_chunk_deflate_mask1.h5");
const MASK0: &[u8] = include_bytes!("fixtures/single_chunk_deflate_mask0.h5");
fn write_temp(label: &str, bytes: &[u8]) -> PathBuf {
static COUNTER: AtomicU64 = AtomicU64::new(0);
let n = COUNTER.fetch_add(1, Ordering::Relaxed);
let dir = std::env::temp_dir().join(format!(
"rust_hdf5_single_chunk_{}_{}_{}",
label,
std::process::id(),
n
));
std::fs::create_dir_all(&dir).unwrap();
let path = dir.join(format!("{label}.h5"));
std::fs::write(&path, bytes).unwrap();
path
}
fn cleanup(path: &PathBuf) {
let _ = std::fs::remove_file(path);
if let Some(dir) = path.parent() {
let _ = std::fs::remove_dir_all(dir);
}
}
#[test]
fn single_chunk_filter_mask1_skips_the_filter() {
let path = write_temp("mask1", MASK1);
let file = H5File::open(&path).unwrap();
let ds = file.dataset("x").unwrap();
let got = ds.read_raw::<u8>().unwrap();
assert_eq!(
got,
(0u8..64).collect::<Vec<u8>>(),
"single chunk with filter_mask=1 must be read as raw stored bytes"
);
drop(file);
cleanup(&path);
}
#[test]
fn single_chunk_filter_mask0_reverses_the_filter() {
let path = write_temp("mask0", MASK0);
let file = H5File::open(&path).unwrap();
let ds = file.dataset("y").unwrap();
let got = ds.read_raw::<u8>().unwrap();
assert_eq!(
got,
(0u8..64).collect::<Vec<u8>>(),
"single chunk with filter_mask=0 must inflate back to the original"
);
drop(file);
cleanup(&path);
}