/** * The shared name map of a data pack: the file named "nm" inside a .vromfs.bin. * * BLK documents with format labels 3, 4 and 5 refer to these names instead of carrying * their own (format.ts). Layout, checked against the stock 2.61.0.37 char.vromfs.bin: * 8 bytes hash of the names * 32 bytes identifier of the pack's zstd dictionary; all zero when the pack has none * rest zstd frame holding a name table (binary/name-table.ts) */ import { BlkFormatError } from './errors.ts'; import { ByteReader } from './binary/byte-reader.ts'; import { decompress } from './binary/format.ts'; import { readNameTable } from './binary/name-table.ts'; const HASH_SIZE = 8; const DICTIONARY_ID_SIZE = 32; export interface SharedNameMap { readonly names: readonly string[]; /** Hex identifier of the pack's zstd dictionary, or null when the pack has none. */ readonly dictionaryId: string | null; } export function parseSharedNameMap(file: Uint8Array, dictionary?: Uint8Array): SharedNameMap { if (file.length <= HASH_SIZE + DICTIONARY_ID_SIZE) throw new BlkFormatError('shared name map is too short'); const idBytes = file.subarray(HASH_SIZE, HASH_SIZE + DICTIONARY_ID_SIZE); const dictionaryId = idBytes.some((byte) => byte !== 0) ? Buffer.from(idBytes).toString('hex') : null; const body = decompress(file.subarray(HASH_SIZE + DICTIONARY_ID_SIZE), dictionary); return { names: readNameTable(new ByteReader(body)), dictionaryId }; }