import { File } from "../file.js"; import { Tag } from "../tag.js"; import { ReadStyle } from "../toolkit/types.js"; import type { IOStream } from "../toolkit/ioStream.js"; import { Id3v2Tag } from "../mpeg/id3v2/id3v2Tag.js"; import { DsdiffProperties } from "./dsdiffProperties.js"; import { DsdiffDiinTag } from "./dsdiffDiinTag.js"; /** * Identifies which tag types to strip from a DSDIFF file. * Values are bitflags that can be combined with `|`. */ export declare enum DsdiffTagType { /** The ID3v2 chunk. */ ID3v2 = 1, /** The DIIN sub-chunks (title + artist). */ DIIN = 2 } /** * DSD Interchange File Format (DSDIFF) handler. * * DSDIFF is a RIFF-style big-endian container ("FRM8" + "DSD ") that can * hold both DSD uncompressed and DST compressed audio. Metadata is * provided by an optional ID3v2 chunk and/or a DIIN chunk with limited * title/artist fields. */ export declare class DsdiffFile extends File { /** The ID3v2 tag, if present. */ private _id3v2Tag; /** The DIIN tag, if present. */ private _diinTag; /** Combined tag that delegates to the available sub-tags. */ private _combinedTag; /** Parsed audio properties. */ private _properties; /** Total file size as recorded in the FRM8 header (bytes, excluding the 12-byte FRM8 header). */ private _size; /** All root-level chunks discovered during parsing. */ private _chunks; /** Child chunks for the PROP and DIIN container chunks (indexed by {@link ChildChunkKind}). */ private _childChunks; /** Index into `_chunks` for the PROP and DIIN root chunks, or -1 if absent. */ private _childChunkIndex; /** Whether the ID3v2 tag lives inside the PROP chunk rather than at the root level. */ private _isID3InPropChunk; /** Whether an ID3v2 tag was found in the file. */ private _hasID3v2; /** Whether a DIIN chunk was found in the file. */ private _hasDiin; /** Four-character chunk ID used for the ID3v2 tag (either `"ID3 "` or `"id3 "`). */ private _id3v2TagChunkID; /** * Private constructor — use {@link DsdiffFile.open} to create instances. * @param stream The underlying I/O stream. */ private constructor(); /** * Opens a DSDIFF file and parses its metadata. * @param stream The I/O stream to read from. * @param readProperties Whether to parse audio properties (default `true`). * @param readStyle Accuracy / speed trade-off for property reading. * @returns A fully initialised {@link DsdiffFile} instance. */ static open(stream: IOStream, readProperties?: boolean, readStyle?: ReadStyle): Promise; /** * Quick-check whether `stream` looks like a valid DSDIFF file. * Requires "FRM8" at offset 0 and "DSD " at offset 12. */ static isSupported(stream: IOStream): Promise; /** * Converts a JavaScript string to Latin-1 bytes using C-string semantics: * each character is stored as `charCode & 0xFF`, stopping at the first * character whose code point maps to `0x00` in Latin-1. This matches the * behaviour of C++ TagLib's `ByteVector::fromCString(tag->artist().toCString())` * used in the DSDIFF DIIN chunk writer — `toCString()` returns a null-terminated * `const char*`, so characters that are truncated to `\x00` (i.e. code points * that are a multiple of 256) act as a string terminator. */ private static _toLatin1CString; /** * Returns the combined tag (ID3v2 with DIIN fallback) for this file. * @returns The active {@link CombinedTag}. */ tag(): Tag; /** * Returns the parsed audio properties, or `null` if properties were not read. * @returns The {@link DsdiffProperties} or `null`. */ audioProperties(): DsdiffProperties | null; /** * Writes all pending tag changes back to the underlying stream. * @param version ID3v2 version to use when rendering the ID3v2 tag (3 or 4, default 4). * @returns `true` on success, `false` if the file is read-only. */ save(version?: number): Promise; /** * Removes the specified tag types from the file. * * Passing {@link DsdiffTagType.ID3v2} removes the ID3v2 chunk, passing * {@link DsdiffTagType.DIIN} removes the DIIN sub-chunks and container, and * passing both (or omitting the argument) removes all tags. * * @param tags Bitmask of tag types to remove (default: all tags). */ strip(tags?: DsdiffTagType): Promise; /** Get the ID3v2 tag, optionally creating one if absent. */ id3v2Tag(create?: boolean): Id3v2Tag | null; /** Get the DIIN tag, optionally creating one if absent. */ diinTag(create?: boolean): DsdiffDiinTag | null; /** Whether the file contains an ID3v2 tag. */ get hasID3v2Tag(): boolean; /** Whether the file contains a DIIN chunk. */ get hasDIINTag(): boolean; /** * Reads and parses the DSDIFF file structure from the stream. * @param readProperties Whether to parse audio properties. * @param readStyle Accuracy / speed trade-off hint. */ private read; /** * Parses the child chunks of the PROP (Sound Property) container chunk. * @param rootIdx Index of the PROP chunk in `_chunks`. * @param bigEndian Whether integers are big-endian (always `true` for DSDIFF). */ private parsePROPChunk; /** * Parses the child chunks of the DIIN (DSD Interchange Information) container chunk. * @param rootIdx Index of the DIIN chunk in `_chunks`. * @param bigEndian Whether integers are big-endian (always `true` for DSDIFF). */ private parseDIINChunk; /** * Writes data to a root-level chunk, creating or removing it as needed. * @param name Four-character chunk name. * @param data Payload to write; an empty vector removes the chunk. */ private setRootChunkData; /** * Writes data to a child chunk inside a container chunk, creating or removing it as needed. * @param name Four-character chunk name. * @param data Payload to write; an empty vector removes the chunk. * @param kind Which container chunk (PROP or DIIN) to operate on. */ private setChildChunkData; /** * Removes a root-level chunk by index, updating the file and chunk list. * @param i Index into `_chunks` of the chunk to remove. */ private removeRootChunk; /** * Replaces the payload of a root-level chunk in place. * @param i Index into `_chunks` of the chunk to update. * @param data New payload to write. */ private updateRootChunk; /** * Appends a new root-level chunk at the end of the file. * @param name Four-character chunk identifier. * @param data Payload to write. */ private appendRootChunk; /** * Removes a child chunk from a container chunk by index. * @param i Index of the child chunk within the container's child list. * @param kind Which container chunk (PROP or DIIN) to operate on. */ private removeChildChunk; /** * Replaces the payload of a child chunk inside a container chunk. * @param i Index of the child chunk within the container's child list. * @param data New payload to write. * @param kind Which container chunk (PROP or DIIN) to operate on. */ private updateChildChunk; /** * Appends a new child chunk inside a container chunk. * @param name Four-character chunk identifier. * @param data Payload to write. * @param kind Which container chunk (PROP or DIIN) to append into. */ private appendChildChunk; /** * Writes a DSDIFF chunk (header + payload + optional padding) to the stream. * @param name Four-character chunk identifier. * @param data Chunk payload. * @param offset File offset at which to write the chunk. * @param replace Number of bytes at `offset` to overwrite. * @param leadingPadding Optional number of zero-padding bytes to prepend. */ private writeChunk; /** * Recalculates the file offsets of root chunks starting at `startIdx`. * Must be called after any insertion or removal that shifts data. * @param startIdx First index in `_chunks` whose offset needs updating. */ private updateRootChunkOffsets; /** * Searches a chunk list for a chunk with the given name. * @param chunks The list of chunks to search. * @param name The four-character chunk identifier to look for. * @returns The index of the matching chunk, or -1 if not found. */ private findChunkIndex; /** * Returns `true` if `name` is a valid four-character printable ASCII chunk identifier. * @param name The byte vector to validate. * @returns `true` if the name consists of exactly four printable ASCII bytes. */ private isValidChunkID; /** Rebuilds `_combinedTag` from the current set of sub-tags (ID3v2 and DIIN). */ private refreshCombinedTag; } //# sourceMappingURL=dsdiffFile.d.ts.map