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

byte

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

int

Compression

Compression codecs declared in the header (up to 4 for V5; 1 for V1-V4).

public IEnumerable<ChdCodec> Compression { get; }

Property Value

IEnumerable<ChdCodec>

HunkBytes

Size in bytes of a single hunk (block).

public uint HunkBytes { get; }

Property Value

uint

HunkCount

Number of hunks (blocks) in the image.

public uint HunkCount { get; }

Property Value

uint

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

bool

IsChild

True if this CHD is a differential child. Alias for RequiresParent.

public bool IsChild { get; }

Property Value

bool

IsDvd

true if this CHD contains DVD metadata.

public bool IsDvd { get; }

Property Value

bool

IsGdRom

true if this CHD is a GD-ROM (Sega Dreamcast) image.

public bool IsGdRom { get; }

Property Value

bool

IsHdd

true if this CHD contains hard disk geometry metadata.

public bool IsHdd { get; }

Property Value

bool

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

bool

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

uint

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

long

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

IReadOnlyList<ChdMetadataEntry>

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

int

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

bool

SecondaryCodec

Secondary codec for V3/V4 CHDCOMPRESSION_ZLIB_PLUS files (type 6 map entries).

public ChdCodec SecondaryCodec { get; }

Property Value

ChdCodec

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

ulong

Tracks

Track layout information. null if this CHD is not a CD/GD-ROM image.

public IReadOnlyList<ChdTrackInfo>? Tracks { get; }

Property Value

IReadOnlyList<ChdTrackInfo>

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

uint

Version

CHD format version (1-5).

public uint Version { get; }

Property Value

uint

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

maxHunks int

Maximum 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

lookAhead int

Number 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

tag string

Four-character metadata tag (e.g. "GAME", "GDDD").

index uint

Zero-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

ValueTask

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

progress IProgress<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

string

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

outputDir string

Target directory. Created if it doesn't exist.

baseFileName string

Base filename (without extension) for output files.

progress IProgress<ChdProgress>

An optional IProgress<T> receiving a ChdProgress report after each decompressed hunk. null (default) disables progress reporting.

cancellationToken CancellationToken

A token to cancel the extraction. OperationCanceledException is thrown if cancellation is requested between hunk writes.

cooked bool

When true and this is a CD/GD-ROM image, writes cooked sectors (stripped to DataSize bytes per frame, omitting 96-byte subcode) matching chdman's extractcd output. When false (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

outputDir string

Target directory. Created if it doesn't exist.

baseFileName string

Base filename (without extension) for output files.

progress IProgress<ChdProgress>

An optional IProgress<T> receiving a ChdProgress report after each decompressed hunk. null (default) disables progress reporting.

cancellationToken CancellationToken

A token to cancel the extraction. OperationCanceledException is thrown if cancellation is requested between hunk writes.

cooked bool

When true and this is a CD/GD-ROM image, writes cooked sectors (stripped to DataSize bytes per frame) matching chdman's extractcd output. When false (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

tocPath string
binPath string
progress IProgress<ChdProgress>
cancellationToken CancellationToken

Returns

ChdError

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

binFileName string

The 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

binFileName string

The filename of the binary data file to reference in the CUE sheet.

style CueStyle

The 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

trackFiles string[]

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

trackFiles string[]

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

trackFiles string[]

Array of filenames for each track's binary data file. Must match track count.

cooked bool

When true, start LBA values are computed as the cumulative sum of previous tracks' Frames (chdman cooked output, pad-aware). When false the 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

binFileName string

Binary data filename quoted in DATAFILE lines (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

hunkIndex uint

Returns

string

GetHunkCodecNameForCodec(ChdCodec)

Returns the display name for a codec value (e.g. Deflate for zlib).

public static string GetHunkCodecNameForCodec(ChdCodec codec)

Parameters

codec ChdCodec

Returns

string

GetHunkCompressedLength(uint)

Returns the on-disk compressed length for a hunk (0 for SELF/PARENT/MINI).

public uint GetHunkCompressedLength(uint hunkIndex)

Parameters

hunkIndex uint

Returns

uint

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

hunkIndex uint

Returns

CompressionType

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

hunkIndex uint
codec ChdCodec
compressedBytes uint

Returns

ChdError

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

tag string

Four-character tag to search for (e.g. "GDDD", "CHT2"), or null/empty for a wildcard match.

index uint

Zero-based occurrence index among the entries with the matching tag.

entry ChdMetadataEntry

The matching entry, or null when 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

IReadOnlyList<ChdTrackInfo>

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

stream Stream

Seekable, readable stream positioned anywhere; it will be seeked as needed.

leaveOpen bool

If false, the stream is disposed when this instance is disposed.

parent ChdFile

An already-open parent ChdFile, or null for a standalone CHD. The caller retains ownership.

chdFile ChdFile

When this method returns, contains the opened ChdFile instance, or null on error.

cancellationToken CancellationToken

A 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

stream Stream

Seekable, readable stream positioned anywhere; it will be seeked as needed.

leaveOpen bool

If false, the stream is disposed when this instance is disposed.

parent ChdFile

An already-open parent ChdFile, or null for a standalone CHD. The caller retains ownership.

parentResolver ParentResolver

A callback for lazy parent resolution, or null to use the explicit parent.

chdFile ChdFile

When this method returns, contains the opened ChdFile instance, or null on error.

cancellationToken CancellationToken

A 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

stream Stream

Seekable, readable stream positioned anywhere; it will be seeked as needed.

leaveOpen bool

If false, the stream is disposed when this instance is disposed.

chdFile ChdFile

When this method returns, contains the opened ChdFile instance, or null on error.

cancellationToken CancellationToken

A 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

stream Stream

Seekable, readable stream positioned anywhere; it will be seeked as needed.

leaveOpen bool

If false, the stream is disposed when this instance is disposed.

parentResolver ParentResolver

A callback that resolves parent CHDs by SHA1/MD5 hash, or null to fail on parent-referenced hunks.

chdFile ChdFile

When this method returns, contains the opened ChdFile instance, or null on error.

cancellationToken CancellationToken

A 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

filename string

Path to the CHD file to open.

parent ChdFile

An already-open parent ChdFile, or null for a standalone CHD. The same parent instance may be shared by multiple children as long as all access is single-threaded.

chdFile ChdFile

When this method returns, contains the opened ChdFile, or null on error.

cancellationToken CancellationToken

A 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

filename string
parent ChdFile
memoryMapped bool
chdFile ChdFile
cancellationToken CancellationToken

Returns

ChdError

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

filename string

Path to the CHD file to open.

chdFile ChdFile

When this method returns, contains the opened ChdFile, or null on error.

cancellationToken CancellationToken

A 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

filename string

Path to the CHD file to open.

parentResolver ParentResolver

A callback that resolves parent CHDs by SHA1/MD5 hash, or null to fail on parent-referenced hunks.

chdFile ChdFile

When this method returns, contains the opened ChdFile, or null on error.

cancellationToken CancellationToken

A 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

filename string

Path to the CHD file to open.

memoryMapped bool

When 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 instances Precache is a no-op.

chdFile ChdFile

When this method returns, contains the opened ChdFile, or null on error.

cancellationToken CancellationToken

A 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

filename string

Path to the CHD file to open.

parentFilename string

Path to the parent CHD, or null/empty for a standalone CHD.

chdFile ChdFile

When this method returns, contains the opened ChdFile, or null on error.

cancellationToken CancellationToken

A 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

filename string
parentFilename string
memoryMapped bool
chdFile ChdFile
cancellationToken CancellationToken

Returns

ChdError

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

chd ChdFile

An opened ChdFile instance. Ownership is transferred to the stream; disposing the stream disposes this instance.

stream ChdImageStream

Contains the ChdImageStream.

Returns

ChdError

Chderrnone.

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

chd ChdFile

An opened ChdFile instance.

ownsChd bool

If true, disposing the stream disposes chd.

stream ChdImageStream

Contains the ChdImageStream.

Returns

ChdError

Chderrnone.

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

filename string

Path to the CHD file.

stream ChdImageStream

When this method returns Chderrnone, contains the ChdImageStream; null on failure.

cancellationToken CancellationToken

A 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

filename string

Path to the CHD file.

parentFilename string

Path to the parent CHD file, or null to open without a parent.

stream ChdImageStream

When this method returns Chderrnone, contains the ChdImageStream; null on failure.

cancellationToken CancellationToken

A 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

filename string

Path to the CHD file.

parentFilename string

Path to the parent CHD file, or null to open without a parent.

cancellationToken CancellationToken

A 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

filename string

Path to the CHD file.

cancellationToken CancellationToken

A 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

stream Stream

Seekable, readable stream positioned anywhere; it will be seeked as needed.

leaveOpen bool

If false, the stream is disposed when this instance is disposed.

parent ChdFile

An already-open parent ChdFile, or null for a standalone CHD. The caller retains ownership.

cancellationToken CancellationToken

A 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 null on 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

stream Stream

Seekable, readable stream positioned anywhere; it will be seeked as needed.

leaveOpen bool

If false, the stream is disposed when this instance is disposed.

parentResolver ParentResolver

A callback that resolves parent CHDs by SHA1/MD5 hash, or null.

cancellationToken CancellationToken

A 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 null on 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

stream Stream

Seekable, readable stream positioned anywhere; it will be seeked as needed.

leaveOpen bool

If false, the stream is disposed when this instance is disposed.

cancellationToken CancellationToken

A 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 null on 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

filename string

Path to the CHD file to open.

parent ChdFile

An already-open parent ChdFile, or null for a standalone CHD. The caller retains ownership.

cancellationToken CancellationToken

A 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 null on 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

filename string

Path to the CHD file to open.

parentResolver ParentResolver

A callback that resolves parent CHDs by SHA1/MD5 hash, or null.

cancellationToken CancellationToken

A 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 null on 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

filename string

Path to the CHD file to open.

parentFilename string

Path to the parent CHD, or null/empty for a standalone CHD.

cancellationToken CancellationToken

A 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 null on 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

filename string

Path to the CHD file to open.

cancellationToken CancellationToken

A 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 null on 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

maxBytes long

The 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 maxBytes or 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

byteOffset ulong

Byte offset into the decompressed image (0 to TotalBytes - 1).

destination byte[]

Destination buffer.

destinationOffset int

Offset in destination at which to start writing.

count int

Number of bytes to read.

cancellationToken CancellationToken

A 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

byteOffset ulong

Byte offset within the decompressed image (0-based).

destination Span<byte>

Destination span to fill.

count int

Number of bytes to read.

cancellationToken CancellationToken

A 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

data byte[]

When this method returns, contains the full decompressed image on success; an empty array on failure.

progress IProgress<ChdProgress>

An optional IProgress<T> receiving a ChdProgress report after each decompressed hunk. null (default) disables progress reporting.

cancellationToken CancellationToken

A 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

byteOffset ulong

Byte offset into the decompressed image (0 to TotalBytes - 1).

destination byte[]

Destination buffer.

destinationOffset int

Offset in destination at which to start writing.

count int

Number of bytes to read.

cancellationToken CancellationToken

A token to cancel the read. OperationCanceledException is thrown if cancellation is requested.

Returns

Task<ChdError>

A task producing the ChdError result.

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

lba uint

The logical block address (LBA 0 = MSF 00:02:00).

buffer byte[]

Destination buffer of at least UnitBytes bytes; receives the frame data.

cancellationToken CancellationToken

A token to cancel the read.

Returns

ChdError

Chderrnone on success; Chderrinvaliddata if this CHD has no CD/GD-ROM track metadata; Chderrinvalidparameter if buffer is too small or lba falls 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

hunknum uint

Zero-based hunk index (0 to HunkCount - 1).

buffer byte[]

Destination buffer of at least HunkBytes bytes.

cancellationToken CancellationToken

A token to cancel the decompression. OperationCanceledException is thrown if cancellation is requested before the hunk is decompressed.

Returns

ChdError

Chderrnone on success; Chderrhunkoutofrange if hunknum is out of range; Chderrinvalidparameter if buffer is 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

hunknum uint

Zero-based hunk index (0 to HunkCount - 1).

buffer Span<byte>

Destination span of at least HunkBytes bytes.

cancellationToken CancellationToken

A token to cancel the read.

Returns

ChdError

Chderrnone on success; Chderrhunkoutofrange if hunknum is out of range; Chderrinvalidparameter if buffer is 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

hunknum uint

Zero-based hunk index (0 to HunkCount - 1).

buffer byte[]

Destination buffer of at least HunkBytes bytes.

cancellationToken CancellationToken

A token to cancel the read. OperationCanceledException is thrown if cancellation is requested.

Returns

Task<ChdError>

A task producing the ChdError result.

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

hunknum uint

Zero-based hunk index (0 to HunkCount - 1).

buffer byte[]

Destination buffer of at least HunkBytes bytes.

cancellationToken CancellationToken

A 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

hunknum uint

Zero-based hunk index (0 to HunkCount - 1).

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. null when 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

hunknum is 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

hunknum uint

Zero-based hunk index (0 to HunkCount - 1).

cancellationToken CancellationToken

A token to cancel the read. OperationCanceledException is thrown if cancellation is requested.

Returns

Task<byte[]>

A task producing the raw stored bytes (null when the hunk has no on-disk data).

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

lba uint

The logical block address (LBA 0 = MSF 00:02:00).

buffer byte[]

Destination buffer of at least 2352 bytes; receives the sector data.

cancellationToken CancellationToken

A token to cancel the read.

Returns

ChdError

Chderrnone on success; Chderrinvaliddata if this CHD has no CD/GD-ROM track metadata; Chderrinvalidparameter if buffer is too small or lba falls 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

m byte

Minutes, BCD-encoded.

s byte

Seconds, BCD-encoded.

f byte

Frames, BCD-encoded.

buffer byte[]

Destination buffer of at least 2352 bytes; receives the sector data.

cancellationToken CancellationToken

A token to cancel the read.

Returns

ChdError

Chderrnone on success; Chderrinvaliddata if this CHD has no CD/GD-ROM track metadata; Chderrinvalidparameter if buffer is 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

tag string

Four-character metadata tag (e.g. "GAME", "GDDD").

data byte[]

The metadata payload bytes.

index uint

Zero-based occurrence index of the entry to replace, or the number of existing entries to append. Default 0.

flags byte

Metadata 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

string

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

trackIndex int

Zero-based track index.

path string

Output file path.

cooked bool

When true writes cooked sectors (matching chdman); when false writes raw frames.

progress IProgress<ChdProgress>

Optional progress reporter.

cancellationToken CancellationToken

Cancellation 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

track ChdTrackInfo

The track to extract.

path string

Output file path.

cooked bool

When true, writes cooked sectors (DataSize per frame).

progress IProgress<ChdProgress>

Optional progress reporter.

cancellationToken CancellationToken

Cancellation 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

track ChdTrackInfo

The track to extract.

path string

Output file path.

progress IProgress<ChdProgress>

Optional progress reporter.

cancellationToken CancellationToken

Cancellation token.

Returns

ChdError

Chderrnone on success.