From 68e17108b21a65a3544507c99133ddb4711f1efc Mon Sep 17 00:00:00 2001 From: Steve Date: Mon, 1 May 2023 11:25:53 -0500 Subject: [PATCH] DataWorker.js from https://github.com/Stuk/jszip/pull/555 --- lib/stream/DataWorker.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/stream/DataWorker.js b/lib/stream/DataWorker.js index ffb99bdd..38862fa8 100644 --- a/lib/stream/DataWorker.js +++ b/lib/stream/DataWorker.js @@ -28,7 +28,12 @@ function DataWorker(dataP) { self.data = data; self.max = data && data.length || 0; self.type = utils.getTypeOf(data); - if(!self.isPaused) { + + if (self.type === 'blob') { + self.max = data.size; + } + + if (!self.isPaused) { self._tickAndRepeat(); } }, function (e) { @@ -85,6 +90,7 @@ DataWorker.prototype._tick = function() { return false; } + var self = this; var size = DEFAULT_BLOCK_SIZE; var data = null, nextIndex = Math.min(this.max, this.index + size); if (this.index >= this.max) { @@ -92,6 +98,22 @@ DataWorker.prototype._tick = function() { return this.end(); } else { switch(this.type) { + case "blob": + var chunk = self.data.slice(this.index, nextIndex); + var reader = new FileReader(); + self.pause(); + self.index = nextIndex; + reader.onload = function(e) { + self.push({ + data : new Uint8Array(e.target.result), + meta : { + percent : self.max ? self.index / self.max * 100 : 0 + } + }); + self.resume(); + }; + reader.readAsArrayBuffer(chunk); + return; case "string": data = this.data.substring(this.index, nextIndex); break;