UNPKG

keynote-parser2

Version:

A library for parsing Apple Keynote file

36 lines (35 loc) 1.36 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseIwaSnappyFrame = void 0; const snappyjs_1 = __importDefault(require("snappyjs")); /** * Unpack IWA file chunk data from snappy frame * * - 0: 0x00 * - 1 ~ 3: length of the chunk data (little-endian) * - 4 ~ 4 + chunk data length: snappy compressed chunk data * * @see https://github.com/obriensp/iWorkFileFormat/blob/master/Docs/index.md#snappy-compression */ const parseIwaSnappyFrame = (data, cursor) => { // the first byte of the frame is always 0x00 if (data[cursor] !== 0x00) { throw new Error('Invalid IWA snappy frame'); } // the 1-3 bytes of the frame are the data length of the chunk const chunkBufferLength = data.readUintLE(cursor + 1, 3); // get the snappy compressed chunk data const chunkBufferStart = cursor + 4; const chunkBufferEnd = chunkBufferStart + chunkBufferLength; const chunkBuffer = data.subarray(chunkBufferStart, chunkBufferEnd); // uncompress the chunk data const chunk = snappyjs_1.default.uncompress(chunkBuffer); return { chunk, nextCursor: chunkBufferEnd, }; }; exports.parseIwaSnappyFrame = parseIwaSnappyFrame;