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:

  1. GetMetadata(string? tag, uint index, out ChdMetadataEntry?) β€” mirrors chd_get_metadata (tag search, occurrence index, wildcard via null/empty tag, Chderrmetadatanotfound).
  2. ChdMetadataEntry.Flags β€” exposes the metadata flags byte (libchdr’s resultflags).
  3. ChdFile.Precache() β€” mirrors chd_precache (whole compressed file in memory, idempotent, stream position restored).
  4. 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 chdman never 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.