@loaders.gl/polyfills 4.0.0-alpha.5 → 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.js +2 -2
- package/dist/dist.min.js +268 -55
- 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/dist/es5/libs/encoding-indexes-asian.js +13 -0
- 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/esm/libs/encoding-indexes-asian.js +13 -0
- 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 +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +90 -49
- package/dist/lib/encoding-indexes.js +34 -29
- package/dist/lib/encoding.js +2610 -1281
- package/dist/libs/encoding-indexes-asian.d.ts +1 -1
- package/dist/libs/encoding-indexes-asian.js +9 -8
- package/dist/node/buffer/btoa.node.js +12 -5
- 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 +6 -1
- package/dist/node/fetch/fetch.node.d.ts.map +1 -1
- package/dist/node/fetch/fetch.node.js +128 -111
- package/dist/node/fetch/headers.node.d.ts +1 -1
- package/dist/node/fetch/headers.node.d.ts.map +1 -1
- package/dist/node/fetch/headers.node.js +95 -114
- package/dist/node/fetch/response.node.d.ts +2 -2
- package/dist/node/fetch/response.node.d.ts.map +1 -1
- package/dist/node/fetch/response.node.js +72 -84
- package/dist/node/fetch/utils/decode-data-uri.node.js +63 -53
- package/dist/node/fetch/utils/stream-utils.node.d.ts +8 -1
- package/dist/node/fetch/utils/stream-utils.node.d.ts.map +1 -1
- package/dist/node/fetch/utils/stream-utils.node.js +68 -93
- package/dist/node/file/blob-stream-controller.js +59 -52
- package/dist/node/file/blob-stream.js +36 -25
- package/dist/node/file/blob.js +151 -131
- package/dist/node/file/file-reader.js +28 -77
- package/dist/node/file/file.js +36 -25
- package/dist/node/file/install-file-polyfills.js +26 -21
- package/dist/node/file/readable-stream.js +10 -3
- package/dist/node/images/encode-image.node.js +38 -17
- package/dist/node/images/parse-image.node.d.ts +3 -1
- package/dist/node/images/parse-image.node.d.ts.map +1 -1
- package/dist/node/images/parse-image.node.js +40 -19
- package/dist/promise/all-settled.js +22 -17
- package/dist/utils/assert.js +8 -5
- package/dist/utils/globals.js +34 -7
- package/package.json +5 -4
- package/src/index.ts +7 -4
- 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/stream-utils.node.ts +10 -58
- 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/lib/encoding-indexes.js.map +0 -1
- package/dist/lib/encoding.js.map +0 -1
- 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
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
|
|
@@ -1,84 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
|
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 } });
|
|
49
16
|
}
|
|
50
|
-
});
|
|
51
17
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const dataUrl = "data://;base64,".concat(atob(text));
|
|
61
|
-
|
|
62
|
-
if (this.onload) {
|
|
63
|
-
this.onload({
|
|
64
|
-
target: {
|
|
65
|
-
result: dataUrl
|
|
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 } });
|
|
66
26
|
}
|
|
67
|
-
});
|
|
68
27
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if (this.onload) {
|
|
75
|
-
this.onload({
|
|
76
|
-
target: {
|
|
77
|
-
result: text
|
|
28
|
+
async readAsText(blob) {
|
|
29
|
+
const text = await blob.text();
|
|
30
|
+
if (this.onload) {
|
|
31
|
+
this.onload({ target: { result: text } });
|
|
78
32
|
}
|
|
79
|
-
});
|
|
80
33
|
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
34
|
}
|
|
84
|
-
|
|
35
|
+
exports.FileReaderPolyfill = FileReaderPolyfill;
|
package/dist/node/file/file.js
CHANGED
|
@@ -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.FilePolyfill = void 0;
|
|
4
|
+
// Forked from @gozala's web-file under MIT license https://github.com/Gozala/web-file
|
|
5
|
+
const blob_1 = require("./blob");
|
|
6
|
+
/**
|
|
7
|
+
* Forked from @gozala's web-file under MIT license
|
|
8
|
+
* @see https://github.com/Gozala/web-file
|
|
9
|
+
*/
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
class FilePolyfill extends blob_1.BlobPolyfill {
|
|
12
|
+
/**
|
|
13
|
+
* @param init
|
|
14
|
+
* @param name - A USVString representing the file name or the path
|
|
15
|
+
* to the file.
|
|
16
|
+
* @param [options]
|
|
17
|
+
*/
|
|
18
|
+
constructor(init, name, options = {}) {
|
|
19
|
+
super(init, options);
|
|
20
|
+
// implements File {
|
|
21
|
+
// public API
|
|
22
|
+
/** The name of the file referenced by the File object. */
|
|
23
|
+
this.name = '';
|
|
24
|
+
/** The path the URL of the File is relative to. */
|
|
25
|
+
this.webkitRelativePath = '';
|
|
26
|
+
// Per File API spec https://w3c.github.io/FileAPI/#file-constructor
|
|
27
|
+
// Every "/" character of file name must be replaced with a ":".
|
|
28
|
+
/** @private */
|
|
29
|
+
this.name = String(name).replace(/\//g, ':');
|
|
30
|
+
/** @private */
|
|
31
|
+
this.lastModified = options?.lastModified || Date.now();
|
|
32
|
+
}
|
|
33
|
+
get [Symbol.toStringTag]() {
|
|
34
|
+
return 'File';
|
|
35
|
+
}
|
|
25
36
|
}
|
|
26
|
-
|
|
37
|
+
exports.FilePolyfill = FilePolyfill;
|
|
@@ -1,22 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.installFilePolyfills = void 0;
|
|
4
|
+
const readable_stream_1 = require("./readable-stream");
|
|
5
|
+
const blob_1 = require("./blob");
|
|
6
|
+
const file_reader_1 = require("./file-reader");
|
|
7
|
+
const file_1 = require("./file");
|
|
8
|
+
function installFilePolyfills() {
|
|
9
|
+
if (typeof ReadableStream === 'undefined' && global) {
|
|
10
|
+
// @ts-ignore;
|
|
11
|
+
global.ReadableStream = readable_stream_1.ReadableStreamPolyfill;
|
|
12
|
+
}
|
|
13
|
+
if (typeof Blob === 'undefined' && global) {
|
|
14
|
+
// @ts-ignore;
|
|
15
|
+
global.Blob = blob_1.BlobPolyfill;
|
|
16
|
+
}
|
|
17
|
+
if (typeof FileReader === 'undefined' && global) {
|
|
18
|
+
// @ts-ignore;
|
|
19
|
+
global.FileReader = file_reader_1.FileReaderPolyfill;
|
|
20
|
+
}
|
|
21
|
+
// Install minimal Node.js File polyfill
|
|
22
|
+
if (typeof File === 'undefined' && global) {
|
|
23
|
+
// @ts-ignore;
|
|
24
|
+
global.File = file_1.FilePolyfill;
|
|
25
|
+
}
|
|
21
26
|
}
|
|
22
|
-
|
|
27
|
+
exports.installFilePolyfills = installFilePolyfills;
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReadableStreamPolyfill = void 0;
|
|
4
|
+
const web_streams_polyfill_1 = require("web-streams-polyfill");
|
|
5
|
+
// Want a polyfill, but please don't install it
|
|
6
|
+
// @ts-ignore
|
|
2
7
|
delete global.ReadableStream;
|
|
3
|
-
|
|
4
|
-
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
class ReadableStreamPolyfill extends web_streams_polyfill_1.ReadableStream {
|
|
10
|
+
}
|
|
11
|
+
exports.ReadableStreamPolyfill = ReadableStreamPolyfill;
|
|
@@ -1,20 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
// Use stackgl modules for DOM-less reading and writing of images
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.encodeImageNode = exports.encodeImageToStreamNode = void 0;
|
|
8
|
+
const save_pixels_1 = __importDefault(require("save-pixels"));
|
|
9
|
+
const ndarray_1 = __importDefault(require("ndarray"));
|
|
10
|
+
const to_array_buffer_node_1 = require("../buffer/to-array-buffer.node");
|
|
11
|
+
/**
|
|
12
|
+
* Returns data bytes representing a compressed image in PNG or JPG format,
|
|
13
|
+
* This data can be saved using file system (f) methods or
|
|
14
|
+
* used in a request.
|
|
15
|
+
* @param image to save
|
|
16
|
+
* @param options
|
|
17
|
+
* @param options.type='png' - png, jpg or image/png, image/jpg are valid
|
|
18
|
+
* @param options.dataURI - Whether to include a data URI header
|
|
19
|
+
* @return {*} bytes
|
|
20
|
+
*/
|
|
21
|
+
function encodeImageToStreamNode(image, options) {
|
|
22
|
+
// Support MIME type strings
|
|
23
|
+
const type = options.type ? options.type.replace('image/', '') : 'jpeg';
|
|
24
|
+
const pixels = (0, ndarray_1.default)(image.data, [image.width, image.height, 4], [4, image.width * 4, 1], 0);
|
|
25
|
+
// Note: savePixels returns a stream
|
|
26
|
+
return (0, save_pixels_1.default)(pixels, type, options);
|
|
8
27
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
28
|
+
exports.encodeImageToStreamNode = encodeImageToStreamNode;
|
|
29
|
+
function encodeImageNode(image, options) {
|
|
30
|
+
const imageStream = encodeImageToStreamNode(image, options);
|
|
31
|
+
return new Promise((resolve) => {
|
|
32
|
+
const buffers = [];
|
|
33
|
+
imageStream.on('data', (buffer) => buffers.push(buffer));
|
|
34
|
+
// TODO - convert to arraybuffer?
|
|
35
|
+
imageStream.on('end', () => {
|
|
36
|
+
const buffer = Buffer.concat(buffers);
|
|
37
|
+
resolve((0, to_array_buffer_node_1.bufferToArrayBuffer)(buffer));
|
|
38
|
+
});
|
|
17
39
|
});
|
|
18
|
-
});
|
|
19
40
|
}
|
|
20
|
-
|
|
41
|
+
exports.encodeImageNode = encodeImageNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-image.node.d.ts","sourceRoot":"","sources":["../../../src/node/images/parse-image.node.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parse-image.node.d.ts","sourceRoot":"","sources":["../../../src/node/images/parse-image.node.ts"],"names":[],"mappings":"AAIA,2EAA2E;AAC3E,eAAO,MAAM,mBAAmB,UAA2C,CAAC;AAG5E,KAAK,OAAO,GAAG;IACb,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAAC;AAEF,wBAAsB,cAAc,CAAC,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAQjG"}
|