mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
buffer: improve blob read performance
Fix: https://github.com/nodejs/node/issues/42108 PR-URL: https://github.com/nodejs/node/pull/42117 Fixes: https://github.com/nodejs/node/issues/42108 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Mestery <mestery@protonmail.com>
This commit is contained in:
parent
04c68ba54a
commit
38626e7f5d
1 changed files with 6 additions and 5 deletions
|
@ -64,6 +64,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');
|
||||
|
@ -323,17 +324,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;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue