hdf5-pure
Pure-Rust HDF5 reader/writer. No C dependencies, no build scripts, WASM-compatible.
Features
- Write HDF5 files with datasets, groups, attributes, and nested hierarchies
- Read HDF5 files (v0/v1/v2/v3 superblocks, v1/v2 object headers, contiguous/chunked/compact storage)
- No C dependencies — compiles to
wasm32-unknown-unknownwith--no-default-features - MATLAB v7.3 compatible — userblock support, fixed-length ASCII attributes, variable-length string arrays, object references
- Deflate and shuffle compression
- Compound types, enumerations, array types
- Complex number datasets (as compound
{real, imag})
Quick start
Writing
use ;
let mut builder = new;
// Datasets
builder.create_dataset
.with_f64_data
.with_shape;
// Groups with nested datasets
let mut grp = builder.create_group;
grp.create_dataset.with_f32_data;
grp.set_attr;
builder.add_group;
// Attributes on the root group
builder.set_attr;
builder.write.unwrap;
Reading
use File;
let file = open.unwrap;
let ds = file.dataset.unwrap;
println!; // [3]
println!; // [22.5, 23.1, 21.8]
let attrs = file.root.attrs.unwrap;
println!; // Some(I64(2))
In-memory (WASM)
use FileBuilder;
let mut builder = new;
builder.create_dataset.with_f64_data;
let bytes: = builder.finish.unwrap; // no filesystem needed
Supported data types
Datasets
| Method | HDF5 type |
|---|---|
with_f64_data |
IEEE 64-bit float |
with_f32_data |
IEEE 32-bit float |
with_i8_data / with_i16_data / with_i32_data / with_i64_data |
Signed integers |
with_u8_data / with_u16_data / with_u32_data / with_u64_data |
Unsigned integers |
with_complex32_data |
Compound {real: f32, imag: f32} |
with_complex64_data |
Compound {real: f64, imag: f64} |
with_compound_data |
Arbitrary compound types |
with_enum_i32_data / with_enum_u8_data |
Enumeration types |
with_array_data |
Fixed-size array types |
with_path_references |
Object references (resolved by path) |
with_dtype + with_shape |
Empty/zero-dimension datasets |
Attributes
| Variant | HDF5 encoding |
|---|---|
AttrValue::F64 / F64Array |
64-bit float scalar/array |
AttrValue::I32 / I64 / I64Array |
Signed integer scalar/array |
AttrValue::U32 / U64 |
Unsigned integer scalar |
AttrValue::String / StringArray |
UTF-8 null-padded string |
AttrValue::AsciiString |
Fixed-length ASCII string |
AttrValue::VarLenAsciiArray |
Variable-length ASCII string array (global heap) |
Compression
// Deflate (zlib)
builder.create_dataset
.with_f64_data
.with_chunks
.with_deflate;
// Shuffle + deflate
builder.create_dataset
.with_f64_data
.with_chunks
.with_shuffle
.with_deflate;
Userblock (MATLAB v7.3)
let mut builder = new;
builder.with_userblock;
builder.create_dataset.with_f64_data;
let mut bytes = builder.finish.unwrap;
// Write MATLAB header into userblock
bytes = b'I';
bytes = b'M';
MATLAB struct pattern
use ;
let mut builder = new;
let mut grp = builder.create_group;
let mut fields = Vecnew;
for in
grp.set_attr;
grp.set_attr;
builder.add_group;
Cargo features
| Feature | Default | Description |
|---|---|---|
std |
yes | File I/O, high-level reader API |
checksum |
yes | Jenkins hash for v2+ object headers |
deflate |
yes | Deflate compression (pure Rust backend) |
fast-checksum |
no | Hardware-accelerated CRC32 via crc32fast |
fast-deflate |
no | zlib-ng backend for deflate via flate2/zlib-ng |
mmap |
no | Memory-mapped file reading via memmap2 |
parallel |
no | Parallel chunk processing via rayon |
provenance |
no | SHA-256 data provenance tracking |
For WASM, disable default features:
[]
= { = "0.1", = false, = ["checksum"] }
Acknowledgements
The HDF5 format parsing and low-level I/O modules are derived from rustyhdf5 by the RustyStack project (MIT licensed).
License
MIT