@loaders.gl/polyfills 4.2.0-alpha.4 → 4.2.0-alpha.6

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.
Files changed (93) hide show
  1. package/dist/buffer/btoa.node.js +5 -3
  2. package/dist/buffer/to-array-buffer.node.js +6 -6
  3. package/dist/crypto/node-hash.js +46 -45
  4. package/dist/fetch/decode-data-uri.js +56 -41
  5. package/dist/fetch/fetch-polyfill.d.ts +1 -1
  6. package/dist/fetch/fetch-polyfill.d.ts.map +1 -1
  7. package/dist/fetch/fetch-polyfill.js +118 -103
  8. package/dist/fetch/headers-polyfill.js +91 -89
  9. package/dist/fetch/response-polyfill.d.ts +1 -1
  10. package/dist/fetch/response-polyfill.d.ts.map +1 -1
  11. package/dist/fetch/response-polyfill.js +73 -57
  12. package/dist/fetch/utils/decode-data-uri.node.js +56 -41
  13. package/dist/file/blob-stream-controller.js +55 -38
  14. package/dist/file/blob-stream.d.ts +1 -1
  15. package/dist/file/blob-stream.d.ts.map +1 -1
  16. package/dist/file/blob-stream.js +30 -15
  17. package/dist/file/blob.d.ts +1 -1
  18. package/dist/file/blob.d.ts.map +1 -1
  19. package/dist/file/blob.js +152 -109
  20. package/dist/file/file-reader.js +38 -50
  21. package/dist/file/file.js +35 -15
  22. package/dist/file/install-blob-polyfills.js +6 -5
  23. package/dist/file/install-file-polyfills.d.ts +3 -2
  24. package/dist/file/install-file-polyfills.d.ts.map +1 -1
  25. package/dist/file/install-file-polyfills.js +11 -8
  26. package/dist/file/readable-stream.js +5 -2
  27. package/dist/filesystems/fetch-node.d.ts.map +1 -1
  28. package/dist/filesystems/fetch-node.js +80 -68
  29. package/dist/filesystems/node-file.d.ts.map +1 -1
  30. package/dist/filesystems/node-file.js +129 -87
  31. package/dist/filesystems/node-filesystem.d.ts +1 -1
  32. package/dist/filesystems/node-filesystem.d.ts.map +1 -1
  33. package/dist/filesystems/node-filesystem.js +39 -35
  34. package/dist/filesystems/stream-utils.node.js +88 -55
  35. package/dist/images/encode-image-node.js +25 -12
  36. package/dist/images/encode-image.node.js +25 -12
  37. package/dist/images/parse-image-node.js +30 -23
  38. package/dist/images/parse-image.node.js +30 -23
  39. package/dist/index.browser.js +8 -3
  40. package/dist/index.cjs +13 -65091
  41. package/dist/index.cjs.map +7 -0
  42. package/dist/index.d.ts +4 -4
  43. package/dist/index.d.ts.map +1 -1
  44. package/dist/index.js +46 -15
  45. package/dist/libs/encoding-indexes-asian.js +6 -7
  46. package/dist/load-library/require-utils.node.js +70 -44
  47. package/dist/streams/make-node-stream.d.ts.map +1 -1
  48. package/dist/streams/make-node-stream.js +52 -46
  49. package/dist/text-encoder/encoding-indexes.js +31 -28
  50. package/dist/text-encoder/text-encoder.js +2604 -1033
  51. package/dist/utils/assert.js +3 -4
  52. package/dist/utils/is-browser.js +7 -2
  53. package/package.json +13 -11
  54. package/src/fetch/response-polyfill.ts +2 -0
  55. package/src/filesystems/fetch-node.ts +2 -0
  56. package/src/filesystems/node-file.ts +4 -0
  57. package/src/filesystems/node-filesystem.ts +1 -0
  58. package/src/index.ts +1 -0
  59. package/src/load-library/require-utils.node.ts +1 -1
  60. package/src/streams/make-node-stream.ts +3 -2
  61. package/dist/buffer/btoa.node.js.map +0 -1
  62. package/dist/buffer/to-array-buffer.node.js.map +0 -1
  63. package/dist/crypto/node-hash.js.map +0 -1
  64. package/dist/dist.dev.js +0 -45
  65. package/dist/fetch/decode-data-uri.js.map +0 -1
  66. package/dist/fetch/fetch-polyfill.js.map +0 -1
  67. package/dist/fetch/headers-polyfill.js.map +0 -1
  68. package/dist/fetch/response-polyfill.js.map +0 -1
  69. package/dist/fetch/utils/decode-data-uri.node.js.map +0 -1
  70. package/dist/file/blob-stream-controller.js.map +0 -1
  71. package/dist/file/blob-stream.js.map +0 -1
  72. package/dist/file/blob.js.map +0 -1
  73. package/dist/file/file-reader.js.map +0 -1
  74. package/dist/file/file.js.map +0 -1
  75. package/dist/file/install-blob-polyfills.js.map +0 -1
  76. package/dist/file/install-file-polyfills.js.map +0 -1
  77. package/dist/file/readable-stream.js.map +0 -1
  78. package/dist/filesystems/fetch-node.js.map +0 -1
  79. package/dist/filesystems/node-file.js.map +0 -1
  80. package/dist/filesystems/node-filesystem.js.map +0 -1
  81. package/dist/filesystems/stream-utils.node.js.map +0 -1
  82. package/dist/images/encode-image-node.js.map +0 -1
  83. package/dist/images/encode-image.node.js.map +0 -1
  84. package/dist/images/parse-image-node.js.map +0 -1
  85. package/dist/images/parse-image.node.js.map +0 -1
  86. package/dist/index.browser.js.map +0 -1
  87. package/dist/index.js.map +0 -1
  88. package/dist/load-library/require-utils.node.js.map +0 -1
  89. package/dist/streams/make-node-stream.js.map +0 -1
  90. package/dist/text-encoder/encoding-indexes.js.map +0 -1
  91. package/dist/text-encoder/text-encoder.js.map +0 -1
  92. package/dist/utils/assert.js.map +0 -1
  93. package/dist/utils/is-browser.js.map +0 -1
@@ -1,101 +1,103 @@
1
- let _Symbol$iterator;
2
- _Symbol$iterator = Symbol.iterator;
1
+ /**
2
+ * Polyfill for Browser Headers
3
+ * Based on https://github.com/github/fetch under MIT license
4
+ */
3
5
  export class Headers {
4
- constructor(headers) {
5
- this.map = void 0;
6
- this.map = {};
7
- if (headers instanceof Headers) {
8
- headers.forEach((value, name) => this.append(name, value));
9
- } else if (Array.isArray(headers)) {
10
- headers.forEach(header => this.append(header[0], header[1]));
11
- } else if (headers) {
12
- Object.getOwnPropertyNames(headers).forEach(name => this.append(name, headers[name]));
6
+ map;
7
+ constructor(headers) {
8
+ this.map = {};
9
+ if (headers instanceof Headers) {
10
+ headers.forEach((value, name) => this.append(name, value));
11
+ }
12
+ else if (Array.isArray(headers)) {
13
+ headers.forEach((header) => this.append(header[0], header[1]));
14
+ }
15
+ else if (headers) {
16
+ Object.getOwnPropertyNames(headers).forEach((name) => this.append(name, headers[name]));
17
+ }
18
+ }
19
+ append(name, value) {
20
+ name = normalizeName(name);
21
+ value = normalizeValue(value);
22
+ const oldValue = this.map[name];
23
+ this.map[name] = oldValue ? `${oldValue}, ${value}` : value;
24
+ }
25
+ delete(name) {
26
+ delete this.map[normalizeName(name)];
13
27
  }
14
- }
15
- append(name, value) {
16
- name = normalizeName(name);
17
- value = normalizeValue(value);
18
- const oldValue = this.map[name];
19
- this.map[name] = oldValue ? `${oldValue}, ${value}` : value;
20
- }
21
- delete(name) {
22
- delete this.map[normalizeName(name)];
23
- }
24
- get(name) {
25
- name = normalizeName(name);
26
- return this.has(name) ? this.map[name] : null;
27
- }
28
- has(name) {
29
- return this.map.hasOwnProperty(normalizeName(name));
30
- }
31
- set(name, value) {
32
- this.map[normalizeName(name)] = normalizeValue(value);
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);
28
+ get(name) {
29
+ name = normalizeName(name);
30
+ return this.has(name) ? this.map[name] : null;
31
+ }
32
+ has(name) {
33
+ return this.map.hasOwnProperty(normalizeName(name));
34
+ }
35
+ set(name, value) {
36
+ this.map[normalizeName(name)] = normalizeValue(value);
37
+ }
38
+ forEach(visitor, thisArg = null) {
39
+ for (const name in this.map) {
40
+ if (this.map.hasOwnProperty(name)) {
41
+ if (thisArg) {
42
+ visitor.call(thisArg, this.map[name], name, this);
43
+ }
44
+ else {
45
+ visitor(this.map[name], name, this);
46
+ }
47
+ }
42
48
  }
43
- }
44
49
  }
45
- }
46
- keys() {
47
- const items = [];
48
- this.forEach(function (value, name) {
49
- items.push(name);
50
- });
51
- return iteratorFor(items);
52
- }
53
- values() {
54
- const items = [];
55
- this.forEach(function (value) {
56
- items.push(value);
57
- });
58
- return iteratorFor(items);
59
- }
60
- entries() {
61
- const items = [];
62
- this.forEach(function (value, name) {
63
- items.push([name, value]);
64
- });
65
- return iteratorFor(items);
66
- }
67
- *[_Symbol$iterator]() {
68
- yield* this.entries();
69
- }
50
+ keys() {
51
+ const items = [];
52
+ this.forEach(function (value, name) {
53
+ items.push(name);
54
+ });
55
+ return iteratorFor(items);
56
+ }
57
+ values() {
58
+ const items = [];
59
+ this.forEach(function (value) {
60
+ items.push(value);
61
+ });
62
+ return iteratorFor(items);
63
+ }
64
+ entries() {
65
+ const items = [];
66
+ this.forEach(function (value, name) {
67
+ items.push([name, value]);
68
+ });
69
+ return iteratorFor(items);
70
+ }
71
+ *[Symbol.iterator]() {
72
+ // @ts-ignore must have a '[Symbol.iterator]()' method that returns an iterator.
73
+ yield* this.entries();
74
+ }
70
75
  }
71
76
  function normalizeName(name) {
72
- if (typeof name !== 'string') {
73
- name = String(name);
74
- }
75
- if (/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(name) || name === '') {
76
- throw new TypeError('Invalid character in header field name');
77
- }
78
- return name.toLowerCase();
77
+ if (typeof name !== 'string') {
78
+ name = String(name);
79
+ }
80
+ if (/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(name) || name === '') {
81
+ throw new TypeError('Invalid character in header field name');
82
+ }
83
+ return name.toLowerCase();
79
84
  }
80
85
  function normalizeValue(value) {
81
- if (typeof value !== 'string') {
82
- value = String(value);
83
- }
84
- return value;
86
+ if (typeof value !== 'string') {
87
+ value = String(value);
88
+ }
89
+ return value;
85
90
  }
91
+ // Build a destructive iterator for the value list
86
92
  function iteratorFor(items) {
87
- const iterator = {
88
- next() {
89
- const value = items.shift();
90
- return {
91
- done: value === undefined,
92
- value
93
- };
94
- }
95
- };
96
- iterator[Symbol.iterator] = function () {
93
+ const iterator = {
94
+ next() {
95
+ const value = items.shift();
96
+ return { done: value === undefined, value };
97
+ }
98
+ };
99
+ iterator[Symbol.iterator] = function () {
100
+ return iterator;
101
+ };
97
102
  return iterator;
98
- };
99
- return iterator;
100
103
  }
101
- //# sourceMappingURL=headers-polyfill.js.map
@@ -1,4 +1,4 @@
1
- import { Headers } from './headers-polyfill';
1
+ import { Headers } from "./headers-polyfill.js";
2
2
  export declare class Response {
3
3
  readonly ok: boolean;
4
4
  readonly status: number;
@@ -1 +1 @@
1
- {"version":3,"file":"response-polyfill.d.ts","sourceRoot":"","sources":["../../src/fetch/response-polyfill.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,OAAO,EAAC,MAAM,oBAAoB,CAAC;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
+ {"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;IAyBH,IAAI,IAAI,QAKP;IAIK,WAAW;IAQX,IAAI;IAMJ,IAAI;IAKJ,IAAI;CAMX"}
@@ -1,66 +1,82 @@
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
- constructor(body, options) {
11
- this.ok = void 0;
12
- this.status = void 0;
13
- this.statusText = void 0;
14
- this.headers = void 0;
15
- this.url = void 0;
16
- this.bodyUsed = false;
17
- this._body = void 0;
18
- const {
19
- headers,
20
- status = 200,
21
- statusText = 'OK',
22
- url
23
- } = options || {};
24
- this.url = url;
25
- this.ok = status === 200;
26
- this.status = status;
27
- this.statusText = statusText;
28
- this.headers = new Headers((options === null || options === void 0 ? void 0 : options.headers) || {});
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
+ ok;
24
+ status;
25
+ statusText;
26
+ headers;
27
+ url;
28
+ bodyUsed = false;
29
+ _body;
30
+ // TODO - handle ArrayBuffer, ArrayBufferView, Buffer
31
+ constructor(body, options) {
32
+ const { headers, status = 200, statusText = 'OK', url } = options || {};
33
+ this.url = url;
34
+ this.ok = status === 200;
35
+ this.status = status; // TODO - handle errors and set status
36
+ this.statusText = statusText;
37
+ this.headers = new Headers(options?.headers || {});
38
+ // Check for content-encoding and create a decompression stream
39
+ if (isReadableNodeStream(body)) {
40
+ this._body = decompressReadStream(body, headers);
41
+ }
42
+ else if (typeof body === 'string') {
43
+ // @ts-expect-error
44
+ this._body = stream.Readable.from([new TextEncoder().encode(body)]);
45
+ }
46
+ else {
47
+ // @ts-expect-error
48
+ this._body = stream.Readable.from([body || new ArrayBuffer(0)]);
49
+ }
35
50
  }
36
- }
37
- get body() {
38
- assert(!this.bodyUsed);
39
- assert(isReadableNodeStream(this._body));
40
- this.bodyUsed = true;
41
- return this._body;
42
- }
43
- async arrayBuffer() {
44
- if (!isReadableNodeStream(this._body)) {
45
- return this._body || new ArrayBuffer(0);
51
+ // Subset of Properties
52
+ // Returns a readable stream to the "body" of the response (or file)
53
+ get body() {
54
+ assert(!this.bodyUsed);
55
+ assert(isReadableNodeStream(this._body)); // Not implemented: conversion of ArrayBuffer etc to stream
56
+ this.bodyUsed = true;
57
+ return this._body;
46
58
  }
47
- const data = await concatenateReadStream(this._body);
48
- return data;
49
- }
50
- async text() {
51
- const arrayBuffer = await this.arrayBuffer();
52
- const textDecoder = new TextDecoder();
53
- return textDecoder.decode(arrayBuffer);
54
- }
55
- async json() {
56
- const text = await this.text();
57
- return JSON.parse(text);
58
- }
59
- async blob() {
60
- if (typeof Blob === 'undefined') {
61
- throw new Error('Blob polyfill not installed');
59
+ // Subset of Methods
60
+ async arrayBuffer() {
61
+ if (!isReadableNodeStream(this._body)) {
62
+ return this._body || new ArrayBuffer(0);
63
+ }
64
+ const data = await concatenateReadStream(this._body);
65
+ return data;
66
+ }
67
+ async text() {
68
+ const arrayBuffer = await this.arrayBuffer();
69
+ const textDecoder = new TextDecoder();
70
+ return textDecoder.decode(arrayBuffer);
71
+ }
72
+ async json() {
73
+ const text = await this.text();
74
+ return JSON.parse(text);
75
+ }
76
+ async blob() {
77
+ if (typeof Blob === 'undefined') {
78
+ throw new Error('Blob polyfill not installed');
79
+ }
80
+ return new Blob([await this.arrayBuffer()]);
62
81
  }
63
- return new Blob([await this.arrayBuffer()]);
64
- }
65
82
  }
66
- //# sourceMappingURL=response-polyfill.js.map
@@ -1,45 +1,60 @@
1
- const isArrayBuffer = x => x && x instanceof ArrayBuffer;
2
- const isBuffer = x => x && x instanceof Buffer;
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
- const dataIndex = uri.indexOf(',');
5
- let buffer;
6
- let mimeType;
7
- if (uri.slice(dataIndex - 7, dataIndex) === ';base64') {
8
- buffer = Buffer.from(uri.slice(dataIndex + 1), 'base64');
9
- mimeType = uri.slice(5, dataIndex - 7).trim();
10
- } else {
11
- buffer = Buffer.from(decodeURIComponent(uri.slice(dataIndex + 1)));
12
- mimeType = uri.slice(5, dataIndex).trim();
13
- }
14
- if (!mimeType) {
15
- mimeType = 'text/plain;charset=US-ASCII';
16
- } else if (mimeType.startsWith(';')) {
17
- mimeType = `text/plain${mimeType}`;
18
- }
19
- return {
20
- arrayBuffer: toArrayBuffer(buffer),
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
- if (isArrayBuffer(data)) {
26
- return data;
27
- }
28
- if (isBuffer(data)) {
29
- const typedArray = new Uint8Array(data);
30
- return typedArray.buffer;
31
- }
32
- if (ArrayBuffer.isView(data)) {
33
- return data.buffer;
34
- }
35
- if (typeof data === 'string') {
36
- const text = data;
37
- const uint8Array = new TextEncoder().encode(text);
38
- return uint8Array.buffer;
39
- }
40
- if (data && typeof data === 'object' && data._toArrayBuffer) {
41
- return data._toArrayBuffer();
42
- }
43
- throw new Error(`toArrayBuffer(${JSON.stringify(data, null, 2).slice(10)})`);
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,60 @@
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
- constructor(chunks) {
3
- this.chunks = void 0;
4
- this.isWorking = false;
5
- this.isCancelled = false;
6
- this.chunks = chunks;
7
- }
8
- start(controller) {
9
- this.work(controller);
10
- }
11
- async work(controller) {
12
- const {
13
- chunks
14
- } = this;
15
- this.isWorking = true;
16
- while (!this.isCancelled && (controller.desiredSize || 0) > 0) {
17
- let next;
18
- try {
19
- next = chunks.next();
20
- } catch (error) {
21
- controller.error(error);
22
- break;
23
- }
24
- if (next) {
25
- if (!next.done && !this.isCancelled) {
26
- controller.enqueue(next.value);
27
- } else {
28
- controller.close();
6
+ chunks;
7
+ isWorking = false;
8
+ isCancelled = false;
9
+ /**
10
+ * @param chunks
11
+ */
12
+ constructor(chunks) {
13
+ this.chunks = chunks;
14
+ }
15
+ /**
16
+ * @param controller
17
+ */
18
+ start(controller) {
19
+ this.work(controller); // eslint-disable-line @typescript-eslint/no-floating-promises
20
+ }
21
+ /**
22
+ *
23
+ * @param controller
24
+ */
25
+ async work(controller) {
26
+ const { chunks } = this;
27
+ this.isWorking = true;
28
+ while (!this.isCancelled && (controller.desiredSize || 0) > 0) {
29
+ let next;
30
+ try {
31
+ next = chunks.next();
32
+ }
33
+ catch (error) {
34
+ controller.error(error);
35
+ break;
36
+ }
37
+ if (next) {
38
+ if (!next.done && !this.isCancelled) {
39
+ controller.enqueue(next.value);
40
+ }
41
+ else {
42
+ controller.close();
43
+ }
44
+ }
45
+ }
46
+ this.isWorking = false;
47
+ }
48
+ /**
49
+ *
50
+ * @param {ReadableStreamDefaultController} controller
51
+ */
52
+ pull(controller) {
53
+ if (!this.isWorking) {
54
+ this.work(controller); // eslint-disable-line @typescript-eslint/no-floating-promises
29
55
  }
30
- }
31
56
  }
32
- this.isWorking = false;
33
- }
34
- pull(controller) {
35
- if (!this.isWorking) {
36
- this.work(controller);
57
+ cancel() {
58
+ this.isCancelled = true;
37
59
  }
38
- }
39
- cancel() {
40
- this.isCancelled = true;
41
- }
42
60
  }
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 './readable-stream';
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,MAAM,mBAAmB,CAAC;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"}
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"}
@@ -1,19 +1,34 @@
1
- let _Symbol$asyncIterator;
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
- _Symbol$asyncIterator = Symbol.asyncIterator;
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
- constructor(chunks) {
7
- super(new BlobStreamController(chunks.values()), {
8
- type: 'bytes'
9
- });
10
- this._chunks = void 0;
11
- this._chunks = chunks;
12
- }
13
- async *[_Symbol$asyncIterator](_options) {
14
- const reader = this.getReader();
15
- yield* this._chunks;
16
- reader.releaseLock();
17
- }
15
+ _chunks;
16
+ /**
17
+ * @param chunks
18
+ */
19
+ constructor(chunks) {
20
+ // @ts-ignore
21
+ super(new BlobStreamController(chunks.values()), { type: 'bytes' });
22
+ /** @private */
23
+ this._chunks = chunks;
24
+ }
25
+ /**
26
+ * @property [_options.preventCancel]
27
+ */
28
+ // @ts-ignore
29
+ async *[Symbol.asyncIterator](_options) {
30
+ const reader = this.getReader();
31
+ yield* this._chunks;
32
+ reader.releaseLock();
33
+ }
18
34
  }
19
- //# sourceMappingURL=blob-stream.js.map
@@ -1,4 +1,4 @@
1
- import { BlobStream } from './blob-stream';
1
+ import { BlobStream } from "./blob-stream.js";
2
2
  /**
3
3
  * Forked from @gozala's web-blob under MIT license
4
4
  * @see https://github.com/Gozala/web-blob
@@ -1 +1 @@
1
- {"version":3,"file":"blob.d.ts","sourceRoot":"","sources":["../../src/file/blob.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;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"}
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"}