@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.
Files changed (81) 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 +41 -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 +90 -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 +65 -57
  12. package/dist/fetch/utils/decode-data-uri.node.js +56 -41
  13. package/dist/file/blob-stream-controller.js +54 -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 +29 -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 +146 -109
  20. package/dist/file/file-reader.js +22 -50
  21. package/dist/file/file.js +30 -15
  22. package/dist/file/install-blob-polyfills.js +6 -5
  23. package/dist/file/install-file-polyfills.js +11 -8
  24. package/dist/file/readable-stream.js +5 -2
  25. package/dist/filesystems/fetch-node.js +78 -68
  26. package/dist/filesystems/node-file.js +119 -87
  27. package/dist/filesystems/node-filesystem.d.ts +1 -1
  28. package/dist/filesystems/node-filesystem.d.ts.map +1 -1
  29. package/dist/filesystems/node-filesystem.js +39 -35
  30. package/dist/filesystems/stream-utils.node.js +88 -55
  31. package/dist/images/encode-image-node.js +25 -12
  32. package/dist/images/encode-image.node.js +25 -12
  33. package/dist/images/parse-image-node.js +30 -23
  34. package/dist/images/parse-image.node.js +30 -23
  35. package/dist/index.browser.js +8 -3
  36. package/dist/index.cjs +13 -65091
  37. package/dist/index.cjs.map +7 -0
  38. package/dist/index.d.ts +4 -4
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +45 -15
  41. package/dist/libs/encoding-indexes-asian.js +6 -7
  42. package/dist/load-library/require-utils.node.js +70 -44
  43. package/dist/streams/make-node-stream.js +48 -46
  44. package/dist/text-encoder/encoding-indexes.js +31 -28
  45. package/dist/text-encoder/text-encoder.js +2604 -1033
  46. package/dist/utils/assert.js +3 -4
  47. package/dist/utils/is-browser.js +7 -2
  48. package/package.json +10 -8
  49. package/dist/buffer/btoa.node.js.map +0 -1
  50. package/dist/buffer/to-array-buffer.node.js.map +0 -1
  51. package/dist/crypto/node-hash.js.map +0 -1
  52. package/dist/dist.dev.js +0 -45
  53. package/dist/fetch/decode-data-uri.js.map +0 -1
  54. package/dist/fetch/fetch-polyfill.js.map +0 -1
  55. package/dist/fetch/headers-polyfill.js.map +0 -1
  56. package/dist/fetch/response-polyfill.js.map +0 -1
  57. package/dist/fetch/utils/decode-data-uri.node.js.map +0 -1
  58. package/dist/file/blob-stream-controller.js.map +0 -1
  59. package/dist/file/blob-stream.js.map +0 -1
  60. package/dist/file/blob.js.map +0 -1
  61. package/dist/file/file-reader.js.map +0 -1
  62. package/dist/file/file.js.map +0 -1
  63. package/dist/file/install-blob-polyfills.js.map +0 -1
  64. package/dist/file/install-file-polyfills.js.map +0 -1
  65. package/dist/file/readable-stream.js.map +0 -1
  66. package/dist/filesystems/fetch-node.js.map +0 -1
  67. package/dist/filesystems/node-file.js.map +0 -1
  68. package/dist/filesystems/node-filesystem.js.map +0 -1
  69. package/dist/filesystems/stream-utils.node.js.map +0 -1
  70. package/dist/images/encode-image-node.js.map +0 -1
  71. package/dist/images/encode-image.node.js.map +0 -1
  72. package/dist/images/parse-image-node.js.map +0 -1
  73. package/dist/images/parse-image.node.js.map +0 -1
  74. package/dist/index.browser.js.map +0 -1
  75. package/dist/index.js.map +0 -1
  76. package/dist/load-library/require-utils.node.js.map +0 -1
  77. package/dist/streams/make-node-stream.js.map +0 -1
  78. package/dist/text-encoder/encoding-indexes.js.map +0 -1
  79. package/dist/text-encoder/text-encoder.js.map +0 -1
  80. package/dist/utils/assert.js.map +0 -1
  81. package/dist/utils/is-browser.js.map +0 -1
@@ -1,101 +1,102 @@
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
+ 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
- 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);
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
- 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
- }
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
- 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();
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
- if (typeof value !== 'string') {
82
- value = String(value);
83
- }
84
- return value;
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
- 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 () {
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,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;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
- 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
+ // 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
- 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);
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
- 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');
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
- 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,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
- 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
+ /**
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
- this.isWorking = false;
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 './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,33 @@
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
+ /**
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
@@ -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"}