pub struct H5File { /* private fields */ }Expand description
An HDF5 file opened for reading or writing.
Datasets created from this file hold a shared reference to the underlying I/O handle, so the file does not need to outlive its datasets (they share ownership via reference counting).
Implementations§
Source§impl H5File
impl H5File
Sourcepub fn create<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn create<P: AsRef<Path>>(path: P) -> Result<Self>
Create a new HDF5 file at path. Truncates if the file already exists.
Sourcepub fn open_rw<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn open_rw<P: AsRef<Path>>(path: P) -> Result<Self>
Open an existing HDF5 file for appending new datasets.
Existing datasets are preserved. New datasets can be added and will
be written after the current end of file. Existing chunked datasets
can be extended with write_chunk and extend_dataset.
use rust_hdf5::H5File;
let file = H5File::open_rw("existing.h5").unwrap();
let ds = file.new_dataset::<f64>().shape(&[100]).create("new_data").unwrap();
ds.write_raw(&vec![0.0f64; 100]).unwrap();
file.close().unwrap();Sourcepub fn root_group(&self) -> H5Group
pub fn root_group(&self) -> H5Group
Return a handle to the root group.
The root group can be used to create datasets and sub-groups.
Sourcepub fn create_group(&self, name: &str) -> Result<H5Group>
pub fn create_group(&self, name: &str) -> Result<H5Group>
Create a group in the root of the file.
use rust_hdf5::H5File;
let file = H5File::create("groups.h5").unwrap();
let grp = file.create_group("detector").unwrap();Sourcepub fn new_dataset<T: H5Type>(&self) -> DatasetBuilder<T>
pub fn new_dataset<T: H5Type>(&self) -> DatasetBuilder<T>
Start building a new dataset with the given element type.
This returns a fluent builder. Call .shape(...) to set dimensions and
.create("name") to finalize.
let file = H5File::create("build.h5").unwrap();
let ds = file.new_dataset::<f64>().shape(&[3, 4]).create("matrix").unwrap();Sourcepub fn set_attr_string(&self, name: &str, value: &str) -> Result<()>
pub fn set_attr_string(&self, name: &str, value: &str) -> Result<()>
Add a string attribute to the file (root group).
Sourcepub fn set_attr_numeric<T: H5Type>(&self, name: &str, value: &T) -> Result<()>
pub fn set_attr_numeric<T: H5Type>(&self, name: &str, value: &T) -> Result<()>
Add a numeric attribute to the file (root group).
Sourcepub fn attr_names(&self) -> Result<Vec<String>>
pub fn attr_names(&self) -> Result<Vec<String>>
Return the names of file-level (root group) attributes.
Sourcepub fn attr_string(&self, name: &str) -> Result<String>
pub fn attr_string(&self, name: &str) -> Result<String>
Read a file-level string attribute.
Sourcepub fn is_writable(&self) -> bool
pub fn is_writable(&self) -> bool
Check if the file is in write/append mode.
Sourcepub fn write_vlen_strings(&self, name: &str, strings: &[&str]) -> Result<()>
pub fn write_vlen_strings(&self, name: &str, strings: &[&str]) -> Result<()>
Create a variable-length string dataset and write data.
This is a convenience method for writing h5py-compatible vlen string datasets using global heap storage.
Sourcepub fn dataset(&self, name: &str) -> Result<H5Dataset>
pub fn dataset(&self, name: &str) -> Result<H5Dataset>
Open an existing dataset by name (read mode).
Sourcepub fn dataset_names(&self) -> Vec<String>
pub fn dataset_names(&self) -> Vec<String>
Return the names of all datasets in the root group.
Works in both read and write mode: in write mode, returns the names of datasets created so far; in read mode, returns the names discovered during file open.