UNPKG

@pdfme/pdf-lib

Version:

Create and modify PDF files with JavaScript

63 lines 2.12 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const DecodeStream_1 = __importDefault(require("./DecodeStream")); const chunkSize = 512; class DecryptStream extends DecodeStream_1.default { constructor(stream, decrypt, maybeLength) { super(maybeLength); Object.defineProperty(this, "stream", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "initialized", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "nextChunk", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "decrypt", { enumerable: true, configurable: true, writable: true, value: void 0 }); this.stream = stream; this.decrypt = decrypt; this.nextChunk = null; this.initialized = false; } readBlock() { let chunk; if (this.initialized) { chunk = this.nextChunk; } else { chunk = this.stream.getBytes(chunkSize); this.initialized = true; } if (!chunk || chunk.length === 0) { this.eof = true; return; } this.nextChunk = this.stream.getBytes(chunkSize); const hasMoreData = this.nextChunk && this.nextChunk.length > 0; const decrypt = this.decrypt; chunk = decrypt(chunk, !hasMoreData); const bufferLength = this.bufferLength, newLength = bufferLength + chunk.length, buffer = this.ensureBuffer(newLength); buffer.set(chunk, bufferLength); this.bufferLength = newLength; } } exports.default = DecryptStream; //# sourceMappingURL=DecryptStream.js.map