UNPKG

gulp-armapbo

Version:

The plugin for Gulp which allows to pack ArmA pbo files from sources.

49 lines (47 loc) 1.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const stackBuffer_1 = require("./stackBuffer"); const lzhPacket_1 = require("./lzhPacket"); const lzhReporter_1 = require("./lzhReporter"); class LzhCompressor { constructor(options) { this._progress = new lzhReporter_1.LzhReporter(options); } writeCompressed(entry, target, offset) { let sourceOffset = 0; let targetOffset = offset; const dict = this._getCompressionDict(); const source = entry.contents; this._progress.reportProgress(entry.name, source.length, 0); while (sourceOffset < source.length) { const packet = this._getPacket(); sourceOffset += packet.compose(source, sourceOffset, dict); targetOffset += packet.flush(target, targetOffset); this._progress.reportProgress(entry.name, source.length, sourceOffset); } this._progress.reportProgress(entry.name, source.length, source.length); targetOffset = this._writeCrc(source, target, targetOffset); const written = targetOffset - offset; return written; } _writeCrc(source, target, offset) { const crc = this._getCrc(source); offset = target.writeUInt32LE(crc, offset); return offset; } _getCrc(source) { let crc = 0; for (const byte of source) { crc += byte; } return crc; } _getCompressionDict() { return new stackBuffer_1.StackBuffer(); } _getPacket() { return new lzhPacket_1.LzhPacket(); } } exports.LzhCompressor = LzhCompressor; //# sourceMappingURL=lzhCompressor.js.map