mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
src, lib: fixup lint and format issues for DataQueue/Blob
Co-authored-by: flakey5 <73616808+flakey5@users.noreply.github.com> PR-URL: https://github.com/nodejs/node/pull/45258 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
parent
950cec4c26
commit
71fb06fd64
18 changed files with 1261 additions and 1137 deletions
|
@ -1,6 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
const {
|
||||
ArrayBuffer,
|
||||
ArrayFrom,
|
||||
MathMax,
|
||||
MathMin,
|
||||
|
@ -21,7 +22,7 @@ const {
|
|||
|
||||
const {
|
||||
createBlob: _createBlob,
|
||||
createBlobFromFileHandle: _createBlobFromFileHandle,
|
||||
createBlobFromFilePath: _createBlobFromFilePath,
|
||||
concat,
|
||||
getDataObject,
|
||||
} = internalBinding('blob');
|
||||
|
@ -48,6 +49,7 @@ const {
|
|||
customInspectSymbol: kInspect,
|
||||
kEmptyObject,
|
||||
kEnumerableProperty,
|
||||
lazyDOMException,
|
||||
} = require('internal/util');
|
||||
const { inspect } = require('internal/util/inspect');
|
||||
|
||||
|
@ -58,7 +60,6 @@ const {
|
|||
ERR_INVALID_THIS,
|
||||
ERR_BUFFER_TOO_LARGE,
|
||||
},
|
||||
errnoException,
|
||||
} = require('internal/errors');
|
||||
|
||||
const {
|
||||
|
@ -66,6 +67,10 @@ const {
|
|||
validateDictionary,
|
||||
} = require('internal/validators');
|
||||
|
||||
const {
|
||||
CountQueuingStrategy,
|
||||
} = require('internal/webstreams/queuingstrategies');
|
||||
|
||||
const kHandle = Symbol('kHandle');
|
||||
const kType = Symbol('kType');
|
||||
const kLength = Symbol('kLength');
|
||||
|
@ -265,16 +270,23 @@ class Blob {
|
|||
return PromiseResolve(new ArrayBuffer(0));
|
||||
}
|
||||
|
||||
const { promise, resolve } = createDeferredPromise();
|
||||
const { promise, resolve, reject } = createDeferredPromise();
|
||||
const reader = this[kHandle].getReader();
|
||||
const buffers = [];
|
||||
const readNext = () => {
|
||||
reader.pull((status, buffer) => {
|
||||
if (status === -1) {
|
||||
if (status === 0) {
|
||||
// EOS, concat & resolve
|
||||
// buffer should be undefined here
|
||||
resolve(concat(buffers));
|
||||
return;
|
||||
} else if (status < 0) {
|
||||
// The read could fail for many different reasons when reading
|
||||
// from a non-memory resident blob part (e.g. file-backed blob).
|
||||
// The error details the system error code.
|
||||
const error = lazyDOMException('The blob could not be read', 'NotReadableError');
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
if (buffer !== undefined)
|
||||
buffers.push(buffer);
|
||||
|
@ -319,7 +331,7 @@ class Blob {
|
|||
},
|
||||
pull(c) {
|
||||
const { promise, resolve, reject } = createDeferredPromise();
|
||||
this.pendingPulls.push({resolve, reject});
|
||||
this.pendingPulls.push({ resolve, reject });
|
||||
reader.pull((status, buffer) => {
|
||||
// If pendingPulls is empty here, the stream had to have
|
||||
// been canceled, and we don't really care about the result.
|
||||
|
@ -328,18 +340,24 @@ class Blob {
|
|||
return;
|
||||
}
|
||||
const pending = this.pendingPulls.shift();
|
||||
if (status === -1 || (status === 0 && buffer === undefined)) {
|
||||
if (status === 0) {
|
||||
// EOS
|
||||
c.close();
|
||||
pending.resolve();
|
||||
return;
|
||||
} else if (status < 0) {
|
||||
const error = errnoException(status, 'read');
|
||||
// The read could fail for many different reasons when reading
|
||||
// from a non-memory resident blob part (e.g. file-backed blob).
|
||||
// The error details the system error code.
|
||||
const error = lazyDOMException('The blob could not be read', 'NotReadableError');
|
||||
|
||||
c.error(error);
|
||||
pending.reject(error);
|
||||
return;
|
||||
}
|
||||
c.enqueue(new Uint8Array(buffer));
|
||||
if (buffer !== undefined) {
|
||||
c.enqueue(new Uint8Array(buffer));
|
||||
}
|
||||
pending.resolve();
|
||||
});
|
||||
return promise;
|
||||
|
@ -422,16 +440,22 @@ function resolveObjectURL(url) {
|
|||
}
|
||||
}
|
||||
|
||||
function createBlobFromFileHandle(handle) {
|
||||
const [blob, length] = _createBlobFromFileHandle(handle);
|
||||
return createBlob(blob, length);
|
||||
// TODO(@jasnell): Now that the File class exists, we might consider having
|
||||
// this return a `File` instead of a `Blob`.
|
||||
function createBlobFromFilePath(path, options) {
|
||||
const maybeBlob = _createBlobFromFilePath(path);
|
||||
if (maybeBlob === undefined) {
|
||||
return lazyDOMException('The blob could not be read', 'NotReadableError');
|
||||
}
|
||||
const { 0: blob, 1: length } = maybeBlob;
|
||||
return createBlob(blob, length, options?.type);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
Blob,
|
||||
ClonedBlob,
|
||||
createBlob,
|
||||
createBlobFromFileHandle,
|
||||
createBlobFromFilePath,
|
||||
isBlob,
|
||||
kHandle,
|
||||
resolveObjectURL,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue