UNPKG

@runejs/filestore

Version:

Tools for managing the RuneJS filestore.

75 lines (74 loc) 2.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FileData = void 0; const common_1 = require("@runejs/common"); const data_1 = require("./data"); class FileData { /** * The ID of this file within it's File Index. */ fileId; /** * The File Index that this file belongs to. */ index; /** * A numeric hash of the file's name. */ nameHash; /** * A buffer of the file's raw data. */ content; /** * CRC value of the file's data. */ crc; /** * Whirlpool value of the file's data. */ whirlpool = new common_1.ByteBuffer(64); /** * Version number of the file. */ version; /** * The compression method used by the file in storage. */ compression; /** * The type of file, either an `archive` or a plain `file`. */ type = 'file'; filestoreChannels; decompressed = false; /** * Creates a new `FileData` object. * @param fileId The ID of the file within it's File Index. * @param index The File Index that this file belongs to. * @param filestoreChannels The main filestore channel for data access. */ constructor(fileId, index, filestoreChannels) { this.fileId = fileId; this.index = index; this.filestoreChannels = filestoreChannels; } /** * Reads the file's raw data from the main disk filestore and decompresses it. * @param keys The XTEA keys. * @returns The decompressed file data buffer. */ decompress(keys) { if (this.decompressed) { this.content.readerIndex = 0; this.content.writerIndex = 0; return this.content; } this.decompressed = true; const archiveEntry = (0, data_1.readIndexedDataChunk)(this.fileId, this.index.indexId, this.filestoreChannels); const { buffer } = (0, data_1.decompress)(archiveEntry?.dataFile, keys); this.content = buffer; return this.content; } } exports.FileData = FileData;