diff --git a/lib/internal/blob.js b/lib/internal/blob.js index e5ea99b0a965d2..d35a4615665c4d 100644 --- a/lib/internal/blob.js +++ b/lib/internal/blob.js @@ -65,6 +65,7 @@ const { const kHandle = Symbol('kHandle'); const kState = Symbol('kState'); +const kIndex = Symbol('kIndex'); const kType = Symbol('kType'); const kLength = Symbol('kLength'); const kArrayBufferPromise = Symbol('kArrayBufferPromise'); @@ -325,17 +326,17 @@ class Blob { return new lazyReadableStream({ async start() { this[kState] = await self.arrayBuffer(); + this[kIndex] = 0; }, pull(controller) { - if (this[kState].byteLength <= kMaxChunkSize) { - controller.enqueue(new Uint8Array(this[kState])); + if (this[kState].byteLength - this[kIndex] <= kMaxChunkSize) { + controller.enqueue(new Uint8Array(this[kState], this[kIndex])); controller.close(); this[kState] = undefined; } else { - const slice = this[kState].slice(0, kMaxChunkSize); - this[kState] = this[kState].slice(kMaxChunkSize); - controller.enqueue(new Uint8Array(slice)); + controller.enqueue(new Uint8Array(this[kState], this[kIndex], kMaxChunkSize)); + this[kIndex] += kMaxChunkSize; } } });