Expand description
An implementation of the MAME CHD (Compressed Hunks of Data) format in pure Safe Rust, with support for CHD V1-5.
§Supported Compression Codecs
chd-rs supports the following compression codecs.
- None
- Zlib/Zlib+/Zlib V5
- CDZL (CD Zlib)
- CDLZ (CD LZMA)
- CDFL (CD FLAC)
- FLAC (Raw FLAC)
- LZMA (Raw LZMA)
- Huff (MAME Static Huffman)
- AVHU (AV Huffman)
- Zstandard
- CDZS (CD Zstandard)
§Iterating over hunks
Because Hunk keeps a mutable reference to its owning
Chd, direct iteration of hunks is not possible without
Generic Associated Types. Instead, the hunk indices should be iterated over.
use std::fs::File;
use std::io::BufReader;
use chd::Chd;
let mut f = BufReader::new(File::open("file.chd")?);
let mut chd = Chd::open(&mut f, None)?;
let hunk_count = chd.header().hunk_count();
let hunk_size = chd.header().hunk_size();
// buffer to store uncompressed hunk data must be the same length as the hunk size.
let mut hunk_buf = chd.get_hunksized_buffer();
// buffer to store compressed data.
let mut cmp_buf = Vec::new();
for hunk_num in 0..hunk_count {
let mut hunk = chd.hunk(hunk_num)?;
hunk.read_hunk_in(&mut cmp_buf, &mut hunk_buf)?;
}§Iterating over metadata
Metadata in a CHD file consists of a list of entries that contain offsets to the byte data of the metadata contents in the CHD file. The individual metadata entries can be iterated directly, but a reference to the source stream has to be provided to read the data.
use std::fs::File;
use std::io::BufReader;
use chd::Chd;
let mut f = BufReader::new(File::open("file.chd")?);
let mut chd = Chd::open(&mut f, None)?;
let entries = chd.metadata_refs()?;
for entry in entries {
let metadata = entry.read(&mut f)?;
}Vec<Metadata> implements TryFrom<MetadataRefs> so all metadata entries
can be collected at once without requiring a reference to the file.
use std::fs::File;
use std::io::BufReader;
use chd::Chd;
use chd::metadata::Metadata;
let mut f = BufReader::new(File::open("file.chd")?);
// chd takes ownership of f here
let mut chd = Chd::open(f, None)?;
let metadatas: Vec<Metadata> = chd.metadata_refs()?.try_into()?;Modules§
- codecs
codec_api - Implementations of decompression codecs used in MAME CHD.
- header
- Types and methods relating to header data for a CHD file.
- huffman
huffman_api - Implementation of the MAME CHD Huffman Decoder.
- iter
unstable_lending_iterators - Traits and implementations for lending iterators for hunks and metadata.
These APIs should be considered unstable and will be replaced with APIs
based around GATs and
LendingIteratoronce stabilized. See rust#44265 for the tracking issue on GAT stabilization. - map
- Types and methods relating to the CHD hunk map.
- metadata
- Types and methods relating to metadata stored in a CHD file.
- read
- Helpers and adapters for reading CHD files and hunks.
Structs§
Enums§
- Error
- Error types that may occur when reading a CHD file or hunk.
Type Aliases§
- Result
- Result type for chd-rs.