@loaders.gl/polyfills 3.1.3 → 4.0.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 (142) hide show
  1. package/dist/bundle.js +2 -2
  2. package/dist/bundle.js.map +1 -0
  3. package/dist/index.js +49 -84
  4. package/dist/index.js.map +1 -0
  5. package/dist/lib/encoding-indexes.js +29 -34
  6. package/dist/lib/encoding-indexes.js.map +1 -0
  7. package/dist/lib/encoding.js +1281 -2610
  8. package/dist/lib/encoding.js.map +1 -0
  9. package/dist/libs/encoding-indexes-asian.js +8 -9
  10. package/dist/node/buffer/btoa.node.js +5 -12
  11. package/dist/node/buffer/btoa.node.js.map +1 -0
  12. package/dist/node/buffer/to-array-buffer.node.js +8 -11
  13. package/dist/node/buffer/to-array-buffer.node.js.map +1 -0
  14. package/dist/node/fetch/fetch.node.js +112 -103
  15. package/dist/node/fetch/fetch.node.js.map +1 -0
  16. package/dist/node/fetch/headers.node.js +114 -94
  17. package/dist/node/fetch/headers.node.js.map +1 -0
  18. package/dist/node/fetch/response.node.js +84 -73
  19. package/dist/node/fetch/response.node.js.map +1 -0
  20. package/dist/node/fetch/utils/decode-data-uri.node.js +53 -63
  21. package/dist/node/fetch/utils/decode-data-uri.node.js.map +1 -0
  22. package/dist/node/fetch/utils/stream-utils.node.js +87 -105
  23. package/dist/node/fetch/utils/stream-utils.node.js.map +1 -0
  24. package/dist/node/file/blob-stream-controller.js +52 -59
  25. package/dist/node/file/blob-stream-controller.js.map +1 -0
  26. package/dist/node/file/blob-stream.js +25 -36
  27. package/dist/node/file/blob-stream.js.map +1 -0
  28. package/dist/node/file/blob.js +131 -151
  29. package/dist/node/file/blob.js.map +1 -0
  30. package/dist/node/file/file-reader.js +77 -28
  31. package/dist/node/file/file-reader.js.map +1 -0
  32. package/dist/node/file/file.js +25 -36
  33. package/dist/node/file/file.js.map +1 -0
  34. package/dist/node/file/install-file-polyfills.js +21 -26
  35. package/dist/node/file/install-file-polyfills.js.map +1 -0
  36. package/dist/node/file/readable-stream.js +3 -10
  37. package/dist/node/file/readable-stream.js.map +1 -0
  38. package/dist/node/images/encode-image.node.js +17 -38
  39. package/dist/node/images/encode-image.node.js.map +1 -0
  40. package/dist/node/images/parse-image.node.js +19 -28
  41. package/dist/node/images/parse-image.node.js.map +1 -0
  42. package/dist/promise/all-settled.js +17 -22
  43. package/dist/promise/all-settled.js.map +1 -0
  44. package/dist/utils/assert.js +5 -8
  45. package/dist/utils/assert.js.map +1 -0
  46. package/dist/utils/globals.js +7 -34
  47. package/dist/utils/globals.js.map +1 -0
  48. package/package.json +4 -4
  49. package/dist/es5/bundle.js +0 -7
  50. package/dist/es5/bundle.js.map +0 -1
  51. package/dist/es5/index.js +0 -122
  52. package/dist/es5/index.js.map +0 -1
  53. package/dist/es5/lib/encoding-indexes.js +0 -37
  54. package/dist/es5/lib/encoding-indexes.js.map +0 -1
  55. package/dist/es5/lib/encoding.js +0 -1465
  56. package/dist/es5/lib/encoding.js.map +0 -1
  57. package/dist/es5/libs/encoding-indexes-asian.js +0 -13
  58. package/dist/es5/node/buffer/btoa.node.js +0 -16
  59. package/dist/es5/node/buffer/btoa.node.js.map +0 -1
  60. package/dist/es5/node/buffer/to-array-buffer.node.js +0 -16
  61. package/dist/es5/node/buffer/to-array-buffer.node.js.map +0 -1
  62. package/dist/es5/node/fetch/fetch.node.js +0 -183
  63. package/dist/es5/node/fetch/fetch.node.js.map +0 -1
  64. package/dist/es5/node/fetch/headers.node.js +0 -175
  65. package/dist/es5/node/fetch/headers.node.js.map +0 -1
  66. package/dist/es5/node/fetch/response.node.js +0 -231
  67. package/dist/es5/node/fetch/response.node.js.map +0 -1
  68. package/dist/es5/node/fetch/utils/decode-data-uri.node.js +0 -72
  69. package/dist/es5/node/fetch/utils/decode-data-uri.node.js.map +0 -1
  70. package/dist/es5/node/fetch/utils/stream-utils.node.js +0 -213
  71. package/dist/es5/node/fetch/utils/stream-utils.node.js.map +0 -1
  72. package/dist/es5/node/file/blob-stream-controller.js +0 -110
  73. package/dist/es5/node/file/blob-stream-controller.js.map +0 -1
  74. package/dist/es5/node/file/blob-stream.js +0 -93
  75. package/dist/es5/node/file/blob-stream.js.map +0 -1
  76. package/dist/es5/node/file/blob.js +0 -259
  77. package/dist/es5/node/file/blob.js.map +0 -1
  78. package/dist/es5/node/file/file-reader.js +0 -189
  79. package/dist/es5/node/file/file-reader.js.map +0 -1
  80. package/dist/es5/node/file/file.js +0 -63
  81. package/dist/es5/node/file/file.js.map +0 -1
  82. package/dist/es5/node/file/install-file-polyfills.js +0 -33
  83. package/dist/es5/node/file/install-file-polyfills.js.map +0 -1
  84. package/dist/es5/node/file/readable-stream.js +0 -40
  85. package/dist/es5/node/file/readable-stream.js.map +0 -1
  86. package/dist/es5/node/images/encode-image.node.js +0 -36
  87. package/dist/es5/node/images/encode-image.node.js.map +0 -1
  88. package/dist/es5/node/images/parse-image.node.js +0 -61
  89. package/dist/es5/node/images/parse-image.node.js.map +0 -1
  90. package/dist/es5/promise/all-settled.js +0 -29
  91. package/dist/es5/promise/all-settled.js.map +0 -1
  92. package/dist/es5/utils/assert.js +0 -13
  93. package/dist/es5/utils/assert.js.map +0 -1
  94. package/dist/es5/utils/globals.js +0 -21
  95. package/dist/es5/utils/globals.js.map +0 -1
  96. package/dist/esm/bundle.js +0 -5
  97. package/dist/esm/bundle.js.map +0 -1
  98. package/dist/esm/index.js +0 -63
  99. package/dist/esm/index.js.map +0 -1
  100. package/dist/esm/lib/encoding-indexes.js +0 -30
  101. package/dist/esm/lib/encoding-indexes.js.map +0 -1
  102. package/dist/esm/lib/encoding.js +0 -1450
  103. package/dist/esm/lib/encoding.js.map +0 -1
  104. package/dist/esm/libs/encoding-indexes-asian.js +0 -13
  105. package/dist/esm/node/buffer/btoa.node.js +0 -7
  106. package/dist/esm/node/buffer/btoa.node.js.map +0 -1
  107. package/dist/esm/node/buffer/to-array-buffer.node.js +0 -9
  108. package/dist/esm/node/buffer/to-array-buffer.node.js.map +0 -1
  109. package/dist/esm/node/fetch/fetch.node.js +0 -126
  110. package/dist/esm/node/fetch/fetch.node.js.map +0 -1
  111. package/dist/esm/node/fetch/headers.node.js +0 -125
  112. package/dist/esm/node/fetch/headers.node.js.map +0 -1
  113. package/dist/esm/node/fetch/response.node.js +0 -88
  114. package/dist/esm/node/fetch/response.node.js.map +0 -1
  115. package/dist/esm/node/fetch/utils/decode-data-uri.node.js +0 -55
  116. package/dist/esm/node/fetch/utils/decode-data-uri.node.js.map +0 -1
  117. package/dist/esm/node/fetch/utils/stream-utils.node.js +0 -98
  118. package/dist/esm/node/fetch/utils/stream-utils.node.js.map +0 -1
  119. package/dist/esm/node/file/blob-stream-controller.js +0 -56
  120. package/dist/esm/node/file/blob-stream-controller.js.map +0 -1
  121. package/dist/esm/node/file/blob-stream.js +0 -26
  122. package/dist/esm/node/file/blob-stream.js.map +0 -1
  123. package/dist/esm/node/file/blob.js +0 -140
  124. package/dist/esm/node/file/blob.js.map +0 -1
  125. package/dist/esm/node/file/file-reader.js +0 -84
  126. package/dist/esm/node/file/file-reader.js.map +0 -1
  127. package/dist/esm/node/file/file.js +0 -26
  128. package/dist/esm/node/file/file.js.map +0 -1
  129. package/dist/esm/node/file/install-file-polyfills.js +0 -22
  130. package/dist/esm/node/file/install-file-polyfills.js.map +0 -1
  131. package/dist/esm/node/file/readable-stream.js +0 -4
  132. package/dist/esm/node/file/readable-stream.js.map +0 -1
  133. package/dist/esm/node/images/encode-image.node.js +0 -20
  134. package/dist/esm/node/images/encode-image.node.js.map +0 -1
  135. package/dist/esm/node/images/parse-image.node.js +0 -20
  136. package/dist/esm/node/images/parse-image.node.js.map +0 -1
  137. package/dist/esm/promise/all-settled.js +0 -19
  138. package/dist/esm/promise/all-settled.js.map +0 -1
  139. package/dist/esm/utils/assert.js +0 -6
  140. package/dist/esm/utils/assert.js.map +0 -1
  141. package/dist/esm/utils/globals.js +0 -9
  142. package/dist/esm/utils/globals.js.map +0 -1
@@ -1,63 +1,56 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BlobStreamController = void 0;
4
- /**
5
- * Forked from @gozala's web-blob under MIT license
6
- * @see https://github.com/Gozala/web-blob
7
- */
8
- class BlobStreamController {
9
- /**
10
- * @param chunks
11
- */
12
- constructor(chunks) {
13
- this.isWorking = false;
14
- this.isCancelled = false;
15
- this.chunks = chunks;
16
- }
17
- /**
18
- * @param controller
19
- */
20
- start(controller) {
21
- this.work(controller); // eslint-disable-line @typescript-eslint/no-floating-promises
22
- }
23
- /**
24
- *
25
- * @param controller
26
- */
27
- async work(controller) {
28
- const { chunks } = this;
29
- this.isWorking = true;
30
- while (!this.isCancelled && (controller.desiredSize || 0) > 0) {
31
- let next;
32
- try {
33
- next = chunks.next();
34
- }
35
- catch (error) {
36
- controller.error(error);
37
- break;
38
- }
39
- if (next) {
40
- if (!next.done && !this.isCancelled) {
41
- controller.enqueue(next.value);
42
- }
43
- else {
44
- controller.close();
45
- }
46
- }
47
- }
48
- this.isWorking = false;
49
- }
50
- /**
51
- *
52
- * @param {ReadableStreamDefaultController} controller
53
- */
54
- pull(controller) {
55
- if (!this.isWorking) {
56
- this.work(controller); // eslint-disable-line @typescript-eslint/no-floating-promises
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ export class BlobStreamController {
3
+ constructor(chunks) {
4
+ _defineProperty(this, "chunks", void 0);
5
+
6
+ _defineProperty(this, "isWorking", false);
7
+
8
+ _defineProperty(this, "isCancelled", false);
9
+
10
+ this.chunks = chunks;
11
+ }
12
+
13
+ start(controller) {
14
+ this.work(controller);
15
+ }
16
+
17
+ async work(controller) {
18
+ const {
19
+ chunks
20
+ } = this;
21
+ this.isWorking = true;
22
+
23
+ while (!this.isCancelled && (controller.desiredSize || 0) > 0) {
24
+ let next;
25
+
26
+ try {
27
+ next = chunks.next();
28
+ } catch (error) {
29
+ controller.error(error);
30
+ break;
31
+ }
32
+
33
+ if (next) {
34
+ if (!next.done && !this.isCancelled) {
35
+ controller.enqueue(next.value);
36
+ } else {
37
+ controller.close();
57
38
  }
39
+ }
58
40
  }
59
- cancel() {
60
- this.isCancelled = true;
41
+
42
+ this.isWorking = false;
43
+ }
44
+
45
+ pull(controller) {
46
+ if (!this.isWorking) {
47
+ this.work(controller);
61
48
  }
49
+ }
50
+
51
+ cancel() {
52
+ this.isCancelled = true;
53
+ }
54
+
62
55
  }
63
- exports.BlobStreamController = BlobStreamController;
56
+ //# sourceMappingURL=blob-stream-controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/node/file/blob-stream-controller.ts"],"names":["BlobStreamController","constructor","chunks","start","controller","work","isWorking","isCancelled","desiredSize","next","error","done","enqueue","value","close","pull","cancel"],"mappings":";AAIA,OAAO,MAAMA,oBAAN,CAA2B;AAQhCC,EAAAA,WAAW,CAACC,MAAD,EAA+B;AAAA;;AAAA,uCANb,KAMa;;AAAA,yCALX,KAKW;;AACxC,SAAKA,MAAL,GAAcA,MAAd;AACD;;AAKDC,EAAAA,KAAK,CAACC,UAAD,EAA8C;AACjD,SAAKC,IAAL,CAAUD,UAAV;AACD;;AAMS,QAAJC,IAAI,CAACD,UAAD,EAA8C;AACtD,UAAM;AAACF,MAAAA;AAAD,QAAW,IAAjB;AAEA,SAAKI,SAAL,GAAiB,IAAjB;;AACA,WAAO,CAAC,KAAKC,WAAN,IAAqB,CAACH,UAAU,CAACI,WAAX,IAA0B,CAA3B,IAAgC,CAA5D,EAA+D;AAC7D,UAAIC,IAAJ;;AACA,UAAI;AACFA,QAAAA,IAAI,GAAGP,MAAM,CAACO,IAAP,EAAP;AACD,OAFD,CAEE,OAAOC,KAAP,EAAc;AACdN,QAAAA,UAAU,CAACM,KAAX,CAAiBA,KAAjB;AACA;AACD;;AAED,UAAID,IAAJ,EAAU;AACR,YAAI,CAACA,IAAI,CAACE,IAAN,IAAc,CAAC,KAAKJ,WAAxB,EAAqC;AACnCH,UAAAA,UAAU,CAACQ,OAAX,CAAmBH,IAAI,CAACI,KAAxB;AACD,SAFD,MAEO;AACLT,UAAAA,UAAU,CAACU,KAAX;AACD;AACF;AACF;;AAED,SAAKR,SAAL,GAAiB,KAAjB;AACD;;AAMDS,EAAAA,IAAI,CAACX,UAAD,EAAa;AACf,QAAI,CAAC,KAAKE,SAAV,EAAqB;AACnB,WAAKD,IAAL,CAAUD,UAAV;AACD;AACF;;AACDY,EAAAA,MAAM,GAAG;AACP,SAAKT,WAAL,GAAmB,IAAnB;AACD;;AA3D+B","sourcesContent":["/**\n * Forked from @gozala's web-blob under MIT license\n * @see https://github.com/Gozala/web-blob\n */\nexport class BlobStreamController {\n private chunks: Iterator<Uint8Array>;\n private isWorking: boolean = false;\n private isCancelled: boolean = false;\n\n /**\n * @param chunks\n */\n constructor(chunks: Iterator<Uint8Array>) {\n this.chunks = chunks;\n }\n\n /**\n * @param controller\n */\n start(controller: ReadableStreamDefaultController) {\n this.work(controller); // eslint-disable-line @typescript-eslint/no-floating-promises\n }\n\n /**\n *\n * @param controller\n */\n async work(controller: ReadableStreamDefaultController) {\n const {chunks} = this;\n\n this.isWorking = true;\n while (!this.isCancelled && (controller.desiredSize || 0) > 0) {\n let next: {done?: boolean; value?: Uint8Array} | undefined;\n try {\n next = chunks.next();\n } catch (error) {\n controller.error(error);\n break;\n }\n\n if (next) {\n if (!next.done && !this.isCancelled) {\n controller.enqueue(next.value);\n } else {\n controller.close();\n }\n }\n }\n\n this.isWorking = false;\n }\n\n /**\n *\n * @param {ReadableStreamDefaultController} controller\n */\n pull(controller) {\n if (!this.isWorking) {\n this.work(controller); // eslint-disable-line @typescript-eslint/no-floating-promises\n }\n }\n cancel() {\n this.isCancelled = true;\n }\n}\n"],"file":"blob-stream-controller.js"}
@@ -1,37 +1,26 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BlobStream = void 0;
4
- /**
5
- * Forked from @gozala's web-blob under MIT license
6
- * @see https://github.com/Gozala/web-blob
7
- */
8
- const readable_stream_1 = require("./readable-stream");
9
- const blob_stream_controller_1 = require("./blob-stream-controller");
10
- /**
11
- * Blob stream is a `ReadableStream` extension optimized to have minimal
12
- * overhead when consumed as `AsyncIterable<Uint8Array>`.
13
- * extends {ReadableStream<Uint8Array>}
14
- * implements {AsyncIterable<Uint8Array>}
15
- */
16
- // @ts-ignore
17
- class BlobStream extends readable_stream_1.ReadableStreamPolyfill {
18
- /**
19
- * @param chunks
20
- */
21
- constructor(chunks) {
22
- // @ts-ignore
23
- super(new blob_stream_controller_1.BlobStreamController(chunks.values()), { type: 'bytes' });
24
- /** @private */
25
- this._chunks = chunks;
26
- }
27
- /**
28
- * @property [_options.preventCancel]
29
- */
30
- // @ts-ignore
31
- async *[Symbol.asyncIterator](_options) {
32
- const reader = this.getReader();
33
- yield* this._chunks;
34
- reader.releaseLock();
35
- }
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+
3
+ let _Symbol$asyncIterator;
4
+
5
+ import { ReadableStreamPolyfill } from './readable-stream';
6
+ import { BlobStreamController } from './blob-stream-controller';
7
+ _Symbol$asyncIterator = Symbol.asyncIterator;
8
+ export class BlobStream extends ReadableStreamPolyfill {
9
+ constructor(chunks) {
10
+ super(new BlobStreamController(chunks.values()), {
11
+ type: 'bytes'
12
+ });
13
+
14
+ _defineProperty(this, "_chunks", void 0);
15
+
16
+ this._chunks = chunks;
17
+ }
18
+
19
+ async *[_Symbol$asyncIterator](_options) {
20
+ const reader = this.getReader();
21
+ yield* this._chunks;
22
+ reader.releaseLock();
23
+ }
24
+
36
25
  }
37
- exports.BlobStream = BlobStream;
26
+ //# sourceMappingURL=blob-stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/node/file/blob-stream.ts"],"names":["ReadableStreamPolyfill","BlobStreamController","Symbol","asyncIterator","BlobStream","constructor","chunks","values","type","_chunks","_options","reader","getReader","releaseLock"],"mappings":";;;;AAIA,SAAQA,sBAAR,QAAqC,mBAArC;AACA,SAAQC,oBAAR,QAAmC,0BAAnC;wBAyBUC,MAAM,CAACC,a;AAhBjB,OAAO,MAAMC,UAAN,SAA4BJ,sBAA5B,CAAsD;AAK3DK,EAAAA,WAAW,CAACC,MAAD,EAAS;AAElB,UAAM,IAAIL,oBAAJ,CAAyBK,MAAM,CAACC,MAAP,EAAzB,CAAN,EAAiD;AAACC,MAAAA,IAAI,EAAE;AAAP,KAAjD;;AAFkB;;AAIlB,SAAKC,OAAL,GAAeH,MAAf;AACD;;AAMD,iCAA8BI,QAA9B,EAA+F;AAC7F,UAAMC,MAAM,GAAG,KAAKC,SAAL,EAAf;AACA,WAAO,KAAKH,OAAZ;AACAE,IAAAA,MAAM,CAACE,WAAP;AACD;;AApB0D","sourcesContent":["/**\n * Forked from @gozala's web-blob under MIT license\n * @see https://github.com/Gozala/web-blob\n */\nimport {ReadableStreamPolyfill} from './readable-stream';\nimport {BlobStreamController} from './blob-stream-controller';\n\n/**\n * Blob stream is a `ReadableStream` extension optimized to have minimal\n * overhead when consumed as `AsyncIterable<Uint8Array>`.\n * extends {ReadableStream<Uint8Array>}\n * implements {AsyncIterable<Uint8Array>}\n */\n// @ts-ignore\nexport class BlobStream<T> extends ReadableStreamPolyfill<T> {\n private readonly _chunks: Uint8Array[];\n /**\n * @param chunks\n */\n constructor(chunks) {\n // @ts-ignore\n super(new BlobStreamController(chunks.values()), {type: 'bytes'});\n /** @private */\n this._chunks = chunks;\n }\n\n /**\n * @property [_options.preventCancel]\n */\n // @ts-ignore\n async *[Symbol.asyncIterator](_options?: {preventCancel?: boolean}): AsyncIterable<Uint8Array> {\n const reader = this.getReader();\n yield* this._chunks;\n reader.releaseLock();\n }\n}\n"],"file":"blob-stream.js"}
@@ -1,160 +1,140 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BlobPolyfill = void 0;
4
- // Forked from @gozala's web-blob under MIT license https://github.com/Gozala/web-blob
5
- const blob_stream_1 = require("./blob-stream");
6
- /**
7
- * Forked from @gozala's web-blob under MIT license
8
- * @see https://github.com/Gozala/web-blob
9
- */
10
- class BlobPolyfill {
11
- /**
12
- * @param [init]
13
- * @param [options]
14
- */
15
- constructor(init = [], options = {}) {
16
- this.parts = [];
17
- this.size = 0;
18
- for (const part of init) {
19
- if (typeof part === 'string') {
20
- const bytes = new TextEncoder().encode(part);
21
- this.parts.push(bytes);
22
- this.size += bytes.byteLength;
23
- }
24
- else if (part instanceof BlobPolyfill) {
25
- this.size += part.size;
26
- // @ts-ignore - `parts` is marked private so TS will complain about
27
- // accessing it.
28
- this.parts.push(...part.parts);
29
- }
30
- else if (part instanceof ArrayBuffer) {
31
- this.parts.push(new Uint8Array(part));
32
- this.size += part.byteLength;
33
- }
34
- else if (part instanceof Uint8Array) {
35
- this.parts.push(part);
36
- this.size += part.byteLength;
37
- }
38
- else if (ArrayBuffer.isView(part)) {
39
- const { buffer, byteOffset, byteLength } = part;
40
- this.parts.push(new Uint8Array(buffer, byteOffset, byteLength));
41
- this.size += byteLength;
42
- }
43
- else {
44
- const bytes = new TextEncoder().encode(String(part));
45
- this.parts.push(bytes);
46
- this.size += bytes.byteLength;
47
- }
48
- }
49
- /** @private */
50
- this.type = readType(options.type);
51
- }
52
- /**
53
- * Returns a new Blob object containing the data in the specified range of
54
- * bytes of the blob on which it's called.
55
- * @param start=0 - An index into the Blob indicating the first
56
- * byte to include in the new Blob. If you specify a negative value, it's
57
- * treated as an offset from the end of the Blob toward the beginning. For
58
- * example, `-10` would be the 10th from last byte in the Blob. The default
59
- * value is `0`. If you specify a value for start that is larger than the
60
- * size of the source Blob, the returned Blob has size 0 and contains no
61
- * data.
62
- * @param end - An index into the `Blob` indicating the first byte
63
- * that will *not* be included in the new `Blob` (i.e. the byte exactly at
64
- * this index is not included). If you specify a negative value, it's treated
65
- * as an offset from the end of the Blob toward the beginning. For example,
66
- * `-10` would be the 10th from last byte in the `Blob`. The default value is
67
- * size.
68
- * @param type - The content type to assign to the new Blob;
69
- * this will be the value of its type property. The default value is an empty
70
- * string.
71
- */
72
- slice(start = 0, end = this.size, type = '') {
73
- const { size, parts: parts } = this;
74
- let offset = start < 0 ? Math.max(size + start, 0) : Math.min(start, size);
75
- let limit = end < 0 ? Math.max(size + end, 0) : Math.min(end, size);
76
- const span = Math.max(limit - offset, 0);
77
- const blob = new BlobPolyfill([], { type });
78
- if (span === 0) {
79
- // @ts-ignore
80
- return blob;
81
- }
82
- let blobSize = 0;
83
- const blobParts = [];
84
- for (const part of parts) {
85
- const { byteLength } = part;
86
- if (offset > 0 && byteLength <= offset) {
87
- offset -= byteLength;
88
- limit -= byteLength;
89
- }
90
- else {
91
- const chunk = part.subarray(offset, Math.min(byteLength, limit));
92
- blobParts.push(chunk);
93
- blobSize += chunk.byteLength;
94
- // no longer need to take that into account
95
- offset = 0;
96
- // don't add the overflow to new blobParts
97
- if (blobSize >= span) {
98
- break;
99
- }
100
- }
101
- }
102
- blob.parts = blobParts;
103
- blob.size = blobSize;
104
- // @ts-ignore
105
- return blob;
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+
3
+ let _Symbol$toStringTag;
4
+
5
+ import { BlobStream } from './blob-stream';
6
+ _Symbol$toStringTag = Symbol.toStringTag;
7
+ export class BlobPolyfill {
8
+ constructor(init = [], options = {}) {
9
+ _defineProperty(this, "type", void 0);
10
+
11
+ _defineProperty(this, "size", void 0);
12
+
13
+ _defineProperty(this, "parts", void 0);
14
+
15
+ this.parts = [];
16
+ this.size = 0;
17
+
18
+ for (const part of init) {
19
+ if (typeof part === 'string') {
20
+ const bytes = new TextEncoder().encode(part);
21
+ this.parts.push(bytes);
22
+ this.size += bytes.byteLength;
23
+ } else if (part instanceof BlobPolyfill) {
24
+ this.size += part.size;
25
+ this.parts.push(...part.parts);
26
+ } else if (part instanceof ArrayBuffer) {
27
+ this.parts.push(new Uint8Array(part));
28
+ this.size += part.byteLength;
29
+ } else if (part instanceof Uint8Array) {
30
+ this.parts.push(part);
31
+ this.size += part.byteLength;
32
+ } else if (ArrayBuffer.isView(part)) {
33
+ const {
34
+ buffer,
35
+ byteOffset,
36
+ byteLength
37
+ } = part;
38
+ this.parts.push(new Uint8Array(buffer, byteOffset, byteLength));
39
+ this.size += byteLength;
40
+ } else {
41
+ const bytes = new TextEncoder().encode(String(part));
42
+ this.parts.push(bytes);
43
+ this.size += bytes.byteLength;
44
+ }
106
45
  }
107
- /**
108
- * Returns a promise that resolves with an ArrayBuffer containing the entire
109
- * contents of the Blob as binary data.
110
- */
111
- // eslint-disable-next-line require-await
112
- async arrayBuffer() {
113
- return this._toArrayBuffer();
46
+
47
+ this.type = readType(options.type);
48
+ }
49
+
50
+ slice(start = 0, end = this.size, type = '') {
51
+ const {
52
+ size,
53
+ parts: parts
54
+ } = this;
55
+ let offset = start < 0 ? Math.max(size + start, 0) : Math.min(start, size);
56
+ let limit = end < 0 ? Math.max(size + end, 0) : Math.min(end, size);
57
+ const span = Math.max(limit - offset, 0);
58
+ const blob = new BlobPolyfill([], {
59
+ type
60
+ });
61
+
62
+ if (span === 0) {
63
+ return blob;
114
64
  }
115
- /**
116
- * Returns a promise that resolves with a USVString containing the entire
117
- * contents of the Blob interpreted as UTF-8 text.
118
- */
119
- // eslint-disable-next-line require-await
120
- async text() {
121
- const decoder = new TextDecoder();
122
- let text = '';
123
- for (const part of this.parts) {
124
- text += decoder.decode(part);
65
+
66
+ let blobSize = 0;
67
+ const blobParts = [];
68
+
69
+ for (const part of parts) {
70
+ const {
71
+ byteLength
72
+ } = part;
73
+
74
+ if (offset > 0 && byteLength <= offset) {
75
+ offset -= byteLength;
76
+ limit -= byteLength;
77
+ } else {
78
+ const chunk = part.subarray(offset, Math.min(byteLength, limit));
79
+ blobParts.push(chunk);
80
+ blobSize += chunk.byteLength;
81
+ offset = 0;
82
+
83
+ if (blobSize >= span) {
84
+ break;
125
85
  }
126
- return text;
86
+ }
127
87
  }
128
- /**
129
- */
130
- // @ts-ignore
131
- stream() {
132
- return new blob_stream_1.BlobStream(this.parts);
88
+
89
+ blob.parts = blobParts;
90
+ blob.size = blobSize;
91
+ return blob;
92
+ }
93
+
94
+ async arrayBuffer() {
95
+ return this._toArrayBuffer();
96
+ }
97
+
98
+ async text() {
99
+ const decoder = new TextDecoder();
100
+ let text = '';
101
+
102
+ for (const part of this.parts) {
103
+ text += decoder.decode(part);
133
104
  }
134
- /**
135
- * @returns {string}
136
- */
137
- toString() {
138
- return '[object Blob]';
139
- }
140
- get [Symbol.toStringTag]() {
141
- return 'Blob';
142
- }
143
- _toArrayBuffer() {
144
- const buffer = new ArrayBuffer(this.size);
145
- const bytes = new Uint8Array(buffer);
146
- let offset = 0;
147
- for (const part of this.parts) {
148
- bytes.set(part, offset);
149
- offset += part.byteLength;
150
- }
151
- return buffer;
105
+
106
+ return text;
107
+ }
108
+
109
+ stream() {
110
+ return new BlobStream(this.parts);
111
+ }
112
+
113
+ toString() {
114
+ return '[object Blob]';
115
+ }
116
+
117
+ get [_Symbol$toStringTag]() {
118
+ return 'Blob';
119
+ }
120
+
121
+ _toArrayBuffer() {
122
+ const buffer = new ArrayBuffer(this.size);
123
+ const bytes = new Uint8Array(buffer);
124
+ let offset = 0;
125
+
126
+ for (const part of this.parts) {
127
+ bytes.set(part, offset);
128
+ offset += part.byteLength;
152
129
  }
130
+
131
+ return buffer;
132
+ }
133
+
153
134
  }
154
- exports.BlobPolyfill = BlobPolyfill;
155
- /**
156
- */
135
+
157
136
  function readType(input = '') {
158
- const type = String(input).toLowerCase();
159
- return /[^\u0020-\u007E]/.test(type) ? '' : type;
137
+ const type = String(input).toLowerCase();
138
+ return /[^\u0020-\u007E]/.test(type) ? '' : type;
160
139
  }
140
+ //# sourceMappingURL=blob.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/node/file/blob.ts"],"names":["BlobStream","Symbol","toStringTag","BlobPolyfill","constructor","init","options","parts","size","part","bytes","TextEncoder","encode","push","byteLength","ArrayBuffer","Uint8Array","isView","buffer","byteOffset","String","type","readType","slice","start","end","offset","Math","max","min","limit","span","blob","blobSize","blobParts","chunk","subarray","arrayBuffer","_toArrayBuffer","text","decoder","TextDecoder","decode","stream","toString","set","input","toLowerCase","test"],"mappings":";;;;AACA,SAAQA,UAAR,QAAyB,eAAzB;sBAsJOC,MAAM,CAACC,W;AAhJd,OAAO,MAAMC,YAAN,CAAmB;AAWxBC,EAAAA,WAAW,CAACC,IAAgB,GAAG,EAApB,EAAwBC,OAAwB,GAAG,EAAnD,EAAuD;AAAA;;AAAA;;AAAA;;AAChE,SAAKC,KAAL,GAAa,EAAb;AAEA,SAAKC,IAAL,GAAY,CAAZ;;AACA,SAAK,MAAMC,IAAX,IAAmBJ,IAAnB,EAAyB;AACvB,UAAI,OAAOI,IAAP,KAAgB,QAApB,EAA8B;AAC5B,cAAMC,KAAK,GAAG,IAAIC,WAAJ,GAAkBC,MAAlB,CAAyBH,IAAzB,CAAd;AACA,aAAKF,KAAL,CAAWM,IAAX,CAAgBH,KAAhB;AACA,aAAKF,IAAL,IAAaE,KAAK,CAACI,UAAnB;AACD,OAJD,MAIO,IAAIL,IAAI,YAAYN,YAApB,EAAkC;AACvC,aAAKK,IAAL,IAAaC,IAAI,CAACD,IAAlB;AAGA,aAAKD,KAAL,CAAWM,IAAX,CAAgB,GAAGJ,IAAI,CAACF,KAAxB;AACD,OALM,MAKA,IAAIE,IAAI,YAAYM,WAApB,EAAiC;AACtC,aAAKR,KAAL,CAAWM,IAAX,CAAgB,IAAIG,UAAJ,CAAeP,IAAf,CAAhB;AACA,aAAKD,IAAL,IAAaC,IAAI,CAACK,UAAlB;AACD,OAHM,MAGA,IAAIL,IAAI,YAAYO,UAApB,EAAgC;AACrC,aAAKT,KAAL,CAAWM,IAAX,CAAgBJ,IAAhB;AACA,aAAKD,IAAL,IAAaC,IAAI,CAACK,UAAlB;AACD,OAHM,MAGA,IAAIC,WAAW,CAACE,MAAZ,CAAmBR,IAAnB,CAAJ,EAA8B;AACnC,cAAM;AAACS,UAAAA,MAAD;AAASC,UAAAA,UAAT;AAAqBL,UAAAA;AAArB,YAAmCL,IAAzC;AACA,aAAKF,KAAL,CAAWM,IAAX,CAAgB,IAAIG,UAAJ,CAAeE,MAAf,EAAuBC,UAAvB,EAAmCL,UAAnC,CAAhB;AACA,aAAKN,IAAL,IAAaM,UAAb;AACD,OAJM,MAIA;AACL,cAAMJ,KAAK,GAAG,IAAIC,WAAJ,GAAkBC,MAAlB,CAAyBQ,MAAM,CAACX,IAAD,CAA/B,CAAd;AACA,aAAKF,KAAL,CAAWM,IAAX,CAAgBH,KAAhB;AACA,aAAKF,IAAL,IAAaE,KAAK,CAACI,UAAnB;AACD;AACF;;AAGD,SAAKO,IAAL,GAAYC,QAAQ,CAAChB,OAAO,CAACe,IAAT,CAApB;AACD;;AAsBDE,EAAAA,KAAK,CAACC,KAAa,GAAG,CAAjB,EAAoBC,GAAW,GAAG,KAAKjB,IAAvC,EAA6Ca,IAAY,GAAG,EAA5D,EAAsE;AACzE,UAAM;AAACb,MAAAA,IAAD;AAAOD,MAAAA,KAAK,EAAEA;AAAd,QAAuB,IAA7B;AACA,QAAImB,MAAM,GAAGF,KAAK,GAAG,CAAR,GAAYG,IAAI,CAACC,GAAL,CAASpB,IAAI,GAAGgB,KAAhB,EAAuB,CAAvB,CAAZ,GAAwCG,IAAI,CAACE,GAAL,CAASL,KAAT,EAAgBhB,IAAhB,CAArD;AAEA,QAAIsB,KAAK,GAAGL,GAAG,GAAG,CAAN,GAAUE,IAAI,CAACC,GAAL,CAASpB,IAAI,GAAGiB,GAAhB,EAAqB,CAArB,CAAV,GAAoCE,IAAI,CAACE,GAAL,CAASJ,GAAT,EAAcjB,IAAd,CAAhD;AACA,UAAMuB,IAAI,GAAGJ,IAAI,CAACC,GAAL,CAASE,KAAK,GAAGJ,MAAjB,EAAyB,CAAzB,CAAb;AACA,UAAMM,IAAI,GAAG,IAAI7B,YAAJ,CAAiB,EAAjB,EAAqB;AAACkB,MAAAA;AAAD,KAArB,CAAb;;AAEA,QAAIU,IAAI,KAAK,CAAb,EAAgB;AAEd,aAAOC,IAAP;AACD;;AAED,QAAIC,QAAQ,GAAG,CAAf;AACA,UAAMC,SAAuB,GAAG,EAAhC;;AACA,SAAK,MAAMzB,IAAX,IAAmBF,KAAnB,EAA0B;AACxB,YAAM;AAACO,QAAAA;AAAD,UAAeL,IAArB;;AACA,UAAIiB,MAAM,GAAG,CAAT,IAAcZ,UAAU,IAAIY,MAAhC,EAAwC;AACtCA,QAAAA,MAAM,IAAIZ,UAAV;AACAgB,QAAAA,KAAK,IAAIhB,UAAT;AACD,OAHD,MAGO;AACL,cAAMqB,KAAK,GAAG1B,IAAI,CAAC2B,QAAL,CAAcV,MAAd,EAAsBC,IAAI,CAACE,GAAL,CAASf,UAAT,EAAqBgB,KAArB,CAAtB,CAAd;AACAI,QAAAA,SAAS,CAACrB,IAAV,CAAesB,KAAf;AACAF,QAAAA,QAAQ,IAAIE,KAAK,CAACrB,UAAlB;AAEAY,QAAAA,MAAM,GAAG,CAAT;;AAGA,YAAIO,QAAQ,IAAIF,IAAhB,EAAsB;AACpB;AACD;AACF;AACF;;AAEDC,IAAAA,IAAI,CAACzB,KAAL,GAAa2B,SAAb;AACAF,IAAAA,IAAI,CAACxB,IAAL,GAAYyB,QAAZ;AAGA,WAAOD,IAAP;AACD;;AAOgB,QAAXK,WAAW,GAAyB;AACxC,WAAO,KAAKC,cAAL,EAAP;AACD;;AAOS,QAAJC,IAAI,GAAoB;AAC5B,UAAMC,OAAO,GAAG,IAAIC,WAAJ,EAAhB;AACA,QAAIF,IAAI,GAAG,EAAX;;AACA,SAAK,MAAM9B,IAAX,IAAmB,KAAKF,KAAxB,EAA+B;AAC7BgC,MAAAA,IAAI,IAAIC,OAAO,CAACE,MAAR,CAAejC,IAAf,CAAR;AACD;;AACD,WAAO8B,IAAP;AACD;;AAKDI,EAAAA,MAAM,GAAoB;AACxB,WAAO,IAAI3C,UAAJ,CAAoB,KAAKO,KAAzB,CAAP;AACD;;AAKDqC,EAAAA,QAAQ,GAAG;AACT,WAAO,eAAP;AACD;;AAED,8BAA2B;AACzB,WAAO,MAAP;AACD;;AAEDN,EAAAA,cAAc,GAAgB;AAC5B,UAAMpB,MAAM,GAAG,IAAIH,WAAJ,CAAgB,KAAKP,IAArB,CAAf;AACA,UAAME,KAAK,GAAG,IAAIM,UAAJ,CAAeE,MAAf,CAAd;AACA,QAAIQ,MAAM,GAAG,CAAb;;AACA,SAAK,MAAMjB,IAAX,IAAmB,KAAKF,KAAxB,EAA+B;AAC7BG,MAAAA,KAAK,CAACmC,GAAN,CAAUpC,IAAV,EAAgBiB,MAAhB;AACAA,MAAAA,MAAM,IAAIjB,IAAI,CAACK,UAAf;AACD;;AACD,WAAOI,MAAP;AACD;;AA7JuB;;AAkK1B,SAASI,QAAT,CAAkBwB,KAAa,GAAG,EAAlC,EAA8C;AAC5C,QAAMzB,IAAI,GAAGD,MAAM,CAAC0B,KAAD,CAAN,CAAcC,WAAd,EAAb;AACA,SAAO,mBAAmBC,IAAnB,CAAwB3B,IAAxB,IAAgC,EAAhC,GAAqCA,IAA5C;AACD","sourcesContent":["// Forked from @gozala's web-blob under MIT license https://github.com/Gozala/web-blob\nimport {BlobStream} from './blob-stream';\n\n/**\n * Forked from @gozala's web-blob under MIT license\n * @see https://github.com/Gozala/web-blob\n */\nexport class BlobPolyfill {\n // implements Blob {\n /** The MIME type of the data contained in the Blob. If type is unknown, string is empty. */\n readonly type: string;\n /** The size, in bytes, of the data contained in the Blob object. */\n size: number;\n private parts: Uint8Array[];\n /**\n * @param [init]\n * @param [options]\n */\n constructor(init: BlobPart[] = [], options: BlobPropertyBag = {}) {\n this.parts = [];\n\n this.size = 0;\n for (const part of init) {\n if (typeof part === 'string') {\n const bytes = new TextEncoder().encode(part);\n this.parts.push(bytes);\n this.size += bytes.byteLength;\n } else if (part instanceof BlobPolyfill) {\n this.size += part.size;\n // @ts-ignore - `parts` is marked private so TS will complain about\n // accessing it.\n this.parts.push(...part.parts);\n } else if (part instanceof ArrayBuffer) {\n this.parts.push(new Uint8Array(part));\n this.size += part.byteLength;\n } else if (part instanceof Uint8Array) {\n this.parts.push(part);\n this.size += part.byteLength;\n } else if (ArrayBuffer.isView(part)) {\n const {buffer, byteOffset, byteLength} = part;\n this.parts.push(new Uint8Array(buffer, byteOffset, byteLength));\n this.size += byteLength;\n } else {\n const bytes = new TextEncoder().encode(String(part));\n this.parts.push(bytes);\n this.size += bytes.byteLength;\n }\n }\n\n /** @private */\n this.type = readType(options.type);\n }\n\n /**\n * Returns a new Blob object containing the data in the specified range of\n * bytes of the blob on which it's called.\n * @param start=0 - An index into the Blob indicating the first\n * byte to include in the new Blob. If you specify a negative value, it's\n * treated as an offset from the end of the Blob toward the beginning. For\n * example, `-10` would be the 10th from last byte in the Blob. The default\n * value is `0`. If you specify a value for start that is larger than the\n * size of the source Blob, the returned Blob has size 0 and contains no\n * data.\n * @param end - An index into the `Blob` indicating the first byte\n * that will *not* be included in the new `Blob` (i.e. the byte exactly at\n * this index is not included). If you specify a negative value, it's treated\n * as an offset from the end of the Blob toward the beginning. For example,\n * `-10` would be the 10th from last byte in the `Blob`. The default value is\n * size.\n * @param type - The content type to assign to the new Blob;\n * this will be the value of its type property. The default value is an empty\n * string.\n */\n slice(start: number = 0, end: number = this.size, type: string = ''): Blob {\n const {size, parts: parts} = this;\n let offset = start < 0 ? Math.max(size + start, 0) : Math.min(start, size);\n\n let limit = end < 0 ? Math.max(size + end, 0) : Math.min(end, size);\n const span = Math.max(limit - offset, 0);\n const blob = new BlobPolyfill([], {type});\n\n if (span === 0) {\n // @ts-ignore\n return blob;\n }\n\n let blobSize = 0;\n const blobParts: Uint8Array[] = [];\n for (const part of parts) {\n const {byteLength} = part;\n if (offset > 0 && byteLength <= offset) {\n offset -= byteLength;\n limit -= byteLength;\n } else {\n const chunk = part.subarray(offset, Math.min(byteLength, limit));\n blobParts.push(chunk);\n blobSize += chunk.byteLength;\n // no longer need to take that into account\n offset = 0;\n\n // don't add the overflow to new blobParts\n if (blobSize >= span) {\n break;\n }\n }\n }\n\n blob.parts = blobParts;\n blob.size = blobSize;\n\n // @ts-ignore\n return blob;\n }\n\n /**\n * Returns a promise that resolves with an ArrayBuffer containing the entire\n * contents of the Blob as binary data.\n */\n // eslint-disable-next-line require-await\n async arrayBuffer(): Promise<ArrayBuffer> {\n return this._toArrayBuffer();\n }\n\n /**\n * Returns a promise that resolves with a USVString containing the entire\n * contents of the Blob interpreted as UTF-8 text.\n */\n // eslint-disable-next-line require-await\n async text(): Promise<string> {\n const decoder = new TextDecoder();\n let text = '';\n for (const part of this.parts) {\n text += decoder.decode(part);\n }\n return text;\n }\n\n /**\n */\n // @ts-ignore\n stream(): BlobStream<any> {\n return new BlobStream<any>(this.parts);\n }\n\n /**\n * @returns {string}\n */\n toString() {\n return '[object Blob]';\n }\n\n get [Symbol.toStringTag]() {\n return 'Blob';\n }\n\n _toArrayBuffer(): ArrayBuffer {\n const buffer = new ArrayBuffer(this.size);\n const bytes = new Uint8Array(buffer);\n let offset = 0;\n for (const part of this.parts) {\n bytes.set(part, offset);\n offset += part.byteLength;\n }\n return buffer;\n }\n}\n\n/**\n */\nfunction readType(input: string = ''): string {\n const type = String(input).toLowerCase();\n return /[^\\u0020-\\u007E]/.test(type) ? '' : type;\n}\n"],"file":"blob.js"}
@@ -1,35 +1,84 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FileReaderPolyfill = void 0;
4
- const btoa_node_1 = require("../buffer/btoa.node");
5
- class FileReaderPolyfill {
6
- constructor() {
7
- this.onload = null;
8
- }
9
- abort() {
10
- return;
11
- }
12
- async readAsArrayBuffer(blob) {
13
- const arrayBuffer = await blob.arrayBuffer();
14
- if (this.onload) {
15
- this.onload({ target: { result: arrayBuffer } });
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ import { atob } from '../buffer/btoa.node';
3
+ export class FileReaderPolyfill {
4
+ constructor() {
5
+ _defineProperty(this, "onload", void 0);
6
+
7
+ _defineProperty(this, "onabort", void 0);
8
+
9
+ _defineProperty(this, "onerror", void 0);
10
+
11
+ _defineProperty(this, "error", void 0);
12
+
13
+ _defineProperty(this, "onloadstart", void 0);
14
+
15
+ _defineProperty(this, "onloadend", void 0);
16
+
17
+ _defineProperty(this, "onprogress", void 0);
18
+
19
+ _defineProperty(this, "readyState", void 0);
20
+
21
+ _defineProperty(this, "result", void 0);
22
+
23
+ _defineProperty(this, "DONE", void 0);
24
+
25
+ _defineProperty(this, "EMPTY", void 0);
26
+
27
+ _defineProperty(this, "LOADING", void 0);
28
+
29
+ _defineProperty(this, "addEventListener", void 0);
30
+
31
+ _defineProperty(this, "removeEventListener", void 0);
32
+
33
+ _defineProperty(this, "dispatchEvent", void 0);
34
+
35
+ this.onload = null;
36
+ }
37
+
38
+ abort() {
39
+ return;
40
+ }
41
+
42
+ async readAsArrayBuffer(blob) {
43
+ const arrayBuffer = await blob.arrayBuffer();
44
+
45
+ if (this.onload) {
46
+ this.onload({
47
+ target: {
48
+ result: arrayBuffer
16
49
  }
50
+ });
17
51
  }
18
- async readAsBinaryString(blob) {
19
- throw Error('Not implemented');
20
- }
21
- async readAsDataURL(blob) {
22
- const text = await blob.text();
23
- const dataUrl = `data://;base64,${(0, btoa_node_1.atob)(text)}`;
24
- if (this.onload) {
25
- this.onload({ target: { result: dataUrl } });
52
+ }
53
+
54
+ async readAsBinaryString(blob) {
55
+ throw Error('Not implemented');
56
+ }
57
+
58
+ async readAsDataURL(blob) {
59
+ const text = await blob.text();
60
+ const dataUrl = "data://;base64,".concat(atob(text));
61
+
62
+ if (this.onload) {
63
+ this.onload({
64
+ target: {
65
+ result: dataUrl
26
66
  }
67
+ });
27
68
  }
28
- async readAsText(blob) {
29
- const text = await blob.text();
30
- if (this.onload) {
31
- this.onload({ target: { result: text } });
69
+ }
70
+
71
+ async readAsText(blob) {
72
+ const text = await blob.text();
73
+
74
+ if (this.onload) {
75
+ this.onload({
76
+ target: {
77
+ result: text
32
78
  }
79
+ });
33
80
  }
81
+ }
82
+
34
83
  }
35
- exports.FileReaderPolyfill = FileReaderPolyfill;
84
+ //# sourceMappingURL=file-reader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/node/file/file-reader.ts"],"names":["atob","FileReaderPolyfill","constructor","onload","abort","readAsArrayBuffer","blob","arrayBuffer","target","result","readAsBinaryString","Error","readAsDataURL","text","dataUrl","readAsText"],"mappings":";AAAA,SAAQA,IAAR,QAAmB,qBAAnB;AAEA,OAAO,MAAMC,kBAAN,CAA+C;AAmBpDC,EAAAA,WAAW,GAAG;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AACZ,SAAKC,MAAL,GAAc,IAAd;AACD;;AAEDC,EAAAA,KAAK,GAAS;AACZ;AACD;;AAEsB,QAAjBC,iBAAiB,CAACC,IAAD,EAA4B;AACjD,UAAMC,WAAW,GAAG,MAAMD,IAAI,CAACC,WAAL,EAA1B;;AACA,QAAI,KAAKJ,MAAT,EAAiB;AACf,WAAKA,MAAL,CAAY;AAACK,QAAAA,MAAM,EAAE;AAACC,UAAAA,MAAM,EAAEF;AAAT;AAAT,OAAZ;AACD;AACF;;AAEuB,QAAlBG,kBAAkB,CAACJ,IAAD,EAAO;AAC7B,UAAMK,KAAK,CAAC,iBAAD,CAAX;AACD;;AAEkB,QAAbC,aAAa,CAACN,IAAD,EAAO;AACxB,UAAMO,IAAI,GAAG,MAAMP,IAAI,CAACO,IAAL,EAAnB;AACA,UAAMC,OAAO,4BAAqBd,IAAI,CAACa,IAAD,CAAzB,CAAb;;AACA,QAAI,KAAKV,MAAT,EAAiB;AACf,WAAKA,MAAL,CAAY;AAACK,QAAAA,MAAM,EAAE;AAACC,UAAAA,MAAM,EAAEK;AAAT;AAAT,OAAZ;AACD;AACF;;AAEe,QAAVC,UAAU,CAACT,IAAD,EAAO;AACrB,UAAMO,IAAI,GAAG,MAAMP,IAAI,CAACO,IAAL,EAAnB;;AACA,QAAI,KAAKV,MAAT,EAAiB;AACf,WAAKA,MAAL,CAAY;AAACK,QAAAA,MAAM,EAAE;AAACC,UAAAA,MAAM,EAAEI;AAAT;AAAT,OAAZ;AACD;AACF;;AAnDmD","sourcesContent":["import {atob} from '../buffer/btoa.node';\n\nexport class FileReaderPolyfill implements FileReader {\n // onload: ({result: any}) => void;\n onload;\n onabort;\n onerror;\n error;\n onloadstart;\n onloadend;\n onprogress;\n\n readyState;\n result;\n DONE;\n EMPTY;\n LOADING;\n addEventListener;\n removeEventListener;\n dispatchEvent;\n\n constructor() {\n this.onload = null;\n }\n\n abort(): void {\n return;\n }\n\n async readAsArrayBuffer(blob: Blob): Promise<void> {\n const arrayBuffer = await blob.arrayBuffer();\n if (this.onload) {\n this.onload({target: {result: arrayBuffer}});\n }\n }\n\n async readAsBinaryString(blob) {\n throw Error('Not implemented');\n }\n\n async readAsDataURL(blob) {\n const text = await blob.text();\n const dataUrl = `data://;base64,${atob(text)}`;\n if (this.onload) {\n this.onload({target: {result: dataUrl}});\n }\n }\n\n async readAsText(blob) {\n const text = await blob.text();\n if (this.onload) {\n this.onload({target: {result: text}});\n }\n }\n}\n"],"file":"file-reader.js"}