Class ChdFile
- Namespace
- CHDSharp
- Assembly
- CHDSharpLib.dll
Provides read-only random access to a CHD (Compressed Hunks of Data) file, supporting format versions 1-5 and parent/child differential CHD chains.
public sealed class ChdFile : IDisposable, IAsyncDisposable
- Inheritance
-
ChdFile
- Implements
- Inherited Members
Examples
var err = ChdFile.Open("game.chd", out var chd);
if (err != ChdError.Chderrnone) return;
using (chd)
{
var hunk = new byte[chd.HunkBytes];
chd.ReadHunk(0, hunk); // first decompressed hunk
var buf = new byte[1024];
chd.Read(0x10000, buf, 0, buf.Length); // arbitrary byte range
}
Remarks
Open a standalone CHD with Open(string, out ChdFile?, CancellationToken). For a child (differential) CHD, supply its parent with Open(string, string?, out ChdFile?, CancellationToken) or Open(string, ChdFile?, out ChdFile?, CancellationToken). Then decompress individual hunks with ReadHunk(uint, byte[], CancellationToken), read arbitrary byte ranges with Read(ulong, byte[], int, int, CancellationToken), or iterate the whole image with EnumerateHunks(IProgress<ChdProgress>?). Async variants of every operation are available ( OpenAsync(string, CancellationToken), ReadHunkAsync(uint, byte[], CancellationToken), ReadAsync(ulong, byte[], int, int, CancellationToken)).
Always dispose the instance (using / await using); this closes the
underlying stream (unless opened with leaveOpen: true) and any internally
opened parent CHD.
Thread safety: an instance is NOT thread-safe. It seeks a shared stream and mutates shared per-hunk buffers, so all calls must be serialized by the caller. Multiple ChdFile instances over separate streams may be used in parallel.
Fields
MetadataChecksumFlag
Flags a metadata entry as covered by the combined-SHA1 verification (CHD_MDFLAGS_CHECKSUM).
public const byte MetadataChecksumFlag = 1
Field Value
Properties
CacheSize
Number of decompressed hunks retained by the multi-hunk LRU cache (libchdr #36).
Defaults to 1, which keeps the same behaviour as the single-hunk _cachedHunk slot
(one hunk held between reads). Setting it to a value > 1 makes
ReadHunk(uint, byte[], CancellationToken)
keep the last CacheSize distinct hunks decompressed, so random reads that
revisit hunks avoid re-decompression. Memory is capped at CacheSize * HunkBytes.
Set to 0 or 1 to disable the multi-hunk cache (back to single-slot behaviour).
public int CacheSize { get; set; }
Property Value
Compression
Compression codecs declared in the header (up to 4 for V5; 1 for V1-V4).
public IEnumerable<ChdCodec> Compression { get; }
Property Value
HunkBytes
Size in bytes of a single hunk (block).
public uint HunkBytes { get; }
Property Value
HunkCount
Number of hunks (blocks) in the image.
public uint HunkCount { get; }
Property Value
IdentData
Gets the ATA IDENTIFY DEVICE response metadata bytes (512 bytes), or null
if this CHD does not contain an IDNT metadata entry. Preserves the original
drive's model, serial, CHS geometry, and firmware revision — needed by some emulators
(e.g. OG Xbox HDD emulation).
public byte[]? IdentData { get; }
Property Value
- byte[]
IsCd
true if this CHD contains CD-ROM track metadata.
public bool IsCd { get; }
Property Value
IsChild
True if this CHD is a differential child. Alias for RequiresParent.
public bool IsChild { get; }
Property Value
IsDvd
true if this CHD contains DVD metadata.
public bool IsDvd { get; }
Property Value
IsGdRom
true if this CHD is a GD-ROM (Sega Dreamcast) image.
public bool IsGdRom { get; }
Property Value
IsHdd
true if this CHD contains hard disk geometry metadata.
public bool IsHdd { get; }
Property Value
IsLittleEndianAudio
true if this is a legacy GD-ROM whose CDDA audio tracks are stored in little-endian
byte order (CD_FLAG_GDROMLE, detected by the old "CHGT" metadata tag). For such discs,
AUDIO track samples must be 16-bit byte-swapped when extracted/played back.
Always false for non-GD-ROM images.
public bool IsLittleEndianAudio { get; }
Property Value
KeyData
Gets the hard disk encryption key metadata bytes, or null if this CHD
does not contain a KEY metadata entry. Used by OG Xbox and other platforms
that encrypt HDD contents.
public byte[]? KeyData { get; }
Property Value
- byte[]
MaxCompressedBlockBytes
The maximum allowed on-disk length (in bytes) of a single compressed hunk.
Normalized to HunkBytes if set below it, so it is always an upper bound on
the on-disk length. Defaults to HunkBytes * 2 (see CHDSharp.ChdHeaders.DefaultMaxCompressedMultiple).
A malicious hunk-map entry claiming a compressed hunk longer than this cap is rejected with
Chderrinvaliddata before any allocation, preventing out-of-memory on crafted files.
Valid CHDs created at low compression levels whose compressed size slightly exceeds the hunk size
remain usable (they fall within the default 2x cap).
public uint MaxCompressedBlockBytes { get; set; }
Property Value
Md5
MD5 of the raw image data (V1-V3). All-zero or null for V4/V5, which dropped MD5.
public byte[] Md5 { get; }
Property Value
- byte[]
MemoryBudget
Memory budget (in bytes) of the multi-hunk LRU cache: the cache retains up to
CacheSize decompressed hunks, i.e. roughly this many bytes. Setting it adjusts
CacheSize to the largest whole number of hunks that fits the budget
(at least one hunk). See ConfigureCache(int).
public long MemoryBudget { get; set; }
Property Value
Metadata
Gets the list of metadata entries from the CHD header (game name, disc info, etc.). Lazy-loaded on first access; empty list if the CHD has no metadata or an error occurs. For V1/V2 CHDs (which have no metadata section) a synthesized "GDDD" hard-disk entry is included, matching libchdr behaviour.
public IReadOnlyList<ChdMetadataEntry> Metadata { get; }
Property Value
PcmciaCisData
Gets the PCMCIA Card Information Structure (CIS) metadata bytes, or null
if this CHD does not contain a CIS metadata entry. Used by PC Engine CD
and other platforms with PCMCIA interfaces.
public byte[]? PcmciaCisData { get; }
Property Value
- byte[]
RawSha1
SHA1 of ONLY the raw (decompressed) image data, excluding metadata (V3-V5).
This is what a full sequential read of the image hashes to.
All-zero or null for V1/V2.
public byte[] RawSha1 { get; }
Property Value
- byte[]
ReadAheadHunkCount
Number of hunks that the read-ahead manager pre-decompresses in the background after each ReadHunk(uint, byte[], CancellationToken) call. Defaults to 0 (disabled). Setting this to a value
0 enables background read-ahead. The read-ahead cache is an L2 layer checked before the LRU cache in ReadHunk(uint, byte[], CancellationToken). Background tasks use ReadHunkConcurrent(uint, byte[], CancellationToken) and are capped at ReadAheadHunkCount concurrent decompressions via a semaphore.
public int ReadAheadHunkCount { get; set; }
Property Value
Remarks
Read-ahead is most beneficial for sequential access patterns (streaming, verification). For purely random access, the LRU CacheSize is more effective. The two caches are complementary: read-ahead fills upcoming hunks proactively, while the LRU retains recently accessed hunks.
RequiresParent
True if this CHD is a differential child that requires a parent CHD to read.
public bool RequiresParent { get; }
Property Value
SecondaryCodec
Secondary codec for V3/V4 CHDCOMPRESSION_ZLIB_PLUS files (type 6 map entries).
public ChdCodec SecondaryCodec { get; }
Property Value
Sha1
SHA1 of the full image including metadata (V4/V5), or the raw SHA1 when that is
all the format provides (V3). All-zero or null for V1/V2, which predate SHA1 hashes.
public byte[] Sha1 { get; }
Property Value
- byte[]
TotalBytes
Total size in bytes of the decompressed image.
public ulong TotalBytes { get; }
Property Value
Tracks
Track layout information. null if this CHD is not a CD/GD-ROM image.
public IReadOnlyList<ChdTrackInfo>? Tracks { get; }
Property Value
UnitBytes
Size in bytes of a unit used for parent block address translation. In V5 this is read from the header. In V1-V4 the concept does not exist in the header, so it is derived from metadata: hard disk metadata ("GDDD" tag) provides the bytes-per-sector value; CD/GD-ROM metadata ("CHCD", "CHTR", "CHT2", "CHGT", "CHGD" tags) produces the CD frame size (2448); otherwise defaults to HunkBytes.
public uint UnitBytes { get; }
Property Value
Version
CHD format version (1-5).
public uint Version { get; }
Property Value
Methods
ConfigureCache(int)
Configures the multi-hunk LRU cache size (number of decompressed hunks to retain). A value <= 1 reverts to the default single-hunk behaviour and releases any cached hunks. See CacheSize.
public void ConfigureCache(int maxHunks)
Parameters
maxHunksintMaximum number of hunks to keep decompressed.
ConfigureReadAhead(int)
Enables or disables background read-ahead decompression. When enabled, each
ReadHunk(uint, byte[], CancellationToken) call triggers background pre-decompression of the next
lookAhead hunks (default 4). Set to 0 or negative to disable.
public void ConfigureReadAhead(int lookAhead)
Parameters
lookAheadintNumber of hunks to read ahead. Default is 4.
DeleteMetadata(string, uint)
Deletes a metadata entry from this CHD (chdman delmeta parity): the entry at
occurrence index among entries with tag tag is
removed. The metadata chain is rewritten atomically (temp file + rename), the combined
SHA-1 is recomputed for V4/V5, and this instance is transparently reopened against the
new file.
public ChdError DeleteMetadata(string tag, uint index = 0)
Parameters
tagstringFour-character metadata tag (e.g. "GAME", "GDDD").
indexuintZero-based occurrence index of the entry to delete. Default 0.
Returns
- ChdError
Chderrnone on success; Chderrinvalidparameter for V1/V2 files or a stream opened with
leaveOpen; Chderrmetadatanotfound when no entry matches or the metadata chain could not be read; otherwise a write/IO error code.
Dispose()
Releases the underlying stream (unless opened with leaveOpen: true), the parent reference if owned, and
codec resources.
public void Dispose()
DisposeAsync()
Asynchronously releases the underlying stream (unless opened with leaveOpen: true) and any
internally-owned parent instance.
public ValueTask DisposeAsync()
Returns
EnumerateHunks(IProgress<ChdProgress>?)
Yields each decompressed hunk in order. The returned array is reused between iterations. Copy it if you need to keep the data beyond the current iteration.
public IEnumerable<byte[]> EnumerateHunks(IProgress<ChdProgress>? progress = null)
Parameters
progressIProgress<ChdProgress>An optional IProgress<T> receiving a ChdProgress report after each decompressed hunk.
null(default) disables progress reporting.
Returns
- IEnumerable<byte[]>
Exceptions
- InvalidDataException
Thrown when a hunk fails to decompress, with the ChdError in the message.
ExportToc()
Returns a human-readable table-of-contents summary.
public string ExportToc()
Returns
ExtractToDirectory(string, string, IProgress<ChdProgress>?, CancellationToken, bool)
Extracts the entire CHD image to the specified directory. For CD/GD-ROM images, also writes a CUE sheet or GDI descriptor. Throws InvalidDataException on any extraction failure.
public IReadOnlyList<string> ExtractToDirectory(string outputDir, string baseFileName, IProgress<ChdProgress>? progress = null, CancellationToken cancellationToken = default, bool cooked = false)
Parameters
outputDirstringTarget directory. Created if it doesn't exist.
baseFileNamestringBase filename (without extension) for output files.
progressIProgress<ChdProgress>An optional IProgress<T> receiving a ChdProgress report after each decompressed hunk.
null(default) disables progress reporting.cancellationTokenCancellationTokenA token to cancel the extraction. OperationCanceledException is thrown if cancellation is requested between hunk writes.
cookedboolWhen
trueand this is a CD/GD-ROM image, writes cooked sectors (stripped to DataSize bytes per frame, omitting 96-byte subcode) matching chdman'sextractcdoutput. Whenfalse(default) the full 2448-byte frames are written. Has no effect for DVD/HDD/raw images.
Returns
- IReadOnlyList<string>
List of created file paths.
ExtractToDirectoryWithReporting(string, string, IProgress<ChdProgress>?, CancellationToken, bool)
Extracts the entire CHD image to the specified directory with per-track error reporting. For GD-ROM images, each track is extracted individually and failures are reported per-track rather than stopping at the first error. For all other image types, extraction is all-or-nothing.
public ExtractResult ExtractToDirectoryWithReporting(string outputDir, string baseFileName, IProgress<ChdProgress>? progress = null, CancellationToken cancellationToken = default, bool cooked = false)
Parameters
outputDirstringTarget directory. Created if it doesn't exist.
baseFileNamestringBase filename (without extension) for output files.
progressIProgress<ChdProgress>An optional IProgress<T> receiving a ChdProgress report after each decompressed hunk.
null(default) disables progress reporting.cancellationTokenCancellationTokenA token to cancel the extraction. OperationCanceledException is thrown if cancellation is requested between hunk writes.
cookedboolWhen
trueand this is a CD/GD-ROM image, writes cooked sectors (stripped to DataSize bytes per frame) matching chdman'sextractcdoutput. Whenfalse(default) the full 2448-byte frames are written.
Returns
- ExtractResult
An ExtractResult with created files, per-track results, and overall error.
ExtractToc(string, string, IProgress<ChdProgress>?, CancellationToken)
Extracts this CD CHD to bin+toc in MODE_NORMAL layout (single bin file
containing datasize+subsize bytes per frame, plus a .toc descriptor).
Mirrors chdman.cpp:2918 extraction for MODE_NORMAL including
ZERO/DATAFILE/START and subcode preservation.
public ChdError ExtractToc(string tocPath, string binPath, IProgress<ChdProgress>? progress = null, CancellationToken cancellationToken = default)
Parameters
tocPathstringbinPathstringprogressIProgress<ChdProgress>cancellationTokenCancellationToken
Returns
FlushReadAhead()
Clears the read-ahead cache, discarding any pre-decompressed hunks. Useful after a seek that invalidates the sequential read pattern.
public void FlushReadAhead()
GenerateCueSheet(string)
Generates a standard CUE sheet for this CD-ROM CHD using single-bin format.
public string GenerateCueSheet(string binFileName)
Parameters
binFileNamestringThe filename of the binary data file to reference in the CUE sheet.
Returns
- string
A CUE sheet string.
GenerateCueSheet(string, CueStyle)
Generates a CUE sheet for this CD-ROM CHD in the requested CueStyle (chdman single-bin format, optionally converted to Redump / Redump+CATALOG form).
public string GenerateCueSheet(string binFileName, CueStyle style)
Parameters
binFileNamestringThe filename of the binary data file to reference in the CUE sheet.
styleCueStyleThe output style (see ConvertCue(string, CueStyle)).
Returns
- string
A CUE sheet string in the requested style.
GenerateGdRomCueSheet(string[])
Generates a Redump-style split CUE sheet for a GD-ROM CHD, with per-track
FILE entries and REM SINGLE/HIGH-DENSITY AREA density comments.
Matches chdman extractcd for GD-ROM in MODE_CUEBIN with
--splitbin (chdman.cpp:2854, 2945). Uses the
has_physical_pregap / padframes / splitframes fixup.
public string GenerateGdRomCueSheet(string[] trackFiles)
Parameters
trackFilesstring[]Array of filenames for each track's binary data file. Must match track count. For GD-ROM the caller should pass the per-track cooked filenames (e.g.
"disc01.bin"etc.) as produced by the extractor.
Returns
- string
A split CUE sheet string with density REMs.
GenerateGdiDescriptor(string[])
Generates a GDI descriptor for this GD-ROM CHD.
public string GenerateGdiDescriptor(string[] trackFiles)
Parameters
trackFilesstring[]Array of filenames for each track's binary data file. Must match track count.
Returns
- string
A GDI descriptor string.
GenerateGdiDescriptor(string[], bool)
Generates a GDI descriptor for this GD-ROM CHD.
public string GenerateGdiDescriptor(string[] trackFiles, bool cooked)
Parameters
trackFilesstring[]Array of filenames for each track's binary data file. Must match track count.
cookedboolWhen
true, start LBA values are computed as the cumulative sum of previous tracks' Frames (chdman cooked output, pad-aware). Whenfalsethe CHD's physical StartFrame is used (raw frames).
Returns
- string
A GDI descriptor string.
GenerateTocFileContents(string)
Generates a TOC descriptor for this CD/GD-ROM CHD in MODE_NORMAL format
(chdman.cpp:1592 output_track_metadata for MODE_NORMAL).
Matches chdman extractcd when the output file ends with .toc
(no .cue/.gdi): header CD_ROM/CD_ROM_XA/CD_DA
followed by per-track // Track N, TRACK, NO COPY,
ZERO, DATAFILE, START blocks.
public string GenerateTocFileContents(string binFileName)
Parameters
binFileNamestringBinary data filename quoted in
DATAFILElines (e.g.disc.bin).
Returns
- string
A TOC descriptor string.
GetHunkCodecName(uint)
Returns the display name for a hunk's codec, matching chdman info --verbose
(chdman.cpp:1760). For Uncompressed, Copy from self, etc. the
pseudo-codec names are returned; for Compressiontype0..3 the codec's
registered name (Deflate, LZMA, …) is returned.
public string GetHunkCodecName(uint hunkIndex)
Parameters
hunkIndexuint
Returns
GetHunkCodecNameForCodec(ChdCodec)
Returns the display name for a codec value (e.g. Deflate for zlib).
public static string GetHunkCodecNameForCodec(ChdCodec codec)
Parameters
codecChdCodec
Returns
GetHunkCompressedLength(uint)
Returns the on-disk compressed length for a hunk (0 for SELF/PARENT/MINI).
public uint GetHunkCompressedLength(uint hunkIndex)
Parameters
hunkIndexuint
Returns
GetHunkCompressionType(uint)
Returns the compression type for a single hunk without decompressing it (chdman hunk_info parity).
For SELF entries the type is Compressionself; for
PARENT the type is Compressionparent; for compressed
hunks it is Compressiontype0..3 or Compressiontype2Nd.
public CompressionType GetHunkCompressionType(uint hunkIndex)
Parameters
hunkIndexuint
Returns
GetHunkInfo(uint, out ChdCodec, out uint)
Returns the codec type and compressed length for a hunk, mirroring MAME's
chd_file::hunk_info (chd.h:317). For SELF/PARENT/MINI
the returned codec is the pseudo-type (CHD_CODEC_SELF etc.);
for compressed hunks it is the actual codec tag (e.g. CHD_CODEC_ZLIB).
public ChdError GetHunkInfo(uint hunkIndex, out ChdCodec codec, out uint compressedBytes)
Parameters
Returns
GetMetadata(string?, uint, out ChdMetadataEntry?)
Searches the metadata chain for an entry with the given four-character
tag and occurrence index (libchdr
chd_get_metadata parity). Pass null or an empty string as
tag to match entries of any tag.
public ChdError GetMetadata(string? tag, uint index, out ChdMetadataEntry? entry)
Parameters
tagstringFour-character tag to search for (e.g. "GDDD", "CHT2"), or
null/empty for a wildcard match.indexuintZero-based occurrence index among the entries with the matching tag.
entryChdMetadataEntryThe matching entry, or
nullwhen not found or on error.
Returns
- ChdError
Chderrnone on success; Chderrmetadatanotfound if no entry matches; Chderrinvaliddata or Chderrreaderror if the metadata could not be read.
GetTracksForCue()
Returns the GD-ROM track list after applying the Redump has_physical_pregap
fixup (chdman.cpp:2854). For non-GD-ROM images returns the original track list.
Exposed for testing and for callers that need to inspect the mutated TOC.
public IReadOnlyList<ChdTrackInfo> GetTracksForCue()
Returns
Open(Stream, bool, ChdFile?, out ChdFile?, CancellationToken)
Opens a (possibly child) CHD from an existing seekable stream, resolving
parent references against parent (null = standalone).
public static ChdError Open(Stream stream, bool leaveOpen, ChdFile? parent, out ChdFile? chdFile, CancellationToken cancellationToken = default)
Parameters
streamStreamSeekable, readable stream positioned anywhere; it will be seeked as needed.
leaveOpenboolIf false, the stream is disposed when this instance is disposed.
parentChdFileAn already-open parent ChdFile, or
nullfor a standalone CHD. The caller retains ownership.chdFileChdFileWhen this method returns, contains the opened ChdFile instance, or
nullon error.cancellationTokenCancellationTokenA token to cancel the open. OperationCanceledException is thrown if cancellation is requested.
Returns
- ChdError
Chderrnone on success; otherwise an error code.
Open(Stream, bool, ChdFile?, ParentResolver?, out ChdFile?, CancellationToken)
Opens a (possibly child) CHD from an existing seekable stream, resolving
parent references against parent (null = standalone) or
lazily via parentResolver.
public static ChdError Open(Stream stream, bool leaveOpen, ChdFile? parent, ParentResolver? parentResolver, out ChdFile? chdFile, CancellationToken cancellationToken = default)
Parameters
streamStreamSeekable, readable stream positioned anywhere; it will be seeked as needed.
leaveOpenboolIf false, the stream is disposed when this instance is disposed.
parentChdFileAn already-open parent ChdFile, or
nullfor a standalone CHD. The caller retains ownership.parentResolverParentResolverA callback for lazy parent resolution, or
nullto use the explicitparent.chdFileChdFileWhen this method returns, contains the opened ChdFile instance, or
nullon error.cancellationTokenCancellationTokenA token to cancel the open. OperationCanceledException is thrown if cancellation is requested.
Returns
- ChdError
Chderrnone on success; otherwise an error code.
Open(Stream, bool, out ChdFile?, CancellationToken)
Opens a standalone CHD from an existing seekable stream for random access.
public static ChdError Open(Stream stream, bool leaveOpen, out ChdFile? chdFile, CancellationToken cancellationToken = default)
Parameters
streamStreamSeekable, readable stream positioned anywhere; it will be seeked as needed.
leaveOpenboolIf false, the stream is disposed when this instance is disposed.
chdFileChdFileWhen this method returns, contains the opened ChdFile instance, or
nullon error.cancellationTokenCancellationTokenA token to cancel the open. OperationCanceledException is thrown if cancellation is requested.
Returns
- ChdError
Chderrnone on success; otherwise an error code.
Open(Stream, bool, ParentResolver?, out ChdFile?, CancellationToken)
Opens a (possibly child) CHD from an existing seekable stream, resolving parent references lazily via a ParentResolver callback.
public static ChdError Open(Stream stream, bool leaveOpen, ParentResolver? parentResolver, out ChdFile? chdFile, CancellationToken cancellationToken = default)
Parameters
streamStreamSeekable, readable stream positioned anywhere; it will be seeked as needed.
leaveOpenboolIf false, the stream is disposed when this instance is disposed.
parentResolverParentResolverA callback that resolves parent CHDs by SHA1/MD5 hash, or
nullto fail on parent-referenced hunks.chdFileChdFileWhen this method returns, contains the opened ChdFile instance, or
nullon error.cancellationTokenCancellationTokenA token to cancel the open.
Returns
- ChdError
Chderrnone on success; otherwise an error code.
Open(string, ChdFile?, out ChdFile?, CancellationToken)
Opens a (possibly child) CHD from disk, resolving parent references
against an already-open parent. The caller retains
ownership of parent (it is not disposed by this
instance). Pass null for a standalone CHD.
public static ChdError Open(string filename, ChdFile? parent, out ChdFile? chdFile, CancellationToken cancellationToken = default)
Parameters
filenamestringPath to the CHD file to open.
parentChdFileAn already-open parent ChdFile, or
nullfor a standalone CHD. The same parent instance may be shared by multiple children as long as all access is single-threaded.chdFileChdFileWhen this method returns, contains the opened ChdFile, or
nullon error.cancellationTokenCancellationTokenA token to cancel the open. OperationCanceledException is thrown if cancellation is requested.
Returns
- ChdError
Chderrnone on success; otherwise an error code.
Open(string, ChdFile?, bool, out ChdFile?, CancellationToken)
Opens a (possibly child) CHD from disk with an optional memory-mapped data region,
resolving parent references against an already-open parent
(see Open(string, ChdFile?, out ChdFile?, CancellationToken)).
public static ChdError Open(string filename, ChdFile? parent, bool memoryMapped, out ChdFile? chdFile, CancellationToken cancellationToken = default)
Parameters
filenamestringparentChdFilememoryMappedboolchdFileChdFilecancellationTokenCancellationToken
Returns
Open(string, out ChdFile?, CancellationToken)
Opens a standalone CHD file from disk for random access. Fails with Chderrrequiresparent if the file is a child CHD.
public static ChdError Open(string filename, out ChdFile? chdFile, CancellationToken cancellationToken = default)
Parameters
filenamestringPath to the CHD file to open.
chdFileChdFileWhen this method returns, contains the opened ChdFile, or
nullon error.cancellationTokenCancellationTokenA token to cancel the open. OperationCanceledException is thrown if cancellation is requested.
Returns
- ChdError
Chderrnone on success; otherwise an error code (e.g. Chderrfilenotfound, Chderrinvalidfile, Chderrrequiresparent).
Open(string, ParentResolver?, out ChdFile?, CancellationToken)
Opens a (possibly child) CHD from disk, resolving parent references lazily via a ParentResolver callback. The parent is not opened until the first parent-referenced hunk is read, and the resolved instance is cached for subsequent reads.
public static ChdError Open(string filename, ParentResolver? parentResolver, out ChdFile? chdFile, CancellationToken cancellationToken = default)
Parameters
filenamestringPath to the CHD file to open.
parentResolverParentResolverA callback that resolves parent CHDs by SHA1/MD5 hash, or
nullto fail on parent-referenced hunks.chdFileChdFileWhen this method returns, contains the opened ChdFile, or
nullon error.cancellationTokenCancellationTokenA token to cancel the open.
Returns
- ChdError
Chderrnone on success; otherwise an error code.
Open(string, bool, out ChdFile?, CancellationToken)
Opens a standalone CHD file from disk for random access with an optional memory-mapped data region (see Open(string, out ChdFile?, CancellationToken)).
public static ChdError Open(string filename, bool memoryMapped, out ChdFile? chdFile, CancellationToken cancellationToken = default)
Parameters
filenamestringPath to the CHD file to open.
memoryMappedboolWhen
true, the compressed data region is memory-mapped: hunk reads are served straight from mapped memory (no syscalls). Falls back to regular stream reads when the mapping cannot be created (32-bit processes, huge files). For memory-mapped instancesPrecacheis a no-op.chdFileChdFileWhen this method returns, contains the opened ChdFile, or
nullon error.cancellationTokenCancellationTokenA token to cancel the open.
Returns
- ChdError
Chderrnone on success; otherwise an error code.
Open(string, string?, out ChdFile?, CancellationToken)
Opens a (possibly child) CHD from disk, resolving parent references
against the parent CHD at parentFilename. The parent is
opened internally and disposed together with the returned instance.
public static ChdError Open(string filename, string? parentFilename, out ChdFile? chdFile, CancellationToken cancellationToken = default)
Parameters
filenamestringPath to the CHD file to open.
parentFilenamestringPath to the parent CHD, or
null/empty for a standalone CHD.chdFileChdFileWhen this method returns, contains the opened ChdFile, or
nullon error.cancellationTokenCancellationTokenA token to cancel the open. OperationCanceledException is thrown if cancellation is requested.
Returns
- ChdError
Chderrnone on success; otherwise an error code (e.g. Chderrinvalidparent if the parent's hashes do not match).
Open(string, string?, bool, out ChdFile?, CancellationToken)
Opens a (possibly child) CHD from disk with an optional memory-mapped data region,
resolving parent references against the CHD at parentFilename
(see Open(string, string?, out ChdFile?, CancellationToken) and
Open(string, bool, out ChdFile?, CancellationToken)).
public static ChdError Open(string filename, string? parentFilename, bool memoryMapped, out ChdFile? chdFile, CancellationToken cancellationToken = default)
Parameters
filenamestringparentFilenamestringmemoryMappedboolchdFileChdFilecancellationTokenCancellationToken
Returns
OpenAsStream(ChdFile, out ChdImageStream)
Opens the CHD from an already-opened ChdFile and returns a seekable, read-only Stream over the decompressed image.
public static ChdError OpenAsStream(ChdFile chd, out ChdImageStream stream)
Parameters
chdChdFileAn opened ChdFile instance. Ownership is transferred to the stream; disposing the stream disposes this instance.
streamChdImageStreamContains the ChdImageStream.
Returns
OpenAsStream(ChdFile, bool, out ChdImageStream)
Opens the CHD from an already-opened ChdFile and returns a seekable, read-only Stream over the decompressed image, optionally without transferring ownership.
public static ChdError OpenAsStream(ChdFile chd, bool ownsChd, out ChdImageStream stream)
Parameters
chdChdFileAn opened ChdFile instance.
ownsChdboolIf
true, disposing the stream disposeschd.streamChdImageStreamContains the ChdImageStream.
Returns
OpenAsStream(string, out ChdImageStream?, CancellationToken)
Opens the CHD file and returns a seekable, read-only Stream over the decompressed image. The stream decompresses hunks on demand; a single hunk is cached so sequential reads avoid re-decoding.
public static ChdError OpenAsStream(string filename, out ChdImageStream? stream, CancellationToken cancellationToken = default)
Parameters
filenamestringPath to the CHD file.
streamChdImageStreamWhen this method returns Chderrnone, contains the ChdImageStream;
nullon failure.cancellationTokenCancellationTokenA token to cancel the open operation.
Returns
- ChdError
Chderrnone on success; otherwise an error code.
Remarks
Disposing the returned stream disposes the underlying ChdFile.
OpenAsStream(string, string?, out ChdImageStream?, CancellationToken)
Opens the CHD file with a parent and returns a seekable, read-only Stream over the decompressed image.
public static ChdError OpenAsStream(string filename, string? parentFilename, out ChdImageStream? stream, CancellationToken cancellationToken = default)
Parameters
filenamestringPath to the CHD file.
parentFilenamestringPath to the parent CHD file, or
nullto open without a parent.streamChdImageStreamWhen this method returns Chderrnone, contains the ChdImageStream;
nullon failure.cancellationTokenCancellationTokenA token to cancel the open operation.
Returns
- ChdError
Chderrnone on success; otherwise an error code.
OpenAsStreamAsync(string, string?, CancellationToken)
Asynchronously opens the CHD file with a parent and returns a seekable, read-only Stream over the decompressed image.
public static Task<(ChdError error, ChdImageStream? stream)> OpenAsStreamAsync(string filename, string? parentFilename, CancellationToken cancellationToken = default)
Parameters
filenamestringPath to the CHD file.
parentFilenamestringPath to the parent CHD file, or
nullto open without a parent.cancellationTokenCancellationTokenA token to cancel the open operation.
Returns
- Task<(ChdError error, ChdImageStream stream)>
A tuple of (ChdError, ChdImageStream?). Error is Chderrnone on success; stream is non-null on success.
OpenAsStreamAsync(string, CancellationToken)
Asynchronously opens the CHD file and returns a seekable, read-only Stream over the decompressed image.
public static Task<(ChdError error, ChdImageStream? stream)> OpenAsStreamAsync(string filename, CancellationToken cancellationToken = default)
Parameters
filenamestringPath to the CHD file.
cancellationTokenCancellationTokenA token to cancel the open operation.
Returns
- Task<(ChdError error, ChdImageStream stream)>
A tuple of (ChdError, ChdImageStream?). Error is Chderrnone on success; stream is non-null on success.
OpenAsync(Stream, bool, ChdFile?, CancellationToken)
Asynchronously opens a (possibly child) CHD from an existing seekable stream against an already-open parent (see Open(Stream, bool, ChdFile?, out ChdFile?, CancellationToken)).
public static Task<(ChdError error, ChdFile? file)> OpenAsync(Stream stream, bool leaveOpen, ChdFile? parent, CancellationToken cancellationToken = default)
Parameters
streamStreamSeekable, readable stream positioned anywhere; it will be seeked as needed.
leaveOpenboolIf false, the stream is disposed when this instance is disposed.
parentChdFileAn already-open parent ChdFile, or
nullfor a standalone CHD. The caller retains ownership.cancellationTokenCancellationTokenA token to cancel the open. OperationCanceledException is thrown (or the returned task is cancelled) if cancellation is requested.
Returns
- Task<(ChdError error, ChdFile file)>
A task producing a tuple of the ChdError result and the opened ChdFile (or
nullon error).
OpenAsync(Stream, bool, ParentResolver?, CancellationToken)
Asynchronously opens a (possibly child) CHD from an existing seekable stream, resolving parent references lazily via a ParentResolver callback (see Open(Stream, bool, ParentResolver?, out ChdFile?, CancellationToken)).
public static Task<(ChdError error, ChdFile? file)> OpenAsync(Stream stream, bool leaveOpen, ParentResolver? parentResolver, CancellationToken cancellationToken = default)
Parameters
streamStreamSeekable, readable stream positioned anywhere; it will be seeked as needed.
leaveOpenboolIf false, the stream is disposed when this instance is disposed.
parentResolverParentResolverA callback that resolves parent CHDs by SHA1/MD5 hash, or
null.cancellationTokenCancellationTokenA token to cancel the open.
Returns
- Task<(ChdError error, ChdFile file)>
A task producing a tuple of the ChdError result and the opened ChdFile (or
nullon error).
OpenAsync(Stream, bool, CancellationToken)
Asynchronously opens a standalone CHD from an existing seekable stream (see Open(Stream, bool, out ChdFile?, CancellationToken)).
public static Task<(ChdError error, ChdFile? file)> OpenAsync(Stream stream, bool leaveOpen, CancellationToken cancellationToken = default)
Parameters
streamStreamSeekable, readable stream positioned anywhere; it will be seeked as needed.
leaveOpenboolIf false, the stream is disposed when this instance is disposed.
cancellationTokenCancellationTokenA token to cancel the open. OperationCanceledException is thrown (or the returned task is cancelled) if cancellation is requested.
Returns
- Task<(ChdError error, ChdFile file)>
A task producing a tuple of the ChdError result and the opened ChdFile (or
nullon error).
OpenAsync(string, ChdFile?, CancellationToken)
Asynchronously opens a (possibly child) CHD from disk against an already-open parent (see Open(string, ChdFile?, out ChdFile?, CancellationToken)).
public static Task<(ChdError error, ChdFile? file)> OpenAsync(string filename, ChdFile? parent, CancellationToken cancellationToken = default)
Parameters
filenamestringPath to the CHD file to open.
parentChdFileAn already-open parent ChdFile, or
nullfor a standalone CHD. The caller retains ownership.cancellationTokenCancellationTokenA token to cancel the open. OperationCanceledException is thrown (or the returned task is cancelled) if cancellation is requested.
Returns
- Task<(ChdError error, ChdFile file)>
A task producing a tuple of the ChdError result and the opened ChdFile (or
nullon error).
OpenAsync(string, ParentResolver?, CancellationToken)
Asynchronously opens a (possibly child) CHD from disk, resolving parent references lazily via a ParentResolver callback (see Open(string, ParentResolver?, out ChdFile?, CancellationToken)).
public static Task<(ChdError error, ChdFile? file)> OpenAsync(string filename, ParentResolver? parentResolver, CancellationToken cancellationToken = default)
Parameters
filenamestringPath to the CHD file to open.
parentResolverParentResolverA callback that resolves parent CHDs by SHA1/MD5 hash, or
null.cancellationTokenCancellationTokenA token to cancel the open.
Returns
- Task<(ChdError error, ChdFile file)>
A task producing a tuple of the ChdError result and the opened ChdFile (or
nullon error).
OpenAsync(string, string?, CancellationToken)
Asynchronously opens a (possibly child) CHD from disk, resolving parent references against
the CHD at parentFilename (see
Open(string, string?, out ChdFile?, CancellationToken)).
public static Task<(ChdError error, ChdFile? file)> OpenAsync(string filename, string? parentFilename, CancellationToken cancellationToken = default)
Parameters
filenamestringPath to the CHD file to open.
parentFilenamestringPath to the parent CHD, or
null/empty for a standalone CHD.cancellationTokenCancellationTokenA token to cancel the open. OperationCanceledException is thrown (or the returned task is cancelled) if cancellation is requested.
Returns
- Task<(ChdError error, ChdFile file)>
A task producing a tuple of the ChdError result and the opened ChdFile (or
nullon error).
OpenAsync(string, CancellationToken)
Asynchronously opens a standalone CHD file from disk (see Open(string, out ChdFile?, CancellationToken)).
public static Task<(ChdError error, ChdFile? file)> OpenAsync(string filename, CancellationToken cancellationToken = default)
Parameters
filenamestringPath to the CHD file to open.
cancellationTokenCancellationTokenA token to cancel the open. OperationCanceledException is thrown (or the returned task is cancelled) if cancellation is requested.
Returns
- Task<(ChdError error, ChdFile file)>
A task producing a tuple of the ChdError result and the opened ChdFile (or
nullon error).
Precache(long)
Reads the entire compressed CHD file into memory (see Precache(long)), refusing
files larger than maxBytes with Chderroutofmemory.
public ChdError Precache(long maxBytes = 2147483647)
Parameters
maxByteslongThe largest file size (in bytes) this call is willing to buffer; larger files return Chderroutofmemory without reading.
Returns
- ChdError
Chderrnone on success (or if already precached); Chderroutofmemory if the file is larger than
maxBytesor cannot be allocated; Chderrreaderror if the file could not be read.
Read(ulong, byte[], int, int, CancellationToken)
Reads count bytes from the decompressed image starting
at byteOffset, decompressing hunks on demand. A single
hunk is cached, so sequential reads within the same hunk avoid re-decoding.
public ChdError Read(ulong byteOffset, byte[] destination, int destinationOffset, int count, CancellationToken cancellationToken = default)
Parameters
byteOffsetulongByte offset into the decompressed image (0 to TotalBytes - 1).
destinationbyte[]Destination buffer.
destinationOffsetintOffset in
destinationat which to start writing.countintNumber of bytes to read.
cancellationTokenCancellationTokenA token to cancel the read. OperationCanceledException is thrown if cancellation is requested before a hunk is decompressed.
Returns
- ChdError
Chderrnone on success; Chderrinvalidparameter if the requested range is outside the image or the destination bounds; otherwise a decompression error code.
Read(ulong, Span<byte>, int, CancellationToken)
Reads a contiguous run of bytes from the decompressed image into a caller-owned Span<T>. Internally reuses the single-hunk cache for efficiency.
public ChdError Read(ulong byteOffset, Span<byte> destination, int count, CancellationToken cancellationToken = default)
Parameters
byteOffsetulongByte offset within the decompressed image (0-based).
destinationSpan<byte>Destination span to fill.
countintNumber of bytes to read.
cancellationTokenCancellationTokenA token to cancel the read.
Returns
- ChdError
Chderrnone on success; Chderrinvalidparameter if the requested range is out of bounds; otherwise a hunk read error.
ReadAllBytes(out byte[], IProgress<ChdProgress>?, CancellationToken)
Decompresses the entire CHD image into a single byte array.
public ChdError ReadAllBytes(out byte[] data, IProgress<ChdProgress>? progress = null, CancellationToken cancellationToken = default)
Parameters
databyte[]When this method returns, contains the full decompressed image on success; an empty array on failure.
progressIProgress<ChdProgress>An optional IProgress<T> receiving a ChdProgress report after each decompressed hunk.
null(default) disables progress reporting.cancellationTokenCancellationTokenA token to cancel the read. OperationCanceledException is thrown if cancellation is requested before a hunk is decompressed.
Returns
- ChdError
Chderrnone on success; Chderroutofmemory if the image is larger than 2 GiB (MaxValue bytes); otherwise a read/decompression error code.
Remarks
Be cautious: CHD images can be tens of gigabytes. Prefer EnumerateHunks(IProgress<ChdProgress>?) or Read(ulong, byte[], int, int, CancellationToken) for large images.
ReadAsync(ulong, byte[], int, int, CancellationToken)
Asynchronously reads a byte range from the decompressed image (see Read(ulong, byte[], int, int, CancellationToken)). Uses genuine async I/O via ReadHunkAsync(uint, byte[], CancellationToken).
public Task<ChdError> ReadAsync(ulong byteOffset, byte[] destination, int destinationOffset, int count, CancellationToken cancellationToken = default)
Parameters
byteOffsetulongByte offset into the decompressed image (0 to TotalBytes - 1).
destinationbyte[]Destination buffer.
destinationOffsetintOffset in
destinationat which to start writing.countintNumber of bytes to read.
cancellationTokenCancellationTokenA token to cancel the read. OperationCanceledException is thrown if cancellation is requested.
Returns
ReadFrame(uint, byte[], CancellationToken)
Reads the full CD frame (2448 bytes: 2352-byte sector data plus 96-byte subcode; the subcode is zero-filled for tracks without stored subcode) for the given LBA from a CD/GD-ROM CHD. See ReadSector(uint, byte[], CancellationToken) for the image mapping.
public ChdError ReadFrame(uint lba, byte[] buffer, CancellationToken cancellationToken = default)
Parameters
lbauintThe logical block address (LBA 0 = MSF 00:02:00).
bufferbyte[]Destination buffer of at least UnitBytes bytes; receives the frame data.
cancellationTokenCancellationTokenA token to cancel the read.
Returns
- ChdError
Chderrnone on success; Chderrinvaliddata if this CHD has no CD/GD-ROM track metadata; Chderrinvalidparameter if
bufferis too small orlbafalls outside the decompressed image.
ReadHunk(uint, byte[], CancellationToken)
Decompresses a single hunk into buffer.
public ChdError ReadHunk(uint hunknum, byte[] buffer, CancellationToken cancellationToken = default)
Parameters
hunknumuintZero-based hunk index (0 to HunkCount - 1).
bufferbyte[]Destination buffer of at least HunkBytes bytes.
cancellationTokenCancellationTokenA token to cancel the decompression. OperationCanceledException is thrown if cancellation is requested before the hunk is decompressed.
Returns
- ChdError
Chderrnone on success; Chderrhunkoutofrange if
hunknumis out of range; Chderrinvalidparameter ifbufferis too small; Chderrrequiresparent if the hunk references a missing parent; Chderrdecompressionerror if the compressed data is corrupt.
Remarks
The final hunk of an image whose size is not a multiple of HunkBytes is still HunkBytes long (padded as stored in the file).
ReadHunk(uint, Span<byte>, CancellationToken)
Decompresses a single hunk into a caller-owned Span<T>.
This overload allocates a temporary internal buffer and copies the result into
buffer. For zero-copy scenarios where the caller controls the
buffer lifetime, prefer the byte[] overload.
public ChdError ReadHunk(uint hunknum, Span<byte> buffer, CancellationToken cancellationToken = default)
Parameters
hunknumuintZero-based hunk index (0 to HunkCount - 1).
bufferSpan<byte>Destination span of at least HunkBytes bytes.
cancellationTokenCancellationTokenA token to cancel the read.
Returns
- ChdError
Chderrnone on success; Chderrhunkoutofrange if
hunknumis out of range; Chderrinvalidparameter ifbufferis too short; otherwise a decompression error.
ReadHunkAsync(uint, byte[], CancellationToken)
Asynchronously decompresses a single hunk into buffer (see
ReadHunk(uint, byte[], CancellationToken)).
The compressed data is read with real asynchronous I/O (RandomAccess.ReadAsync for
file-backed instances, Stream.ReadExactlyAsync otherwise); decompression itself is
CPU-bound and runs on the calling thread. Does not touch the shared per-hunk cache.
public Task<ChdError> ReadHunkAsync(uint hunknum, byte[] buffer, CancellationToken cancellationToken = default)
Parameters
hunknumuintZero-based hunk index (0 to HunkCount - 1).
bufferbyte[]Destination buffer of at least HunkBytes bytes.
cancellationTokenCancellationTokenA token to cancel the read. OperationCanceledException is thrown if cancellation is requested.
Returns
ReadHunkConcurrent(uint, byte[], CancellationToken)
Decompresses a single hunk into buffer in a way that is safe for
concurrent use on the same ChdFile instance from multiple threads
(emulator-style parallel sector loaders). Unlike ReadHunk(uint, byte[], CancellationToken), this
method:
never uses the shared per-hunk/compressed-buffer caches, gives each calling thread its
own codec state, and reads compressed data without sharing stream position
(RandomAccess for file-backed instances). The existing single-threaded API is
unchanged. For child CHDs, parent resolution serializes on the parent instance.
public ChdError ReadHunkConcurrent(uint hunknum, byte[] buffer, CancellationToken cancellationToken = default)
Parameters
hunknumuintZero-based hunk index (0 to HunkCount - 1).
bufferbyte[]Destination buffer of at least HunkBytes bytes.
cancellationTokenCancellationTokenA token to cancel the decompression.
Returns
- ChdError
The same result codes as ReadHunk(uint, byte[], CancellationToken).
ReadRawHunk(uint)
Reads the raw on-disk bytes of a hunk exactly as stored in the CHD file, without
decompression (chd-rs read_raw_in parity). Useful for debugging, repacking,
and map analysis.
public byte[]? ReadRawHunk(uint hunknum)
Parameters
Returns
- byte[]
The raw stored bytes: the compressed block for codec entries (types 0-3 and the V3/V4 secondary codec), the raw block for Compressionnone entries, or the referenced hunk's bytes for Compressionself entries.
nullwhen the hunk has no on-disk data (parent reference, V3/V4 mini inline pattern, V5 zero-fill) or its stored range lies outside the file.
Exceptions
- ArgumentOutOfRangeException
hunknumis out of range.
ReadRawHunkAsync(uint, CancellationToken)
Asynchronously reads the raw on-disk bytes of a hunk (see ReadRawHunk(uint)). Uses genuine async I/O.
public Task<byte[]?> ReadRawHunkAsync(uint hunknum, CancellationToken cancellationToken = default)
Parameters
hunknumuintZero-based hunk index (0 to HunkCount - 1).
cancellationTokenCancellationTokenA token to cancel the read. OperationCanceledException is thrown if cancellation is requested.
Returns
ReadSector(uint, byte[], CancellationToken)
Reads the 2352-byte sector data for the given LBA from a CD/GD-ROM CHD. The address is
mapped through the track table: LBA 0 is the first data track's INDEX 01 position, which
sits PREGAP frames into the decompressed image when the pregap is stored physically
(metadata PGTYPE:V...), and at image frame 0 otherwise. The returned data is the
first 2352 bytes of the 2448-byte frame (tracks with a smaller data size are zero-padded
as stored in the image).
public ChdError ReadSector(uint lba, byte[] buffer, CancellationToken cancellationToken = default)
Parameters
lbauintThe logical block address (LBA 0 = MSF 00:02:00).
bufferbyte[]Destination buffer of at least 2352 bytes; receives the sector data.
cancellationTokenCancellationTokenA token to cancel the read.
Returns
- ChdError
Chderrnone on success; Chderrinvaliddata if this CHD has no CD/GD-ROM track metadata; Chderrinvalidparameter if
bufferis too small orlbafalls outside the decompressed image.
ReadSectorMsf(byte, byte, byte, byte[], CancellationToken)
Reads the 2352-byte sector data at the given BCD MSF address
(e.g. 00:02:00 = (0x00, 0x02, 0x00), which is LBA 0). See ReadSector(uint, byte[], CancellationToken)
for the image mapping and error codes.
public ChdError ReadSectorMsf(byte m, byte s, byte f, byte[] buffer, CancellationToken cancellationToken = default)
Parameters
mbyteMinutes, BCD-encoded.
sbyteSeconds, BCD-encoded.
fbyteFrames, BCD-encoded.
bufferbyte[]Destination buffer of at least 2352 bytes; receives the sector data.
cancellationTokenCancellationTokenA token to cancel the read.
Returns
- ChdError
Chderrnone on success; Chderrinvaliddata if this CHD has no CD/GD-ROM track metadata; Chderrinvalidparameter if
bufferis too small, the MSF address precedes 00:02:00 (negative LBA), or the address falls outside the decompressed image.
SetMetadata(string, byte[], uint, byte)
Sets (adds or replaces) a metadata entry in this CHD (chdman addmeta parity).
The entry at occurrence index among entries with tag
tag is replaced; when index equals the number of
existing entries with that tag, the entry is appended. The metadata chain is rewritten
atomically (temp file + rename), the combined SHA-1 is recomputed for V4/V5, and this
instance is transparently reopened against the new file.
public ChdError SetMetadata(string tag, byte[] data, uint index = 0, byte flags = 1)
Parameters
tagstringFour-character metadata tag (e.g. "GAME", "GDDD").
databyte[]The metadata payload bytes.
indexuintZero-based occurrence index of the entry to replace, or the number of existing entries to append. Default 0.
flagsbyteMetadata flags: MetadataChecksumFlag (default) includes the entry in the combined-SHA1 verification.
Returns
- ChdError
Chderrnone on success; Chderrinvalidparameter for V1/V2 files, a stream opened with
leaveOpen, a non-four-character tag, or an out-of-range index; Chderrmetadatanotfound when the metadata chain could not be read; otherwise a write/IO error code.
ToString()
Returns a string representation of the CHD file including version, size, and hunk count.
public override string ToString()
Returns
WriteGdRomTrack(int, string, bool, IProgress<ChdProgress>?, CancellationToken)
Writes a single GD-ROM track in Redump CUE/BIN cooked mode, applying the
has_physical_pregap fixup. Use this for GD-ROM CUE extraction instead
of the standard track writer.
public ChdError WriteGdRomTrack(int trackIndex, string path, bool cooked, IProgress<ChdProgress>? progress = null, CancellationToken cancellationToken = default)
Parameters
trackIndexintZero-based track index.
pathstringOutput file path.
cookedboolWhen
truewrites cooked sectors (matching chdman); whenfalsewrites raw frames.progressIProgress<ChdProgress>Optional progress reporter.
cancellationTokenCancellationTokenCancellation token.
Returns
- ChdError
Chderrnone on success.
WriteTrackToFile(ChdTrackInfo, string, bool, IProgress<ChdProgress>?, CancellationToken)
Writes a single track to a file, optionally in cooked mode (stripped to DataSize per frame, matching chdman extractcd).
public ChdError WriteTrackToFile(ChdTrackInfo track, string path, bool cooked, IProgress<ChdProgress>? progress = null, CancellationToken cancellationToken = default)
Parameters
trackChdTrackInfoThe track to extract.
pathstringOutput file path.
cookedboolWhen
true, writes cooked sectors (DataSize per frame).progressIProgress<ChdProgress>Optional progress reporter.
cancellationTokenCancellationTokenCancellation token.
Returns
- ChdError
Chderrnone on success.
WriteTrackToFile(ChdTrackInfo, string, IProgress<ChdProgress>?, CancellationToken)
Writes a single track to a file, performing CDDA byte-swap for legacy GD-ROM audio tracks.
public ChdError WriteTrackToFile(ChdTrackInfo track, string path, IProgress<ChdProgress>? progress = null, CancellationToken cancellationToken = default)
Parameters
trackChdTrackInfoThe track to extract.
pathstringOutput file path.
progressIProgress<ChdProgress>Optional progress reporter.
cancellationTokenCancellationTokenCancellation token.
Returns
- ChdError
Chderrnone on success.