diff --git a/crates/clawhdf5/src/lib.rs b/crates/clawhdf5/src/lib.rs index 40ae557..12e2f69 100644 --- a/crates/clawhdf5/src/lib.rs +++ b/crates/clawhdf5/src/lib.rs @@ -144,6 +144,35 @@ mod tests { assert_eq!(ds.dtype().unwrap(), DType::I32); } + #[test] + fn dataset_raw_datatype() { + use clawhdf5_format::datatype::Datatype; + let bytes = make_simple_file(); + let file = File::from_bytes(bytes).unwrap(); + let dt = file.dataset("counts").unwrap().raw_datatype().unwrap(); + assert!( + matches!( + dt, + Datatype::FixedPoint { + size: 4, + signed: true, + .. + } + ), + "{dt:?}" + ); + // The full type pairs with read_selection's bytes. + let raw = file + .dataset("counts") + .unwrap() + .read_selection(&Selection::All) + .unwrap(); + assert_eq!( + clawhdf5_format::data_read::read_as_i64(&raw, &dt).unwrap(), + vec![10, 20, 30] + ); + } + #[test] fn root_group_datasets() { let bytes = make_simple_file(); diff --git a/crates/clawhdf5/src/reader.rs b/crates/clawhdf5/src/reader.rs index 65c0292..b0c8d9c 100644 --- a/crates/clawhdf5/src/reader.rs +++ b/crates/clawhdf5/src/reader.rs @@ -416,6 +416,15 @@ impl<'f> Dataset<'f> { Ok(classify_datatype(&dt)) } + /// Returns the dataset's full datatype as stored in the file (byte order, + /// string padding, compound layout, ...), with a committed datatype + /// resolved. Use it with the `clawhdf5_format::data_read` converters on + /// the bytes [`read_selection`](Self::read_selection) returns, for types + /// the typed `read_*` methods do not cover. + pub fn raw_datatype(&self) -> Result { + self.datatype() + } + /// Read all data as `f64` values. pub fn read_f64(&self) -> Result, Error> { let dt = self.datatype()?;