{“ast”:null,“code”:“'use strict';nnvar utils = require('../utils');nnvar GenericWorker = require('./GenericWorker'); // the size of the generated chunksn// TODO expose this as a public variablennnvar DEFAULT_BLOCK_SIZE = 16 * 1024;n/**n * A worker that reads a content and emits chunks.n * @constructorn * @param {Promise} dataP the promise of the data to splitn */nnfunction DataWorker(dataP) {n GenericWorker.call(this, "DataWorker");n var self = this;n this.dataIsReady = false;n this.index = 0;n this.max = 0;n this.data = null;n this.type = "";n this._tickScheduled = false;n dataP.then(function (data) {n self.dataIsReady = true;n self.data = data;n self.max = data && data.length || 0;n self.type = utils.getTypeOf(data);nn if (!self.isPaused) {n self._tickAndRepeat();n }n }, function (e) {n self.error(e);n });n}nnutils.inherits(DataWorker, GenericWorker);n/**n * @see GenericWorker.cleanUpn */nnDataWorker.prototype.cleanUp = function () {n GenericWorker.prototype.cleanUp.call(this);n this.data = null;n};n/**n * @see GenericWorker.resumen */nnnDataWorker.prototype.resume = function () {n if (!GenericWorker.prototype.resume.call(this)) {n return false;n }nn if (!this._tickScheduled && this.dataIsReady) {n this._tickScheduled = true;n utils.delay(this._tickAndRepeat, [], this);n }nn return true;n};n/**n * Trigger a tick a schedule an other call to this function.n */nnnDataWorker.prototype._tickAndRepeat = function () {n this._tickScheduled = false;nn if (this.isPaused || this.isFinished) {n return;n }nn this._tick();nn if (!this.isFinished) {n utils.delay(this._tickAndRepeat, [], this);n this._tickScheduled = true;n }n};n/**n * Read and push a chunk.n */nnnDataWorker.prototype._tick = function () {n if (this.isPaused || this.isFinished) {n return false;n }nn var size = DEFAULT_BLOCK_SIZE;n var data = null,n nextIndex = Math.min(this.max, this.index + size);nn if (this.index >= this.max) {n // EOFn return this.end();n } else {n switch (this.type) {n case "string":n data = this.data.substring(this.index, nextIndex);n break;nn case "uint8array":n data = this.data.subarray(this.index, nextIndex);n break;nn case "array":n case "nodebuffer":n data = this.data.slice(this.index, nextIndex);n break;n }nn this.index = nextIndex;n return this.push({n data: data,n meta: {n percent: this.max ? this.index / this.max * 100 : 0n }n });n }n};nnmodule.exports = DataWorker;”,“map”:null,“metadata”:{},“sourceType”:“module”}