UNPKG

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.

130 lines (129 loc) • 4.94 kB
var timestampUtil_default = { /** * Parse the Info-ZIP Extended Timestamp (0x5455, "UT") extra field and return the modified, * accessed, and/or created times present per the leading info-byte flags. Each time is a * 32-bit signed Unix epoch seconds value (UTC) with 1-second resolution. * @see https://libzip.org/specifications/appnote_iz.txt */ parseExtendedTimestamp: (buffer) => { if (buffer === void 0 || buffer.length === 0) { return void 0; } const times = Array.from( { length: Math.floor((buffer.length - 1) / 4) }, (_, idx) => buffer.readInt32LE(1 + idx * 4) ); if (times.length === 0) { return void 0; } const timestamps = {}; let readTimes = 0; const infoBit = buffer.readInt8(0); if (infoBit & 1) { const epochSeconds = times.at(readTimes); timestamps.modified = epochSeconds === void 0 ? void 0 : new Date(epochSeconds * 1e3); readTimes += 1; } if (infoBit & 2) { const epochSeconds = times.at(readTimes); timestamps.accessed = epochSeconds === void 0 ? void 0 : new Date(epochSeconds * 1e3); readTimes += 1; } if (infoBit & 4) { const epochSeconds = times.at(readTimes); timestamps.created = epochSeconds === void 0 ? void 0 : new Date(epochSeconds * 1e3); } return timestamps; }, /** * Parse the Info-ZIP Unix (0x5855, "UX") or PKWARE Unix (0x000d) extra field and return the * accessed and modified times. Both formats begin with an accessed time and a modified time * stored as 32-bit unsigned Unix epoch seconds (UTC) with 1-second resolution. * @see https://libzip.org/specifications/appnote_iz.txt */ parseUnixExtraTimestamp: (buffer) => { if (buffer === void 0 || buffer.length === 0) { return void 0; } return { accessed: new Date(buffer.readUInt32LE(0) * 1e3), modified: new Date(buffer.readUInt32LE(4) * 1e3) }; }, /** * Parse the NTFS (0x000a) extra field and return the modified, accessed, and created times * recorded by Windows. Times are 64-bit FILETIME values (100-ns intervals since 1601-01-01 * UTC). Returns undefined when the file-times attribute (tag 0x0001) is absent. * @see https://libzip.org/specifications/appnote_iz.txt */ parseNtfsExtraTimestamp: (buffer) => { if (buffer === void 0 || buffer.length === 0) { return void 0; } const attributes = /* @__PURE__ */ new Map(); let position = 4; while (position < buffer.length) { const attributeTagValue = buffer.readUInt16LE(position); const attributeTagSize = buffer.readUInt16LE(position + 2); const attributeTagData = buffer.subarray(position + 4, position + 4 + attributeTagSize); attributes.set(attributeTagValue, attributeTagData); position += 4 + attributeTagSize; } const fileTimes = attributes.get(1); if (fileTimes === void 0) { return void 0; } return { modified: new Date( Number(BigInt(Date.UTC(1601, 0, 1)) + fileTimes.readBigUInt64LE(0) / 10000n) ), accessed: new Date( Number(BigInt(Date.UTC(1601, 0, 1)) + fileTimes.readBigUInt64LE(8) / 10000n) ), created: new Date( Number(BigInt(Date.UTC(1601, 0, 1)) + fileTimes.readBigUInt64LE(16) / 10000n) ) }; }, /** * Parse the Info-ZIP Macintosh (0x334d, "Mac3") extra field and return the file's modified * and created times. The trailing Finder/file-info block may be zlib-compressed when flag * bit 14 is set; that case is unsupported and yields undefined. * @see https://libzip.org/specifications/appnote_iz.txt */ parseInfoZipMacintoshExtraTimestamp: (buffer) => { if (buffer === void 0 || buffer.length < 6) { return void 0; } const flags = buffer.readUInt16LE(4); if (flags & 16384) { return void 0; } if (buffer.length < 53) { return void 0; } return { created: new Date(buffer.readUInt32BE(45) * 1e3 + Date.UTC(1904, 0, 1)), modified: new Date(buffer.readUInt32BE(49) * 1e3 + Date.UTC(1904, 0, 1)) }; }, /** * Parse the MS-DOS time/date pair carried in every zip header and return the file's * modification time. DOS time has 2-second resolution and is interpreted as local time, as * the specification provides no timezone information. * @see https://github.com/DidierStevens/DidierStevensSuite/blob/master/zipdump.py */ parseDOSTimestamp: (bufferTime, bufferDate) => { const seconds = (bufferTime & 31) * 2; const minutes = (bufferTime & 2016) >> 5; const hours = (bufferTime & 63488) >> 11; const day = bufferDate & 31; const month = (bufferDate & 480) >> 5; const year = 1980 + ((bufferDate & 65024) >> 9); return new Date(year, month - 1, day, hours, minutes, seconds); } }; export { timestampUtil_default as default }; //# sourceMappingURL=timestampUtil.js.map