@loaders.gl/polyfills 4.0.0-alpha.4 → 4.0.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.
- package/dist/bundle.d.ts +2 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +2 -2
- package/dist/dist.min.js +4207 -0
- package/dist/es5/bundle.js +6 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/index.js +103 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/lib/encoding-indexes.js +37 -0
- package/dist/es5/lib/encoding-indexes.js.map +1 -0
- package/dist/es5/lib/encoding.js +1214 -0
- package/dist/es5/lib/encoding.js.map +1 -0
- package/{src/libs/encoding-indexes.js → dist/es5/libs/encoding-indexes-asian.js} +2 -40
- package/dist/es5/node/buffer/btoa.node.js +14 -0
- package/dist/es5/node/buffer/btoa.node.js.map +1 -0
- package/dist/es5/node/buffer/to-array-buffer.node.js +14 -0
- package/dist/es5/node/buffer/to-array-buffer.node.js.map +1 -0
- package/dist/es5/node/fetch/fetch-file.node.js +83 -0
- package/dist/es5/node/fetch/fetch-file.node.js.map +1 -0
- package/dist/es5/node/fetch/fetch.node.js +194 -0
- package/dist/es5/node/fetch/fetch.node.js.map +1 -0
- package/dist/es5/node/fetch/headers.node.js +151 -0
- package/dist/es5/node/fetch/headers.node.js.map +1 -0
- package/dist/es5/node/fetch/response.node.js +182 -0
- package/dist/es5/node/fetch/response.node.js.map +1 -0
- package/dist/es5/node/fetch/utils/decode-data-uri.node.js +58 -0
- package/dist/es5/node/fetch/utils/decode-data-uri.node.js.map +1 -0
- package/dist/es5/node/fetch/utils/stream-utils.node.js +92 -0
- package/dist/es5/node/fetch/utils/stream-utils.node.js.map +1 -0
- package/dist/es5/node/file/blob-stream-controller.js +90 -0
- package/dist/es5/node/file/blob-stream-controller.js.map +1 -0
- package/dist/es5/node/file/blob-stream.js +64 -0
- package/dist/es5/node/file/blob-stream.js.map +1 -0
- package/dist/es5/node/file/blob.js +212 -0
- package/dist/es5/node/file/blob.js.map +1 -0
- package/dist/es5/node/file/file-reader.js +153 -0
- package/dist/es5/node/file/file-reader.js.map +1 -0
- package/dist/es5/node/file/file.js +44 -0
- package/dist/es5/node/file/file.js.map +1 -0
- package/dist/es5/node/file/install-file-polyfills.js +25 -0
- package/dist/es5/node/file/install-file-polyfills.js.map +1 -0
- package/dist/es5/node/file/readable-stream.js +27 -0
- package/dist/es5/node/file/readable-stream.js.map +1 -0
- package/dist/es5/node/images/encode-image.node.js +30 -0
- package/dist/es5/node/images/encode-image.node.js.map +1 -0
- package/dist/es5/node/images/parse-image.node.js +64 -0
- package/dist/es5/node/images/parse-image.node.js.map +1 -0
- package/dist/es5/promise/all-settled.js +28 -0
- package/dist/es5/promise/all-settled.js.map +1 -0
- package/dist/es5/utils/assert.js +12 -0
- package/dist/es5/utils/assert.js.map +1 -0
- package/dist/es5/utils/globals.js +18 -0
- package/dist/es5/utils/globals.js.map +1 -0
- package/dist/esm/bundle.js +4 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/index.js +54 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/encoding-indexes.js +30 -0
- package/dist/esm/lib/encoding-indexes.js.map +1 -0
- package/dist/esm/lib/encoding.js +1206 -0
- package/dist/esm/lib/encoding.js.map +1 -0
- package/dist/{libs/encoding-indexes.js → esm/libs/encoding-indexes-asian.js} +2 -40
- package/dist/esm/node/buffer/btoa.node.js +7 -0
- package/dist/esm/node/buffer/btoa.node.js.map +1 -0
- package/dist/esm/node/buffer/to-array-buffer.node.js +8 -0
- package/dist/esm/node/buffer/to-array-buffer.node.js.map +1 -0
- package/dist/esm/node/fetch/fetch-file.node.js +50 -0
- package/dist/esm/node/fetch/fetch-file.node.js.map +1 -0
- package/dist/esm/node/fetch/fetch.node.js +126 -0
- package/dist/esm/node/fetch/fetch.node.js.map +1 -0
- package/dist/esm/node/fetch/headers.node.js +102 -0
- package/dist/esm/node/fetch/headers.node.js.map +1 -0
- package/dist/esm/node/fetch/response.node.js +67 -0
- package/dist/esm/node/fetch/response.node.js.map +1 -0
- package/dist/esm/node/fetch/utils/decode-data-uri.node.js +45 -0
- package/dist/esm/node/fetch/utils/decode-data-uri.node.js.map +1 -0
- package/dist/esm/node/fetch/utils/stream-utils.node.js +43 -0
- package/dist/esm/node/fetch/utils/stream-utils.node.js.map +1 -0
- package/dist/esm/node/file/blob-stream-controller.js +44 -0
- package/dist/esm/node/file/blob-stream-controller.js.map +1 -0
- package/dist/esm/node/file/blob-stream.js +20 -0
- package/dist/esm/node/file/blob-stream.js.map +1 -0
- package/dist/esm/node/file/blob.js +120 -0
- package/dist/esm/node/file/blob.js.map +1 -0
- package/dist/esm/node/file/file-reader.js +60 -0
- package/dist/esm/node/file/file-reader.js.map +1 -0
- package/dist/esm/node/file/file.js +19 -0
- package/dist/esm/node/file/file.js.map +1 -0
- package/dist/esm/node/file/install-file-polyfills.js +19 -0
- package/dist/esm/node/file/install-file-polyfills.js.map +1 -0
- package/dist/esm/node/file/readable-stream.js +4 -0
- package/dist/esm/node/file/readable-stream.js.map +1 -0
- package/dist/esm/node/images/encode-image.node.js +20 -0
- package/dist/esm/node/images/encode-image.node.js.map +1 -0
- package/dist/esm/node/images/parse-image.node.js +29 -0
- package/dist/esm/node/images/parse-image.node.js.map +1 -0
- package/dist/esm/promise/all-settled.js +19 -0
- package/dist/esm/promise/all-settled.js.map +1 -0
- package/dist/esm/utils/assert.js +6 -0
- package/dist/esm/utils/assert.js.map +1 -0
- package/dist/esm/utils/globals.js +9 -0
- package/dist/esm/utils/globals.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +90 -49
- package/dist/lib/encoding-indexes.d.ts +31 -0
- package/dist/lib/encoding-indexes.d.ts.map +1 -0
- package/dist/lib/encoding-indexes.js +35 -0
- package/dist/lib/encoding.d.ts +15 -0
- package/dist/lib/encoding.d.ts.map +1 -0
- package/dist/lib/encoding.js +2779 -0
- package/dist/libs/encoding-indexes-asian.d.ts +10 -0
- package/dist/libs/encoding-indexes-asian.d.ts.map +1 -0
- package/dist/libs/encoding-indexes-asian.js +14 -0
- package/dist/node/buffer/btoa.node.d.ts +3 -0
- package/dist/node/buffer/btoa.node.d.ts.map +1 -0
- package/dist/node/buffer/btoa.node.js +12 -5
- package/dist/node/buffer/to-array-buffer.node.d.ts +2 -0
- package/dist/node/buffer/to-array-buffer.node.d.ts.map +1 -0
- package/dist/node/buffer/to-array-buffer.node.js +11 -8
- package/dist/node/fetch/fetch-file.node.d.ts +4 -0
- package/dist/node/fetch/fetch-file.node.d.ts.map +1 -0
- package/dist/node/fetch/fetch-file.node.js +51 -0
- package/dist/node/fetch/fetch.node.d.ts +12 -0
- package/dist/node/fetch/fetch.node.d.ts.map +1 -0
- package/dist/node/fetch/fetch.node.js +128 -111
- package/dist/node/fetch/headers.node.d.ts +34 -0
- package/dist/node/fetch/headers.node.d.ts.map +1 -0
- package/dist/node/fetch/headers.node.js +95 -114
- package/dist/node/fetch/response.node.d.ts +22 -0
- package/dist/node/fetch/response.node.d.ts.map +1 -0
- package/dist/node/fetch/response.node.js +72 -84
- package/dist/node/fetch/utils/decode-data-uri.node.d.ts +16 -0
- package/dist/node/fetch/utils/decode-data-uri.node.d.ts.map +1 -0
- package/dist/node/fetch/utils/decode-data-uri.node.js +63 -55
- package/dist/node/fetch/utils/stream-utils.node.d.ts +17 -0
- package/dist/node/fetch/utils/stream-utils.node.d.ts.map +1 -0
- package/dist/node/fetch/utils/stream-utils.node.js +69 -85
- package/dist/node/file/blob-stream-controller.d.ts +29 -0
- package/dist/node/file/blob-stream-controller.d.ts.map +1 -0
- package/dist/node/file/blob-stream-controller.js +59 -52
- package/dist/node/file/blob-stream.d.ts +25 -0
- package/dist/node/file/blob-stream.d.ts.map +1 -0
- package/dist/node/file/blob-stream.js +36 -25
- package/dist/node/file/blob.d.ts +58 -0
- package/dist/node/file/blob.d.ts.map +1 -0
- package/dist/node/file/blob.js +151 -131
- package/dist/node/file/file-reader.d.ts +24 -0
- package/dist/node/file/file-reader.d.ts.map +1 -0
- package/dist/node/file/file-reader.js +28 -77
- package/dist/node/file/file.d.ts +25 -0
- package/dist/node/file/file.d.ts.map +1 -0
- package/dist/node/file/file.js +36 -25
- package/dist/node/file/install-file-polyfills.d.ts +2 -0
- package/dist/node/file/install-file-polyfills.d.ts.map +1 -0
- package/dist/node/file/install-file-polyfills.js +26 -21
- package/dist/node/file/readable-stream.d.ts +4 -0
- package/dist/node/file/readable-stream.d.ts.map +1 -0
- package/dist/node/file/readable-stream.js +10 -3
- package/dist/node/images/encode-image.node.d.ts +20 -0
- package/dist/node/images/encode-image.node.d.ts.map +1 -0
- package/dist/node/images/encode-image.node.js +38 -17
- package/dist/node/images/parse-image.node.d.ts +13 -0
- package/dist/node/images/parse-image.node.d.ts.map +1 -0
- package/dist/node/images/parse-image.node.js +40 -19
- package/dist/promise/all-settled.d.ts +10 -0
- package/dist/promise/all-settled.d.ts.map +1 -0
- package/dist/promise/all-settled.js +22 -17
- package/dist/utils/assert.d.ts +2 -0
- package/dist/utils/assert.d.ts.map +1 -0
- package/dist/utils/assert.js +8 -5
- package/dist/utils/globals.d.ts +4 -0
- package/dist/utils/globals.d.ts.map +1 -0
- package/dist/utils/globals.js +34 -7
- package/package.json +9 -8
- package/src/index.ts +9 -6
- package/src/lib/encoding-indexes.ts +34 -0
- package/src/{libs/encoding.js → lib/encoding.ts} +78 -78
- package/src/libs/encoding-indexes-asian.js +13 -0
- package/src/node/fetch/fetch-file.node.ts +51 -0
- package/src/node/fetch/fetch.node.ts +64 -30
- package/src/node/fetch/headers.node.ts +1 -1
- package/src/node/fetch/response.node.ts +4 -2
- package/src/node/fetch/utils/decode-data-uri.node.ts +7 -6
- package/src/node/fetch/utils/stream-utils.node.ts +39 -64
- package/src/node/images/parse-image.node.ts +35 -20
- package/dist/bundle.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/libs/encoding.js +0 -3084
- package/dist/node/buffer/btoa.node.js.map +0 -1
- package/dist/node/buffer/to-array-buffer.node.js.map +0 -1
- package/dist/node/fetch/fetch.node.js.map +0 -1
- package/dist/node/fetch/headers.node.js.map +0 -1
- package/dist/node/fetch/response.node.js.map +0 -1
- package/dist/node/fetch/utils/decode-data-uri.node.js.map +0 -1
- package/dist/node/fetch/utils/stream-utils.node.js.map +0 -1
- package/dist/node/file/blob-stream-controller.js.map +0 -1
- package/dist/node/file/blob-stream.js.map +0 -1
- package/dist/node/file/blob.js.map +0 -1
- package/dist/node/file/file-reader.js.map +0 -1
- package/dist/node/file/file.js.map +0 -1
- package/dist/node/file/install-file-polyfills.js.map +0 -1
- package/dist/node/file/readable-stream.js.map +0 -1
- package/dist/node/images/encode-image.node.js.map +0 -1
- package/dist/node/images/parse-image.node.js.map +0 -1
- package/dist/promise/all-settled.js.map +0 -1
- package/dist/utils/assert.js.map +0 -1
- package/dist/utils/globals.js.map +0 -1
|
@@ -1,56 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
|
38
57
|
}
|
|
39
|
-
}
|
|
40
58
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
pull(controller) {
|
|
46
|
-
if (!this.isWorking) {
|
|
47
|
-
this.work(controller);
|
|
59
|
+
cancel() {
|
|
60
|
+
this.isCancelled = true;
|
|
48
61
|
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
cancel() {
|
|
52
|
-
this.isCancelled = true;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
62
|
}
|
|
56
|
-
|
|
63
|
+
exports.BlobStreamController = BlobStreamController;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Forked from @gozala's web-blob under MIT license
|
|
3
|
+
* @see https://github.com/Gozala/web-blob
|
|
4
|
+
*/
|
|
5
|
+
import { ReadableStreamPolyfill } from './readable-stream';
|
|
6
|
+
/**
|
|
7
|
+
* Blob stream is a `ReadableStream` extension optimized to have minimal
|
|
8
|
+
* overhead when consumed as `AsyncIterable<Uint8Array>`.
|
|
9
|
+
* extends {ReadableStream<Uint8Array>}
|
|
10
|
+
* implements {AsyncIterable<Uint8Array>}
|
|
11
|
+
*/
|
|
12
|
+
export declare class BlobStream<T> extends ReadableStreamPolyfill<T> {
|
|
13
|
+
private readonly _chunks;
|
|
14
|
+
/**
|
|
15
|
+
* @param chunks
|
|
16
|
+
*/
|
|
17
|
+
constructor(chunks: any);
|
|
18
|
+
/**
|
|
19
|
+
* @property [_options.preventCancel]
|
|
20
|
+
*/
|
|
21
|
+
[Symbol.asyncIterator](_options?: {
|
|
22
|
+
preventCancel?: boolean;
|
|
23
|
+
}): AsyncIterable<Uint8Array>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=blob-stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blob-stream.d.ts","sourceRoot":"","sources":["../../../src/node/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,26 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
+
}
|
|
25
36
|
}
|
|
26
|
-
|
|
37
|
+
exports.BlobStream = BlobStream;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { BlobStream } from './blob-stream';
|
|
2
|
+
/**
|
|
3
|
+
* Forked from @gozala's web-blob under MIT license
|
|
4
|
+
* @see https://github.com/Gozala/web-blob
|
|
5
|
+
*/
|
|
6
|
+
export declare class BlobPolyfill {
|
|
7
|
+
/** The MIME type of the data contained in the Blob. If type is unknown, string is empty. */
|
|
8
|
+
readonly type: string;
|
|
9
|
+
/** The size, in bytes, of the data contained in the Blob object. */
|
|
10
|
+
size: number;
|
|
11
|
+
private parts;
|
|
12
|
+
/**
|
|
13
|
+
* @param [init]
|
|
14
|
+
* @param [options]
|
|
15
|
+
*/
|
|
16
|
+
constructor(init?: BlobPart[], options?: BlobPropertyBag);
|
|
17
|
+
/**
|
|
18
|
+
* Returns a new Blob object containing the data in the specified range of
|
|
19
|
+
* bytes of the blob on which it's called.
|
|
20
|
+
* @param start=0 - An index into the Blob indicating the first
|
|
21
|
+
* byte to include in the new Blob. If you specify a negative value, it's
|
|
22
|
+
* treated as an offset from the end of the Blob toward the beginning. For
|
|
23
|
+
* example, `-10` would be the 10th from last byte in the Blob. The default
|
|
24
|
+
* value is `0`. If you specify a value for start that is larger than the
|
|
25
|
+
* size of the source Blob, the returned Blob has size 0 and contains no
|
|
26
|
+
* data.
|
|
27
|
+
* @param end - An index into the `Blob` indicating the first byte
|
|
28
|
+
* that will *not* be included in the new `Blob` (i.e. the byte exactly at
|
|
29
|
+
* this index is not included). If you specify a negative value, it's treated
|
|
30
|
+
* as an offset from the end of the Blob toward the beginning. For example,
|
|
31
|
+
* `-10` would be the 10th from last byte in the `Blob`. The default value is
|
|
32
|
+
* size.
|
|
33
|
+
* @param type - The content type to assign to the new Blob;
|
|
34
|
+
* this will be the value of its type property. The default value is an empty
|
|
35
|
+
* string.
|
|
36
|
+
*/
|
|
37
|
+
slice(start?: number, end?: number, type?: string): Blob;
|
|
38
|
+
/**
|
|
39
|
+
* Returns a promise that resolves with an ArrayBuffer containing the entire
|
|
40
|
+
* contents of the Blob as binary data.
|
|
41
|
+
*/
|
|
42
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
43
|
+
/**
|
|
44
|
+
* Returns a promise that resolves with a USVString containing the entire
|
|
45
|
+
* contents of the Blob interpreted as UTF-8 text.
|
|
46
|
+
*/
|
|
47
|
+
text(): Promise<string>;
|
|
48
|
+
/**
|
|
49
|
+
*/
|
|
50
|
+
stream(): BlobStream<any>;
|
|
51
|
+
/**
|
|
52
|
+
* @returns {string}
|
|
53
|
+
*/
|
|
54
|
+
toString(): string;
|
|
55
|
+
get [Symbol.toStringTag](): string;
|
|
56
|
+
_toArrayBuffer(): ArrayBuffer;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=blob.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blob.d.ts","sourceRoot":"","sources":["../../../src/node/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"}
|
package/dist/node/file/blob.js
CHANGED
|
@@ -1,140 +1,160 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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;
|
|
45
106
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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;
|
|
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();
|
|
64
114
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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;
|
|
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);
|
|
85
125
|
}
|
|
86
|
-
|
|
126
|
+
return text;
|
|
87
127
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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);
|
|
128
|
+
/**
|
|
129
|
+
*/
|
|
130
|
+
// @ts-ignore
|
|
131
|
+
stream() {
|
|
132
|
+
return new blob_stream_1.BlobStream(this.parts);
|
|
104
133
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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;
|
|
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;
|
|
129
152
|
}
|
|
130
|
-
|
|
131
|
-
return buffer;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
153
|
}
|
|
135
|
-
|
|
154
|
+
exports.BlobPolyfill = BlobPolyfill;
|
|
155
|
+
/**
|
|
156
|
+
*/
|
|
136
157
|
function readType(input = '') {
|
|
137
|
-
|
|
138
|
-
|
|
158
|
+
const type = String(input).toLowerCase();
|
|
159
|
+
return /[^\u0020-\u007E]/.test(type) ? '' : type;
|
|
139
160
|
}
|
|
140
|
-
//# sourceMappingURL=blob.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare class FileReaderPolyfill implements FileReader {
|
|
2
|
+
onload: any;
|
|
3
|
+
onabort: any;
|
|
4
|
+
onerror: any;
|
|
5
|
+
error: any;
|
|
6
|
+
onloadstart: any;
|
|
7
|
+
onloadend: any;
|
|
8
|
+
onprogress: any;
|
|
9
|
+
readyState: any;
|
|
10
|
+
result: any;
|
|
11
|
+
DONE: any;
|
|
12
|
+
EMPTY: any;
|
|
13
|
+
LOADING: any;
|
|
14
|
+
addEventListener: any;
|
|
15
|
+
removeEventListener: any;
|
|
16
|
+
dispatchEvent: any;
|
|
17
|
+
constructor();
|
|
18
|
+
abort(): void;
|
|
19
|
+
readAsArrayBuffer(blob: Blob): Promise<void>;
|
|
20
|
+
readAsBinaryString(blob: any): Promise<void>;
|
|
21
|
+
readAsDataURL(blob: any): Promise<void>;
|
|
22
|
+
readAsText(blob: any): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=file-reader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-reader.d.ts","sourceRoot":"","sources":["../../../src/node/file/file-reader.ts"],"names":[],"mappings":"AAEA,qBAAa,kBAAmB,YAAW,UAAU;IAEnD,MAAM,MAAC;IACP,OAAO,MAAC;IACR,OAAO,MAAC;IACR,KAAK,MAAC;IACN,WAAW,MAAC;IACZ,SAAS,MAAC;IACV,UAAU,MAAC;IAEX,UAAU,MAAC;IACX,MAAM,MAAC;IACP,IAAI,MAAC;IACL,KAAK,MAAC;IACN,OAAO,MAAC;IACR,gBAAgB,MAAC;IACjB,mBAAmB,MAAC;IACpB,aAAa,MAAC;;IAMd,KAAK,IAAI,IAAI;IAIP,iBAAiB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAO5C,kBAAkB,CAAC,IAAI,KAAA;IAIvB,aAAa,CAAC,IAAI,KAAA;IAQlB,UAAU,CAAC,IAAI,KAAA;CAMtB"}
|