@loaders.gl/polyfills 4.2.0-alpha.4 → 4.2.0-alpha.5
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/dist/buffer/btoa.node.js +5 -3
- package/dist/buffer/to-array-buffer.node.js +6 -6
- package/dist/crypto/node-hash.js +41 -45
- package/dist/fetch/decode-data-uri.js +56 -41
- package/dist/fetch/fetch-polyfill.d.ts +1 -1
- package/dist/fetch/fetch-polyfill.d.ts.map +1 -1
- package/dist/fetch/fetch-polyfill.js +118 -103
- package/dist/fetch/headers-polyfill.js +90 -89
- package/dist/fetch/response-polyfill.d.ts +1 -1
- package/dist/fetch/response-polyfill.d.ts.map +1 -1
- package/dist/fetch/response-polyfill.js +65 -57
- package/dist/fetch/utils/decode-data-uri.node.js +56 -41
- package/dist/file/blob-stream-controller.js +54 -38
- package/dist/file/blob-stream.d.ts +1 -1
- package/dist/file/blob-stream.d.ts.map +1 -1
- package/dist/file/blob-stream.js +29 -15
- package/dist/file/blob.d.ts +1 -1
- package/dist/file/blob.d.ts.map +1 -1
- package/dist/file/blob.js +146 -109
- package/dist/file/file-reader.js +22 -50
- package/dist/file/file.js +30 -15
- package/dist/file/install-blob-polyfills.js +6 -5
- package/dist/file/install-file-polyfills.js +11 -8
- package/dist/file/readable-stream.js +5 -2
- package/dist/filesystems/fetch-node.js +78 -68
- package/dist/filesystems/node-file.js +119 -87
- package/dist/filesystems/node-filesystem.d.ts +1 -1
- package/dist/filesystems/node-filesystem.d.ts.map +1 -1
- package/dist/filesystems/node-filesystem.js +39 -35
- package/dist/filesystems/stream-utils.node.js +88 -55
- package/dist/images/encode-image-node.js +25 -12
- package/dist/images/encode-image.node.js +25 -12
- package/dist/images/parse-image-node.js +30 -23
- package/dist/images/parse-image.node.js +30 -23
- package/dist/index.browser.js +8 -3
- package/dist/index.cjs +13 -65091
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +45 -15
- package/dist/libs/encoding-indexes-asian.js +6 -7
- package/dist/load-library/require-utils.node.js +70 -44
- package/dist/streams/make-node-stream.js +48 -46
- package/dist/text-encoder/encoding-indexes.js +31 -28
- package/dist/text-encoder/text-encoder.js +2604 -1033
- package/dist/utils/assert.js +3 -4
- package/dist/utils/is-browser.js +7 -2
- package/package.json +10 -8
- package/dist/buffer/btoa.node.js.map +0 -1
- package/dist/buffer/to-array-buffer.node.js.map +0 -1
- package/dist/crypto/node-hash.js.map +0 -1
- package/dist/dist.dev.js +0 -45
- package/dist/fetch/decode-data-uri.js.map +0 -1
- package/dist/fetch/fetch-polyfill.js.map +0 -1
- package/dist/fetch/headers-polyfill.js.map +0 -1
- package/dist/fetch/response-polyfill.js.map +0 -1
- package/dist/fetch/utils/decode-data-uri.node.js.map +0 -1
- package/dist/file/blob-stream-controller.js.map +0 -1
- package/dist/file/blob-stream.js.map +0 -1
- package/dist/file/blob.js.map +0 -1
- package/dist/file/file-reader.js.map +0 -1
- package/dist/file/file.js.map +0 -1
- package/dist/file/install-blob-polyfills.js.map +0 -1
- package/dist/file/install-file-polyfills.js.map +0 -1
- package/dist/file/readable-stream.js.map +0 -1
- package/dist/filesystems/fetch-node.js.map +0 -1
- package/dist/filesystems/node-file.js.map +0 -1
- package/dist/filesystems/node-filesystem.js.map +0 -1
- package/dist/filesystems/stream-utils.node.js.map +0 -1
- package/dist/images/encode-image-node.js.map +0 -1
- package/dist/images/encode-image.node.js.map +0 -1
- package/dist/images/parse-image-node.js.map +0 -1
- package/dist/images/parse-image.node.js.map +0 -1
- package/dist/index.browser.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/load-library/require-utils.node.js.map +0 -1
- package/dist/streams/make-node-stream.js.map +0 -1
- package/dist/text-encoder/encoding-indexes.js.map +0 -1
- package/dist/text-encoder/text-encoder.js.map +0 -1
- package/dist/utils/assert.js.map +0 -1
- package/dist/utils/is-browser.js.map +0 -1
|
@@ -1,101 +1,102 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Polyfill for Browser Headers
|
|
3
|
+
* Based on https://github.com/github/fetch under MIT license
|
|
4
|
+
*/
|
|
3
5
|
export class Headers {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
constructor(headers) {
|
|
7
|
+
this.map = {};
|
|
8
|
+
if (headers instanceof Headers) {
|
|
9
|
+
headers.forEach((value, name) => this.append(name, value));
|
|
10
|
+
}
|
|
11
|
+
else if (Array.isArray(headers)) {
|
|
12
|
+
headers.forEach((header) => this.append(header[0], header[1]));
|
|
13
|
+
}
|
|
14
|
+
else if (headers) {
|
|
15
|
+
Object.getOwnPropertyNames(headers).forEach((name) => this.append(name, headers[name]));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
append(name, value) {
|
|
19
|
+
name = normalizeName(name);
|
|
20
|
+
value = normalizeValue(value);
|
|
21
|
+
const oldValue = this.map[name];
|
|
22
|
+
this.map[name] = oldValue ? `${oldValue}, ${value}` : value;
|
|
23
|
+
}
|
|
24
|
+
delete(name) {
|
|
25
|
+
delete this.map[normalizeName(name)];
|
|
13
26
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
forEach(visitor) {
|
|
35
|
-
let thisArg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
36
|
-
for (const name in this.map) {
|
|
37
|
-
if (this.map.hasOwnProperty(name)) {
|
|
38
|
-
if (thisArg) {
|
|
39
|
-
visitor.call(thisArg, this.map[name], name, this);
|
|
40
|
-
} else {
|
|
41
|
-
visitor(this.map[name], name, this);
|
|
27
|
+
get(name) {
|
|
28
|
+
name = normalizeName(name);
|
|
29
|
+
return this.has(name) ? this.map[name] : null;
|
|
30
|
+
}
|
|
31
|
+
has(name) {
|
|
32
|
+
return this.map.hasOwnProperty(normalizeName(name));
|
|
33
|
+
}
|
|
34
|
+
set(name, value) {
|
|
35
|
+
this.map[normalizeName(name)] = normalizeValue(value);
|
|
36
|
+
}
|
|
37
|
+
forEach(visitor, thisArg = null) {
|
|
38
|
+
for (const name in this.map) {
|
|
39
|
+
if (this.map.hasOwnProperty(name)) {
|
|
40
|
+
if (thisArg) {
|
|
41
|
+
visitor.call(thisArg, this.map[name], name, this);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
visitor(this.map[name], name, this);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
42
47
|
}
|
|
43
|
-
}
|
|
44
48
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
49
|
+
keys() {
|
|
50
|
+
const items = [];
|
|
51
|
+
this.forEach(function (value, name) {
|
|
52
|
+
items.push(name);
|
|
53
|
+
});
|
|
54
|
+
return iteratorFor(items);
|
|
55
|
+
}
|
|
56
|
+
values() {
|
|
57
|
+
const items = [];
|
|
58
|
+
this.forEach(function (value) {
|
|
59
|
+
items.push(value);
|
|
60
|
+
});
|
|
61
|
+
return iteratorFor(items);
|
|
62
|
+
}
|
|
63
|
+
entries() {
|
|
64
|
+
const items = [];
|
|
65
|
+
this.forEach(function (value, name) {
|
|
66
|
+
items.push([name, value]);
|
|
67
|
+
});
|
|
68
|
+
return iteratorFor(items);
|
|
69
|
+
}
|
|
70
|
+
*[Symbol.iterator]() {
|
|
71
|
+
// @ts-ignore must have a '[Symbol.iterator]()' method that returns an iterator.
|
|
72
|
+
yield* this.entries();
|
|
73
|
+
}
|
|
70
74
|
}
|
|
71
75
|
function normalizeName(name) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
if (typeof name !== 'string') {
|
|
77
|
+
name = String(name);
|
|
78
|
+
}
|
|
79
|
+
if (/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(name) || name === '') {
|
|
80
|
+
throw new TypeError('Invalid character in header field name');
|
|
81
|
+
}
|
|
82
|
+
return name.toLowerCase();
|
|
79
83
|
}
|
|
80
84
|
function normalizeValue(value) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
+
if (typeof value !== 'string') {
|
|
86
|
+
value = String(value);
|
|
87
|
+
}
|
|
88
|
+
return value;
|
|
85
89
|
}
|
|
90
|
+
// Build a destructive iterator for the value list
|
|
86
91
|
function iteratorFor(items) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
iterator[Symbol.iterator] = function () {
|
|
92
|
+
const iterator = {
|
|
93
|
+
next() {
|
|
94
|
+
const value = items.shift();
|
|
95
|
+
return { done: value === undefined, value };
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
iterator[Symbol.iterator] = function () {
|
|
99
|
+
return iterator;
|
|
100
|
+
};
|
|
97
101
|
return iterator;
|
|
98
|
-
};
|
|
99
|
-
return iterator;
|
|
100
102
|
}
|
|
101
|
-
//# sourceMappingURL=headers-polyfill.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response-polyfill.d.ts","sourceRoot":"","sources":["../../src/fetch/response-polyfill.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"response-polyfill.d.ts","sourceRoot":"","sources":["../../src/fetch/response-polyfill.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,OAAO,EAAC,8BAA2B;AAoB3C,qBAAa,QAAQ;IACnB,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,OAAO,CAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC;gBAIrB,IAAI,KAAA,EACJ,OAAO,EAAE;QACP,OAAO,CAAC,MAAC;QACT,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,GAAG,EAAE,MAAM,CAAC;KACb;IAuBH,IAAI,IAAI,QAKP;IAIK,WAAW;IAQX,IAAI;IAMJ,IAAI;IAKJ,IAAI;CAMX"}
|
|
@@ -1,66 +1,74 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
import { assert } from "../utils/assert.js";
|
|
2
5
|
import { decompressReadStream, concatenateReadStream } from "../filesystems/stream-utils.node.js";
|
|
3
6
|
import { Headers } from "./headers-polyfill.js";
|
|
4
|
-
const isBoolean = x => typeof x === 'boolean';
|
|
5
|
-
const isFunction = x => typeof x === 'function';
|
|
6
|
-
const isObject = x => x !== null && typeof x === 'object';
|
|
7
|
-
const isReadableNodeStream = x => isObject(x) && isFunction(x.read) && isFunction(x.pipe) && isBoolean(x.readable);
|
|
7
|
+
const isBoolean = (x) => typeof x === 'boolean';
|
|
8
|
+
const isFunction = (x) => typeof x === 'function';
|
|
9
|
+
const isObject = (x) => x !== null && typeof x === 'object';
|
|
10
|
+
const isReadableNodeStream = (x) => isObject(x) && isFunction(x.read) && isFunction(x.pipe) && isBoolean(x.readable);
|
|
11
|
+
/**
|
|
12
|
+
* Polyfill for Browser Response
|
|
13
|
+
*
|
|
14
|
+
* Under Node.js we return a mock "fetch response object"
|
|
15
|
+
* so that apps can use the same API as in the browser.
|
|
16
|
+
*
|
|
17
|
+
* Note: This is intended to be a "lightweight" implementation and will have limitations.
|
|
18
|
+
*
|
|
19
|
+
* See https://developer.mozilla.org/en-US/docs/Web/API/Response
|
|
20
|
+
*/
|
|
8
21
|
import * as stream from 'stream';
|
|
9
22
|
export class Response {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (isReadableNodeStream(body)) {
|
|
30
|
-
this._body = decompressReadStream(body, headers);
|
|
31
|
-
} else if (typeof body === 'string') {
|
|
32
|
-
this._body = stream.Readable.from([new TextEncoder().encode(body)]);
|
|
33
|
-
} else {
|
|
34
|
-
this._body = stream.Readable.from([body || new ArrayBuffer(0)]);
|
|
23
|
+
// TODO - handle ArrayBuffer, ArrayBufferView, Buffer
|
|
24
|
+
constructor(body, options) {
|
|
25
|
+
this.bodyUsed = false;
|
|
26
|
+
const { headers, status = 200, statusText = 'OK', url } = options || {};
|
|
27
|
+
this.url = url;
|
|
28
|
+
this.ok = status === 200;
|
|
29
|
+
this.status = status; // TODO - handle errors and set status
|
|
30
|
+
this.statusText = statusText;
|
|
31
|
+
this.headers = new Headers(options?.headers || {});
|
|
32
|
+
// Check for content-encoding and create a decompression stream
|
|
33
|
+
if (isReadableNodeStream(body)) {
|
|
34
|
+
this._body = decompressReadStream(body, headers);
|
|
35
|
+
}
|
|
36
|
+
else if (typeof body === 'string') {
|
|
37
|
+
this._body = stream.Readable.from([new TextEncoder().encode(body)]);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
this._body = stream.Readable.from([body || new ArrayBuffer(0)]);
|
|
41
|
+
}
|
|
35
42
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
async arrayBuffer() {
|
|
44
|
-
if (!isReadableNodeStream(this._body)) {
|
|
45
|
-
return this._body || new ArrayBuffer(0);
|
|
43
|
+
// Subset of Properties
|
|
44
|
+
// Returns a readable stream to the "body" of the response (or file)
|
|
45
|
+
get body() {
|
|
46
|
+
assert(!this.bodyUsed);
|
|
47
|
+
assert(isReadableNodeStream(this._body)); // Not implemented: conversion of ArrayBuffer etc to stream
|
|
48
|
+
this.bodyUsed = true;
|
|
49
|
+
return this._body;
|
|
46
50
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
51
|
+
// Subset of Methods
|
|
52
|
+
async arrayBuffer() {
|
|
53
|
+
if (!isReadableNodeStream(this._body)) {
|
|
54
|
+
return this._body || new ArrayBuffer(0);
|
|
55
|
+
}
|
|
56
|
+
const data = await concatenateReadStream(this._body);
|
|
57
|
+
return data;
|
|
58
|
+
}
|
|
59
|
+
async text() {
|
|
60
|
+
const arrayBuffer = await this.arrayBuffer();
|
|
61
|
+
const textDecoder = new TextDecoder();
|
|
62
|
+
return textDecoder.decode(arrayBuffer);
|
|
63
|
+
}
|
|
64
|
+
async json() {
|
|
65
|
+
const text = await this.text();
|
|
66
|
+
return JSON.parse(text);
|
|
67
|
+
}
|
|
68
|
+
async blob() {
|
|
69
|
+
if (typeof Blob === 'undefined') {
|
|
70
|
+
throw new Error('Blob polyfill not installed');
|
|
71
|
+
}
|
|
72
|
+
return new Blob([await this.arrayBuffer()]);
|
|
62
73
|
}
|
|
63
|
-
return new Blob([await this.arrayBuffer()]);
|
|
64
|
-
}
|
|
65
74
|
}
|
|
66
|
-
//# sourceMappingURL=response-polyfill.js.map
|
|
@@ -1,45 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
1
|
+
// Based on binary-gltf-utils under MIT license: Copyright (c) 2016-17 Karl Cheng
|
|
2
|
+
const isArrayBuffer = (x) => x && x instanceof ArrayBuffer;
|
|
3
|
+
const isBuffer = (x) => x && x instanceof Buffer;
|
|
4
|
+
/**
|
|
5
|
+
* Parses a data URI into a buffer, as well as retrieving its declared MIME type.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} uri - a data URI (assumed to be valid)
|
|
8
|
+
* @returns {Object} { buffer, mimeType }
|
|
9
|
+
*/
|
|
3
10
|
export function decodeDataUri(uri) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
mimeType
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
mimeType
|
|
22
|
-
};
|
|
11
|
+
const dataIndex = uri.indexOf(',');
|
|
12
|
+
let buffer;
|
|
13
|
+
let mimeType;
|
|
14
|
+
if (uri.slice(dataIndex - 7, dataIndex) === ';base64') {
|
|
15
|
+
buffer = Buffer.from(uri.slice(dataIndex + 1), 'base64');
|
|
16
|
+
mimeType = uri.slice(5, dataIndex - 7).trim();
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
buffer = Buffer.from(decodeURIComponent(uri.slice(dataIndex + 1)));
|
|
20
|
+
mimeType = uri.slice(5, dataIndex).trim();
|
|
21
|
+
}
|
|
22
|
+
if (!mimeType) {
|
|
23
|
+
mimeType = 'text/plain;charset=US-ASCII';
|
|
24
|
+
}
|
|
25
|
+
else if (mimeType.startsWith(';')) {
|
|
26
|
+
mimeType = `text/plain${mimeType}`;
|
|
27
|
+
}
|
|
28
|
+
return { arrayBuffer: toArrayBuffer(buffer), mimeType };
|
|
23
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* @param data
|
|
32
|
+
* @todo Duplicate of core
|
|
33
|
+
*/
|
|
24
34
|
export function toArrayBuffer(data) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
35
|
+
if (isArrayBuffer(data)) {
|
|
36
|
+
return data;
|
|
37
|
+
}
|
|
38
|
+
// TODO - per docs we should just be able to call buffer.buffer, but there are issues
|
|
39
|
+
if (isBuffer(data)) {
|
|
40
|
+
// @ts-expect-error
|
|
41
|
+
const typedArray = new Uint8Array(data);
|
|
42
|
+
return typedArray.buffer;
|
|
43
|
+
}
|
|
44
|
+
// Careful - Node Buffers will look like ArrayBuffers (keep after isBuffer)
|
|
45
|
+
if (ArrayBuffer.isView(data)) {
|
|
46
|
+
return data.buffer;
|
|
47
|
+
}
|
|
48
|
+
if (typeof data === 'string') {
|
|
49
|
+
const text = data;
|
|
50
|
+
const uint8Array = new TextEncoder().encode(text);
|
|
51
|
+
return uint8Array.buffer;
|
|
52
|
+
}
|
|
53
|
+
// HACK to support Blob polyfill
|
|
54
|
+
// @ts-expect-error
|
|
55
|
+
if (data && typeof data === 'object' && data._toArrayBuffer) {
|
|
56
|
+
// @ts-expect-error
|
|
57
|
+
return data._toArrayBuffer();
|
|
58
|
+
}
|
|
59
|
+
throw new Error(`toArrayBuffer(${JSON.stringify(data, null, 2).slice(10)})`);
|
|
44
60
|
}
|
|
45
|
-
//# sourceMappingURL=decode-data-uri.node.js.map
|
|
@@ -1,43 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Forked from @gozala's web-blob under MIT license
|
|
3
|
+
* @see https://github.com/Gozala/web-blob
|
|
4
|
+
*/
|
|
1
5
|
export class BlobStreamController {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
6
|
+
/**
|
|
7
|
+
* @param chunks
|
|
8
|
+
*/
|
|
9
|
+
constructor(chunks) {
|
|
10
|
+
this.isWorking = false;
|
|
11
|
+
this.isCancelled = false;
|
|
12
|
+
this.chunks = chunks;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* @param controller
|
|
16
|
+
*/
|
|
17
|
+
start(controller) {
|
|
18
|
+
this.work(controller); // eslint-disable-line @typescript-eslint/no-floating-promises
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* @param controller
|
|
23
|
+
*/
|
|
24
|
+
async work(controller) {
|
|
25
|
+
const { chunks } = this;
|
|
26
|
+
this.isWorking = true;
|
|
27
|
+
while (!this.isCancelled && (controller.desiredSize || 0) > 0) {
|
|
28
|
+
let next;
|
|
29
|
+
try {
|
|
30
|
+
next = chunks.next();
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
controller.error(error);
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
if (next) {
|
|
37
|
+
if (!next.done && !this.isCancelled) {
|
|
38
|
+
controller.enqueue(next.value);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
controller.close();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
this.isWorking = false;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
*
|
|
49
|
+
* @param {ReadableStreamDefaultController} controller
|
|
50
|
+
*/
|
|
51
|
+
pull(controller) {
|
|
52
|
+
if (!this.isWorking) {
|
|
53
|
+
this.work(controller); // eslint-disable-line @typescript-eslint/no-floating-promises
|
|
29
54
|
}
|
|
30
|
-
}
|
|
31
55
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
pull(controller) {
|
|
35
|
-
if (!this.isWorking) {
|
|
36
|
-
this.work(controller);
|
|
56
|
+
cancel() {
|
|
57
|
+
this.isCancelled = true;
|
|
37
58
|
}
|
|
38
|
-
}
|
|
39
|
-
cancel() {
|
|
40
|
-
this.isCancelled = true;
|
|
41
|
-
}
|
|
42
59
|
}
|
|
43
|
-
//# sourceMappingURL=blob-stream-controller.js.map
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Forked from @gozala's web-blob under MIT license
|
|
3
3
|
* @see https://github.com/Gozala/web-blob
|
|
4
4
|
*/
|
|
5
|
-
import { ReadableStreamPolyfill } from
|
|
5
|
+
import { ReadableStreamPolyfill } from "./readable-stream.js";
|
|
6
6
|
/**
|
|
7
7
|
* Blob stream is a `ReadableStream` extension optimized to have minimal
|
|
8
8
|
* overhead when consumed as `AsyncIterable<Uint8Array>`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blob-stream.d.ts","sourceRoot":"","sources":["../../src/file/blob-stream.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAC,sBAAsB,EAAC,
|
|
1
|
+
{"version":3,"file":"blob-stream.d.ts","sourceRoot":"","sources":["../../src/file/blob-stream.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAC,sBAAsB,EAAC,6BAA0B;AAGzD;;;;;GAKG;AAEH,qBAAa,UAAU,CAAC,CAAC,CAAE,SAAQ,sBAAsB,CAAC,CAAC,CAAC;IAC1D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAe;IACvC;;OAEG;gBACS,MAAM,KAAA;IAOlB;;OAEG;IAEI,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,QAAQ,CAAC,EAAE;QAAC,aAAa,CAAC,EAAE,OAAO,CAAA;KAAC,GAAG,aAAa,CAAC,UAAU,CAAC;CAK/F"}
|
package/dist/file/blob-stream.js
CHANGED
|
@@ -1,19 +1,33 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Forked from @gozala's web-blob under MIT license
|
|
3
|
+
* @see https://github.com/Gozala/web-blob
|
|
4
|
+
*/
|
|
2
5
|
import { ReadableStreamPolyfill } from "./readable-stream.js";
|
|
3
6
|
import { BlobStreamController } from "./blob-stream-controller.js";
|
|
4
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Blob stream is a `ReadableStream` extension optimized to have minimal
|
|
9
|
+
* overhead when consumed as `AsyncIterable<Uint8Array>`.
|
|
10
|
+
* extends {ReadableStream<Uint8Array>}
|
|
11
|
+
* implements {AsyncIterable<Uint8Array>}
|
|
12
|
+
*/
|
|
13
|
+
// @ts-ignore
|
|
5
14
|
export class BlobStream extends ReadableStreamPolyfill {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
/**
|
|
16
|
+
* @param chunks
|
|
17
|
+
*/
|
|
18
|
+
constructor(chunks) {
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
super(new BlobStreamController(chunks.values()), { type: 'bytes' });
|
|
21
|
+
/** @private */
|
|
22
|
+
this._chunks = chunks;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @property [_options.preventCancel]
|
|
26
|
+
*/
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
async *[Symbol.asyncIterator](_options) {
|
|
29
|
+
const reader = this.getReader();
|
|
30
|
+
yield* this._chunks;
|
|
31
|
+
reader.releaseLock();
|
|
32
|
+
}
|
|
18
33
|
}
|
|
19
|
-
//# sourceMappingURL=blob-stream.js.map
|
package/dist/file/blob.d.ts
CHANGED
package/dist/file/blob.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blob.d.ts","sourceRoot":"","sources":["../../src/file/blob.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,UAAU,EAAC,
|
|
1
|
+
{"version":3,"file":"blob.d.ts","sourceRoot":"","sources":["../../src/file/blob.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,UAAU,EAAC,yBAAsB;AAEzC;;;GAGG;AACH,qBAAa,YAAY;IAEvB,4FAA4F;IAC5F,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,oEAAoE;IACpE,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,KAAK,CAAe;IAC5B;;;OAGG;gBACS,IAAI,GAAE,QAAQ,EAAO,EAAE,OAAO,GAAE,eAAoB;IAmChE;;;;;;;;;;;;;;;;;;;OAmBG;IACH,KAAK,CAAC,KAAK,GAAE,MAAU,EAAE,GAAG,GAAE,MAAkB,EAAE,IAAI,GAAE,MAAW,GAAG,IAAI;IAyC1E;;;OAGG;IAEG,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC;IAIzC;;;OAGG;IAEG,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;IAS7B;OACG;IAEH,MAAM,IAAI,UAAU,CAAC,GAAG,CAAC;IAIzB;;OAEG;IACH,QAAQ;IAIR,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,WAEvB;IAED,cAAc,IAAI,WAAW;CAU9B"}
|