igir
Version:
🕹 A zero-setup ROM collection manager that sorts, filters, extracts or archives, patches, and reports on collections of any size on any OS.
42 lines (41 loc) • 1.6 kB
JavaScript
class ArchiveExtraDataRecord {
static ARCHIVE_EXTRA_DATA_RECORD_SIGNATURE = Buffer.from("08064b50", "hex").toReversed();
// Size of the signature plus the extra field length field, without the variable-length data.
static ARCHIVE_EXTRA_DATA_RECORD_SIZE = 8;
raw;
extraFieldLength;
extraFieldData;
constructor(props) {
this.raw = props.raw;
this.extraFieldLength = props.extraFieldLength;
this.extraFieldData = props.extraFieldData;
}
/**
* Parse an archive extra data record at the given position, or return undefined if its signature
* is not present there.
*/
static async fromFileHandle(fileHandle, position) {
const fixedLengthBuffer = Buffer.allocUnsafe(this.ARCHIVE_EXTRA_DATA_RECORD_SIZE);
const { bytesRead } = await fileHandle.read({ buffer: fixedLengthBuffer, position });
if (bytesRead < this.ARCHIVE_EXTRA_DATA_RECORD_SIZE || !fixedLengthBuffer.subarray(0, this.ARCHIVE_EXTRA_DATA_RECORD_SIGNATURE.length).equals(this.ARCHIVE_EXTRA_DATA_RECORD_SIGNATURE)) {
return void 0;
}
const extraFieldLength = fixedLengthBuffer.readUInt32LE(4);
const extraFieldData = Buffer.allocUnsafe(extraFieldLength);
if (extraFieldLength > 0) {
await fileHandle.read({
buffer: extraFieldData,
position: position + fixedLengthBuffer.length
});
}
return new ArchiveExtraDataRecord({
raw: Buffer.concat([fixedLengthBuffer, extraFieldData]),
extraFieldLength,
extraFieldData
});
}
}
export {
ArchiveExtraDataRecord as default
};
//# sourceMappingURL=archiveExtraDataRecord.js.map