UNPKG

@thewtex/vtk.js-esm

Version:

Visualization Toolkit for the Web

97 lines (80 loc) 2.53 kB
import { p as pako_1 } from '../node_modules/pako/index.js'; import { u as utils } from './utils.js'; import { G as GenericWorker_1 } from './stream/GenericWorker.js'; var USE_TYPEDARRAY = (typeof Uint8Array !== 'undefined') && (typeof Uint16Array !== 'undefined') && (typeof Uint32Array !== 'undefined'); var ARRAY_TYPE = USE_TYPEDARRAY ? "uint8array" : "array"; var magic = "\x08\x00"; /** * Create a worker that uses pako to inflate/deflate. * @constructor * @param {String} action the name of the pako function to call : either "Deflate" or "Inflate". * @param {Object} options the options to use when (de)compressing. */ function FlateWorker(action, options) { GenericWorker_1.call(this, "FlateWorker/" + action); this._pako = null; this._pakoAction = action; this._pakoOptions = options; // the `meta` object from the last chunk received // this allow this worker to pass around metadata this.meta = {}; } utils.inherits(FlateWorker, GenericWorker_1); /** * @see GenericWorker.processChunk */ FlateWorker.prototype.processChunk = function (chunk) { this.meta = chunk.meta; if (this._pako === null) { this._createPako(); } this._pako.push(utils.transformTo(ARRAY_TYPE, chunk.data), false); }; /** * @see GenericWorker.flush */ FlateWorker.prototype.flush = function () { GenericWorker_1.prototype.flush.call(this); if (this._pako === null) { this._createPako(); } this._pako.push([], true); }; /** * @see GenericWorker.cleanUp */ FlateWorker.prototype.cleanUp = function () { GenericWorker_1.prototype.cleanUp.call(this); this._pako = null; }; /** * Create the _pako object. * TODO: lazy-loading this object isn't the best solution but it's the * quickest. The best solution is to lazy-load the worker list. See also the * issue #446. */ FlateWorker.prototype._createPako = function () { this._pako = new pako_1[this._pakoAction]({ raw: true, level: this._pakoOptions.level || -1 // default compression }); var self = this; this._pako.onData = function(data) { self.push({ data : data, meta : self.meta }); }; }; var compressWorker = function (compressionOptions) { return new FlateWorker("Deflate", compressionOptions); }; var uncompressWorker = function () { return new FlateWorker("Inflate", {}); }; var flate = { magic: magic, compressWorker: compressWorker, uncompressWorker: uncompressWorker }; export { flate as f };