Comparison with libchdr
This page compares CHDSharp against the C reference library libchdr 0.3.0, which CHDSharp uses as a parity baseline.
Headline
CHDSharp is a feature superset of libchdr 0.3.0: it implements everything libchdr does (plus AVHuff, which libchdr does not implement), adds verification, extraction, async APIs, and metadata support, and has zero native dependencies β where libchdr bundles zlib (miniz), LZMA SDK, zstd, and dr_flac, CHDSharp ships managed implementations.
Five-way comparison: CHDSharp vs chd-rs vs CHDlite vs chdman vs libchdr
CHDSharp vs the two other independent CHD implementations (chd-rs 0.3.4 and CHDlite 0.2.1), MAMEβs reference chdman (0.288), and libchdr 0.3.0. The CHDSharp column covers the whole repo (reader + encoder (CHDSharp.Encoder) + CLI). β
= supported, π‘ = partial, β = not supported, β = not applicable (CLI).
| Capability | CHDSharp (this repo) | chd-rs 0.3.4 (Rust) | CHDlite 0.2.1 (C++) | chdman (MAME 0.288) |
libchdr 0.3.0 (C) |
|---|---|---|---|---|---|
| Reading | Β | Β | Β | Β | Β |
| Read V1βV5 | β | β | π‘ V3βV5 only (rejects V1/V2) | β | β |
| All 10 codecs (decode) | β | β | β | β (reference) | π‘ 9 of 10 (no AVHuff) |
| Parent/child chains (read) | β | β | β | β | β |
| Per-hunk CRC16/CRC32 verification | β always | π‘ opt-in feature, off by default | β always | β always | π‘ V5 CRC16 build option (on by default); V3/V4 CRC32 never checked |
| Full-image verify (rawsha1 + combined SHA1) | β parallel | π‘ raw SHA1 only | β sequential | β sequential | β no verify function |
verify --fix (repair header hashes) |
β | β | β | β | β |
| Track/TOC parsing (CD/GD-ROM) | β
Tracks/ChdTrackInfo |
π‘ tags recognized, no track model | β | β | β |
| Metadata read | β | β | β | β | β
chd_get_metadata |
| Writing | Β | Β | Β | Β | Β |
| Write V5 | β (encoder) | β read-only | β | β (reference) | β read-only |
| All 10 codecs (encode) | β
all 10 (avhu via createld, byte-identical) |
β | β | β | β |
Uncompressed CHD (-c none) |
β byte-exact with chdman | π‘ decode only | π‘ core supports, CLI rejects | β | π‘ decode only |
Delta/parent CHD creation (-ip) |
β | β | β | β | β |
| CHDβCHD copy / re-compress | β | β | β | β | β |
| Metadata write (addmeta/delmeta) | β | β | β | β | β |
| IDNT/KEY/CIS metadata read/write | β | β | β | β | β |
| Input formats | Β | Β | Β | Β | Β |
| CUE / GDI / ISO / TOC / NRG parsing | β all five | β | β all five | β all five | β |
| CUE style conversion / Redump match | β | β | β | β
convertcue |
β |
| API & reads | Β | Β | Β | Β | Β |
| Byte-range reads | β
Read(offset, ...) |
β
Read + Seek |
β
read_bytes |
β | β hunk-only chd_read |
| LBA/MSF sector-addressed reads | β
ReadSector/ReadSectorMsf/ReadFrame + CdRomAddress |
β | β
read_sector + msf_to_lba/lba_to_msf |
β | β |
| Thread-safe random access | β
ReadHunkConcurrent |
β | β | β | β |
| Async I/O API | β | β | π‘ async compress pump only | β | β |
| Cancellation + progress reporting | β on all long-running APIs | β | π‘ cancel + callbacks via C API | β | β |
| Precache / multi-hunk LRU cache | β both | β | π‘ single-hunk cache | β | π‘ chd_precache, no hunk cache |
| Header-only DTO read | β
Chd.ReadHeader (libchdr parity) |
π‘ Header struct exposed |
π‘ via ChdReader |
β
info |
β
chd_read_header |
| Performance & tooling | Β | Β | Β | Β | Β |
| Parallel verification | β (default 8 workers) | β | β | β | β |
| Parallel encoding | β (1β64 workers) | β | β (β€ 16, per-codec weighted queues) | β (β€ 16 work-queue threads) | β |
| Benchmarks | β BenchmarkDotNet + chdman comparer | β
benches/ |
β
benchmark_chd.cpp |
β | π‘ tests/benchmark.c (minimal timing harness) |
| Fuzzing / mutation testing | β 3500-seed deterministic suite | β cargo-fuzz target | β | β | π‘ tests/fuzz.c (libFuzzer harness) |
| Extras | Β | Β | Β | Β | Β |
| Extraction (CUE/BIN, GDI, ISO) | β | π‘ raw dump only | β | β | β |
| Platform/game detection | β 11 systems (CHDlite parity) | β | β 11 systems | β | β |
| Multi-hash output (SHA-256/CRC32/XXH3) | β SHA1/SHA256/CRC32/XXH3 | β | β SHA1/MD5/CRC32/SHA256/XXH3 | π‘ SHA1/MD5 only | β |
| Batch mode (folder scan) | β | β | β | β | β |
| Native dependencies | none (pure C#) | none (pure-Rust crates) | zlib-ng / zstd / lzma / flac | zlib / lzma / flac | zlib (miniz) / LZMA SDK / zstd / dr_flac |
| Language | C# (.NET 8/9/10/11) | Rust | C++ | C++ (MAME) | C |
The same table is also in the repository README.
Feature matrix
| Feature | libchdr 0.3.0 (C) | CHDSharp (C#) |
|---|---|---|
| CHD V1βV5 headers | β | β |
| V1/V2 maps (packed entries, self-dedup) | β | β |
| V3/V4 maps (CRC32, mini/self/parent hunks) | β | β |
| V5 compressed map (Huffman+RLE) | β | β |
| V5 uncompressed map | β | β |
| V5 unit-based parent references (incl. unaligned/straddling) | β | β |
zlib / cdzl |
β (miniz) | β (managed) |
lzma / cdlz |
β (LZMA SDK) | β (custom C# port) |
huff |
β | β |
flac / cdfl |
β (dr_flac) | β (custom C# decoder) |
zstd / cdzs |
β (zstd 1.5.7) | β (in-repo VendoredZSTD, zstd 1.5.5 port) |
avhu (AVHuff) |
β (known limitation) | β |
Secondary codec (ZLIB_PLUS type-6 hunks) |
β declared but unimplemented | β |
| Per-hunk CRC32 verification (V3/V4) | β stored, never checked | β (honors NO_CRC) |
| Per-hunk CRC16 verification (V5) | β (build option, default on) | β |
| Full-image verification (SHA1/MD5/rawsha1) | β no verify function | β parallel |
| Combined metadata-SHA1 verification | β | β |
| Metadata query by tag/index/flags | β
chd_get_metadata |
β
GetMetadata + Metadata list |
| V1/V2 synthesized GDDD metadata | β | β |
chd_precache (whole file in RAM) |
β | β
Precache() |
Random access (chd_read / ReadHunk, Read) |
β | β |
| Byte-range reads | β (hunk-only) | β
Read(offset, ...) |
| Sector-addressed reads (LBA/MSF) | β requested (#155) | β
ReadSector/ReadSectorMsf/ReadFrame + CdRomAddress |
| Async API | β | β |
| Extraction (CUE/GDI/ISO/IMG/RAW) | β | β |
| TOC / track parsing | β | β
Tracks/ChdTrackInfo |
| Classification (cd/dvd/hdd/gd-rom) | β | β |
Custom IO (callbacks vs Stream) |
β core_file callbacks | β
Stream overloads |
| Thread-safe logging | β | β
ILoggerFactory |
| CHD creation | β (commented out) | β
CHDSharp.Encoder |
| Native dependencies | zlib, lzma, flac, zstd | none |
Parity work in this repository
To close the small gaps found during the comparison, the library gained:
GetMetadata(string? tag, uint index, out ChdMetadataEntry?)β mirrorschd_get_metadata(tag search, occurrence index, wildcard vianull/empty tag,Chderrmetadatanotfound).ChdMetadataEntry.Flagsβ exposes the metadata flags byte (libchdrβsresultflags).ChdFile.Precache()β mirrorschd_precache(whole compressed file in memory, idempotent, stream position restored).- V1/V2 synthesized GDDD metadata β matches libchdrβs behavior of fabricating
CYLS:β¦,HEADS:β¦,SECS:β¦,BPS:β¦from the obsolete header fields.
All four are covered by ParityFeaturesTests.
Deliberate differences (CHDSharp is stricter)
| Area | libchdr | CHDSharp | Why |
|---|---|---|---|
| V3/V4 CRC32 | never verified | verified (unless NO_CRC) | matches MAME semantics; catches corrupt files libchdr silently accepts |
V3/V4 ZLIB_PLUS type-6 hunks |
falls through, returns success with empty output | fully decoded (secondary codec) | correctness |
| AVHuff | unsupported (open fails or errors) | fully decoded | feature |
| Metadata errors | CHDERR_METADATA_NOT_FOUND only |
also Chderrreaderror/Chderrinvaliddata surfaced |
diagnostics |
Open(Stream) IO failures |
returns errors | returns errors (never throws) | robustness |
Notes on decoder stacks
- FLAC: libchdr uses dr_flac 0.13.3 (battle-tested, full spec). CHDSharpβs custom decoder covers everything CHD content uses β 16/24-bit, all channel modes incl. mid/side, fixed/LPC subframes (orders 1β32), all block sizes, Rice coding, CRC-8/16 β and rejects unsupported cases (e.g. 8/12/20-bit, custom sample-rate codes) that
chdmannever produces. The corpus includes FLAC, cdfl, and AVHuff-FLAC fixtures. - LZMA: both synthesize the fixed properties (lc=3, lp=0, pb=2, dict = hunk size) since CHD hunks are headerless; CHDSharpβs port also supports LZMA2 and preset dictionaries internally.
- Zstd: libchdr uses zstd 1.5.7 native; CHDSharp uses an in-repo pure C# port of the zstd 1.5.5 tree that MAME bundles (
VendoredZSTD). Both handle single-frame blocks correctly and produce byte-identical output for the same hunk buffers.
When to use which
- Use CHDSharp when you want a managed, dependency-free reader with verification, metadata, extraction, and modern .NET ergonomics (async, nullable,
IAsyncDisposable). - Use libchdr when you need a C library for embedding in C/C++ projects, or want the (extremely well-tested) native zstd/LZMA/FLAC stacks and do not need AVHuff, verification, or extraction.