@gjsify/web-streams 0.3.12 → 0.3.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/index.js +22 -87
- package/lib/esm/queuing-strategies.js +47 -55
- package/lib/esm/readable-stream.js +836 -989
- package/lib/esm/register/queuing.js +7 -3
- package/lib/esm/register/readable.js +12 -8
- package/lib/esm/register/text-streams.js +7 -3
- package/lib/esm/register/transform.js +12 -8
- package/lib/esm/register/writable.js +12 -8
- package/lib/esm/text-decoder-stream.js +133 -118
- package/lib/esm/text-encoder-stream.js +58 -44
- package/lib/esm/transform-stream.js +242 -298
- package/lib/esm/util.js +106 -129
- package/lib/esm/writable-stream.js +588 -588
- package/package.json +4 -4
package/lib/esm/util.js
CHANGED
|
@@ -1,161 +1,138 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
1
|
+
//#region src/util.ts
|
|
2
|
+
const kState = Symbol("kState");
|
|
3
|
+
const kType = Symbol("kType");
|
|
3
4
|
function isBrandCheck(brand) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
return (value) => {
|
|
6
|
+
return value != null && typeof value === "object" && value[kState] !== undefined && value[kType] === brand;
|
|
7
|
+
};
|
|
7
8
|
}
|
|
8
9
|
function dequeueValue(controller) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const { value, size } = controller[kState].queue.shift();
|
|
11
|
+
controller[kState].queueTotalSize = Math.max(0, controller[kState].queueTotalSize - size);
|
|
12
|
+
return value;
|
|
12
13
|
}
|
|
13
14
|
function resetQueue(controller) {
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
controller[kState].queue = [];
|
|
16
|
+
controller[kState].queueTotalSize = 0;
|
|
16
17
|
}
|
|
17
18
|
function peekQueueValue(controller) {
|
|
18
|
-
|
|
19
|
+
return controller[kState].queue[0].value;
|
|
19
20
|
}
|
|
20
21
|
function enqueueValueWithSize(controller, value, size) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
size = +size;
|
|
23
|
+
if (typeof size !== "number" || size < 0 || Number.isNaN(size) || size === Infinity) {
|
|
24
|
+
throw new RangeError(`Invalid size: ${size}`);
|
|
25
|
+
}
|
|
26
|
+
controller[kState].queue.push({
|
|
27
|
+
value,
|
|
28
|
+
size
|
|
29
|
+
});
|
|
30
|
+
controller[kState].queueTotalSize += size;
|
|
27
31
|
}
|
|
28
32
|
function extractHighWaterMark(value, defaultHWM) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
if (value === undefined) return defaultHWM;
|
|
34
|
+
value = +value;
|
|
35
|
+
if (typeof value !== "number" || Number.isNaN(value) || value < 0) {
|
|
36
|
+
throw new RangeError(`Invalid highWaterMark: ${value}`);
|
|
37
|
+
}
|
|
38
|
+
return value;
|
|
35
39
|
}
|
|
36
40
|
function extractSizeAlgorithm(size) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
if (size === undefined) return () => 1;
|
|
42
|
+
if (typeof size !== "function") {
|
|
43
|
+
throw new TypeError("strategy.size must be a function");
|
|
44
|
+
}
|
|
45
|
+
return size;
|
|
42
46
|
}
|
|
43
47
|
function cloneAsUint8Array(view) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
const buffer = view.buffer;
|
|
49
|
+
const byteOffset = view.byteOffset;
|
|
50
|
+
const byteLength = view.byteLength;
|
|
51
|
+
return new Uint8Array(buffer.slice(byteOffset, byteOffset + byteLength));
|
|
48
52
|
}
|
|
49
53
|
function ArrayBufferViewGetBuffer(view) {
|
|
50
|
-
|
|
54
|
+
return view.buffer;
|
|
51
55
|
}
|
|
52
56
|
function ArrayBufferViewGetByteLength(view) {
|
|
53
|
-
|
|
57
|
+
return view.byteLength;
|
|
54
58
|
}
|
|
55
59
|
function ArrayBufferViewGetByteOffset(view) {
|
|
56
|
-
|
|
60
|
+
return view.byteOffset;
|
|
57
61
|
}
|
|
58
62
|
function setPromiseHandled(promise) {
|
|
59
|
-
|
|
60
|
-
}, () => {
|
|
61
|
-
});
|
|
63
|
+
promise.then(() => {}, () => {});
|
|
62
64
|
}
|
|
63
65
|
function createPromiseCallback(name, fn, thisArg) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
async function nonOpFlush() {
|
|
70
|
-
}
|
|
71
|
-
function
|
|
72
|
-
}
|
|
73
|
-
async function
|
|
74
|
-
}
|
|
75
|
-
async function nonOpCancel() {
|
|
76
|
-
}
|
|
77
|
-
async function nonOpWrite() {
|
|
78
|
-
}
|
|
79
|
-
const AsyncIteratorPrototype = Object.getPrototypeOf(
|
|
80
|
-
Object.getPrototypeOf(async function* () {
|
|
81
|
-
}).prototype
|
|
82
|
-
);
|
|
66
|
+
if (typeof fn !== "function") {
|
|
67
|
+
throw new TypeError(`${name} must be a function`);
|
|
68
|
+
}
|
|
69
|
+
return async (...args) => fn.call(thisArg, ...args);
|
|
70
|
+
}
|
|
71
|
+
async function nonOpFlush() {}
|
|
72
|
+
function nonOpStart() {}
|
|
73
|
+
async function nonOpPull() {}
|
|
74
|
+
async function nonOpCancel() {}
|
|
75
|
+
async function nonOpWrite() {}
|
|
76
|
+
const AsyncIteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf(async function* () {}).prototype);
|
|
83
77
|
const AsyncIterator = {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
78
|
+
__proto__: AsyncIteratorPrototype,
|
|
79
|
+
next: undefined,
|
|
80
|
+
return: undefined
|
|
87
81
|
};
|
|
88
82
|
function createAsyncFromSyncIterator(syncIteratorRecord) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
83
|
+
const syncIterable = { [Symbol.iterator]: () => syncIteratorRecord.iterator };
|
|
84
|
+
const asyncIterator = async function* () {
|
|
85
|
+
return yield* syncIterable;
|
|
86
|
+
}();
|
|
87
|
+
const nextMethod = asyncIterator.next;
|
|
88
|
+
return {
|
|
89
|
+
iterator: asyncIterator,
|
|
90
|
+
nextMethod,
|
|
91
|
+
done: false
|
|
92
|
+
};
|
|
97
93
|
}
|
|
98
94
|
function getIterator(obj, kind = "sync", method) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
95
|
+
if (method === undefined) {
|
|
96
|
+
if (kind === "async") {
|
|
97
|
+
method = obj[Symbol.asyncIterator];
|
|
98
|
+
if (method == null) {
|
|
99
|
+
const syncMethod = obj[Symbol.iterator];
|
|
100
|
+
if (syncMethod === undefined) {
|
|
101
|
+
throw new TypeError("Object is not iterable");
|
|
102
|
+
}
|
|
103
|
+
const syncIteratorRecord = getIterator(obj, "sync", syncMethod);
|
|
104
|
+
return createAsyncFromSyncIterator(syncIteratorRecord);
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
method = obj[Symbol.iterator];
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (method === undefined) {
|
|
111
|
+
throw new TypeError("Object is not iterable");
|
|
112
|
+
}
|
|
113
|
+
const iterator = method.call(obj);
|
|
114
|
+
if (typeof iterator !== "object" || iterator === null) {
|
|
115
|
+
throw new TypeError("The iterator method must return an object");
|
|
116
|
+
}
|
|
117
|
+
const nextMethod = iterator.next;
|
|
118
|
+
return {
|
|
119
|
+
iterator,
|
|
120
|
+
nextMethod,
|
|
121
|
+
done: false
|
|
122
|
+
};
|
|
123
123
|
}
|
|
124
124
|
function iteratorNext(iteratorRecord, value) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
ArrayBufferViewGetByteOffset,
|
|
140
|
-
AsyncIterator,
|
|
141
|
-
cloneAsUint8Array,
|
|
142
|
-
createAsyncFromSyncIterator,
|
|
143
|
-
createPromiseCallback,
|
|
144
|
-
dequeueValue,
|
|
145
|
-
enqueueValueWithSize,
|
|
146
|
-
extractHighWaterMark,
|
|
147
|
-
extractSizeAlgorithm,
|
|
148
|
-
getIterator,
|
|
149
|
-
isBrandCheck,
|
|
150
|
-
iteratorNext,
|
|
151
|
-
kState,
|
|
152
|
-
kType,
|
|
153
|
-
nonOpCancel,
|
|
154
|
-
nonOpFlush,
|
|
155
|
-
nonOpPull,
|
|
156
|
-
nonOpStart,
|
|
157
|
-
nonOpWrite,
|
|
158
|
-
peekQueueValue,
|
|
159
|
-
resetQueue,
|
|
160
|
-
setPromiseHandled
|
|
161
|
-
};
|
|
125
|
+
let result;
|
|
126
|
+
if (value === undefined) {
|
|
127
|
+
result = iteratorRecord.nextMethod.call(iteratorRecord.iterator);
|
|
128
|
+
} else {
|
|
129
|
+
result = iteratorRecord.nextMethod.call(iteratorRecord.iterator, value);
|
|
130
|
+
}
|
|
131
|
+
if (typeof result !== "object" || result === null) {
|
|
132
|
+
throw new TypeError("The iterator.next() method must return an object");
|
|
133
|
+
}
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
//#endregion
|
|
138
|
+
export { ArrayBufferViewGetBuffer, ArrayBufferViewGetByteLength, ArrayBufferViewGetByteOffset, AsyncIterator, cloneAsUint8Array, createAsyncFromSyncIterator, createPromiseCallback, dequeueValue, enqueueValueWithSize, extractHighWaterMark, extractSizeAlgorithm, getIterator, isBrandCheck, iteratorNext, kState, kType, nonOpCancel, nonOpFlush, nonOpPull, nonOpStart, nonOpWrite, peekQueueValue, resetQueue, setPromiseHandled };
|