@loaders.gl/polyfills 3.1.0-alpha.3 → 3.1.0-beta.2
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 +3993 -4
- package/dist/es5/bundle.js +7 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/index.js +120 -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 +1459 -0
- package/dist/es5/lib/encoding.js.map +1 -0
- package/dist/{libs/encoding-indexes.js → es5/libs/encoding-indexes-asian.js} +2 -40
- package/dist/es5/node/buffer/btoa.node.js +16 -0
- package/dist/es5/node/buffer/btoa.node.js.map +1 -0
- package/dist/es5/node/buffer/to-array-buffer.node.js +16 -0
- package/dist/es5/node/buffer/to-array-buffer.node.js.map +1 -0
- package/dist/es5/node/fetch/fetch.node.js +141 -0
- package/dist/es5/node/fetch/fetch.node.js.map +1 -0
- package/dist/es5/node/fetch/headers.node.js +136 -0
- package/dist/{node → es5/node}/fetch/headers.node.js.map +1 -1
- package/dist/es5/node/fetch/response.node.js +96 -0
- package/dist/es5/node/fetch/response.node.js.map +1 -0
- package/dist/es5/node/fetch/utils/decode-data-uri.node.js +66 -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 +107 -0
- package/dist/es5/node/fetch/utils/stream-utils.node.js.map +1 -0
- package/dist/es5/node/file/blob-stream-controller.js +65 -0
- package/dist/es5/node/file/blob-stream-controller.js.map +1 -0
- package/dist/es5/node/file/blob-stream.js +38 -0
- package/dist/es5/node/file/blob-stream.js.map +1 -0
- package/dist/es5/node/file/blob.js +150 -0
- package/dist/es5/node/file/blob.js.map +1 -0
- package/dist/es5/node/file/file-reader.js +82 -0
- package/dist/es5/node/file/file-reader.js.map +1 -0
- package/dist/es5/node/file/file.js +35 -0
- package/dist/es5/node/file/file.js.map +1 -0
- package/dist/es5/node/file/install-file-polyfills.js +33 -0
- package/dist/es5/node/file/install-file-polyfills.js.map +1 -0
- package/dist/es5/node/file/readable-stream.js +15 -0
- package/dist/es5/node/file/readable-stream.js.map +1 -0
- package/dist/es5/node/images/encode-image.node.js +34 -0
- package/dist/es5/node/images/encode-image.node.js.map +1 -0
- package/dist/es5/node/images/parse-image.node.js +34 -0
- package/dist/es5/node/images/parse-image.node.js.map +1 -0
- package/dist/es5/promise/all-settled.js +29 -0
- package/dist/es5/promise/all-settled.js.map +1 -0
- package/dist/es5/utils/assert.js +13 -0
- package/dist/es5/utils/assert.js.map +1 -0
- package/dist/es5/utils/globals.js +16 -0
- package/dist/es5/utils/globals.js.map +1 -0
- package/dist/esm/bundle.js +5 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/index.js +63 -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 +1450 -0
- package/dist/esm/lib/encoding.js.map +1 -0
- package/{src/libs/encoding-indexes.js → dist/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 +9 -0
- package/dist/esm/node/buffer/to-array-buffer.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 +125 -0
- package/dist/esm/node/fetch/headers.node.js.map +1 -0
- package/dist/esm/node/fetch/response.node.js +88 -0
- package/dist/esm/node/fetch/response.node.js.map +1 -0
- package/dist/esm/node/fetch/utils/decode-data-uri.node.js +57 -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 +89 -0
- package/dist/esm/node/fetch/utils/stream-utils.node.js.map +1 -0
- package/dist/esm/node/file/blob-stream-controller.js +56 -0
- package/dist/esm/node/file/blob-stream-controller.js.map +1 -0
- package/dist/esm/node/file/blob-stream.js +26 -0
- package/dist/esm/node/file/blob-stream.js.map +1 -0
- package/dist/esm/node/file/blob.js +140 -0
- package/dist/esm/node/file/blob.js.map +1 -0
- package/dist/esm/node/file/file-reader.js +84 -0
- package/dist/esm/node/file/file-reader.js.map +1 -0
- package/dist/esm/node/file/file.js +26 -0
- package/dist/esm/node/file/file.js.map +1 -0
- package/dist/esm/node/file/install-file-polyfills.js +22 -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 +20 -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 +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +84 -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.node.d.ts +7 -0
- package/dist/node/fetch/fetch.node.d.ts.map +1 -0
- package/dist/node/fetch/fetch.node.js +104 -102
- 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 +94 -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 +73 -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 +61 -55
- package/dist/node/fetch/utils/stream-utils.node.d.ts +4 -0
- package/dist/node/fetch/utils/stream-utils.node.d.ts.map +1 -0
- package/dist/node/fetch/utils/stream-utils.node.js +88 -79
- 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 +11 -0
- package/dist/node/images/parse-image.node.d.ts.map +1 -0
- package/dist/node/images/parse-image.node.js +28 -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 +8 -8
- package/src/index.ts +2 -2
- package/src/lib/encoding-indexes.ts +34 -0
- package/{dist/libs/encoding.js → src/lib/encoding.ts} +78 -78
- package/src/libs/encoding-indexes-asian.js +13 -0
- package/src/node/fetch/fetch.node.ts +19 -2
- package/dist/bundle.js.map +0 -1
- package/dist/dist.min.js +0 -2
- package/dist/dist.min.js.map +0 -1
- package/dist/index.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/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/src/libs/encoding.js +0 -3084
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/node/fetch/utils/stream-utils.node.ts"],"names":["isRequestURL","url","startsWith","createReadStream","options","noqueryUrl","split","Promise","resolve","reject","stream","fs","encoding","once","on","error","requestFunction","https","request","http","requestOptions","getRequestOptions","req","res","end","decompressReadStream","readStream","headers","get","pipe","zlib","createBrotliDecompress","createGunzip","createDeflate","concatenateReadStream","arrayBuffer","ArrayBuffer","read","chunk","Error","chunkAsArrayBuffer","concatenateArrayBuffers","originalHeaders","key","Object","keys","toLowerCase","urlObject","URL","hostname","path","pathname","method","fetch","source1","source2","sourceArray1","Uint8Array","sourceArray2","temp","byteLength","set","buffer"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AAEA;;AAEA,MAAMA,YAAY,GAAIC,GAAD,IAASA,GAAG,CAACC,UAAJ,CAAe,OAAf,KAA2BD,GAAG,CAACC,UAAJ,CAAe,QAAf,CAAzD;;AAGO,eAAeC,gBAAf,CAAgCF,GAAhC,EAAqCG,OAArC,EAA8C;AAEnD,MAAI,CAACJ,YAAY,CAACC,GAAD,CAAjB,EAAwB;AACtB,UAAMI,UAAU,GAAGJ,GAAG,CAACK,KAAJ,CAAU,GAAV,EAAe,CAAf,CAAnB;AAEA,WAAO,MAAM,IAAIC,OAAJ,CAAY,CAACC,OAAD,EAAUC,MAAV,KAAqB;AAE5C,YAAMC,MAAM,GAAGC,YAAGR,gBAAH,CAAoBE,UAApB,EAAgC;AAACO,QAAAA,QAAQ,EAAE;AAAX,OAAhC,CAAf;;AACAF,MAAAA,MAAM,CAACG,IAAP,CAAY,UAAZ,EAAwB,MAAML,OAAO,CAACE,MAAD,CAArC;AACAA,MAAAA,MAAM,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AH,aAAGA,OAAH,uBAAGA,OAAO,CAAEiD,KAAZ,CANK;AAQL1B,IAAAA;AARK,GAAP;AAUD;;AAED,SAASc,uBAAT,CAAiCa,OAAjC,EAA0CC,OAA1C,EAAmD;AACjD,QAAMC,YAAY,GAAGF,OAAO,YAAYlB,WAAnB,GAAiC,IAAIqB,UAAJ,CAAeH,OAAf,CAAjC,GAA2DA,OAAhF;AACA,QAAMI,YAAY,GAAGH,OAAO,YAAYnB,WAAnB,GAAiC,IAAIqB,UAAJ,CAAeF,OAAf,CAAjC,GAA2DA,OAAhF;AACA,QAAMI,IAAI,GAAG,IAAIF,UAAJ,CAAeD,YAAY,CAACI,UAAb,GAA0BF,YAAY,CAACE,UAAtD,CAAb;AACAD,EAAAA,IAAI,CAACE,GAAL,CAASL,YAAT,EAAuB,CAAvB;AACAG,EAAAA,IAAI,CAACE,GAAL,CAASH,YAAT,EAAuBF,YAAY,CAACI,UAApC;AACA,SAAOD,IAAI,CAACG,MAAZ;AACD","sourcesContent":["import fs from 'fs'; // `fs` will be empty object in browsers (see package.json \"browser\" field).\nimport http from 'http';\nimport https from 'https';\nimport zlib from 'zlib';\n\nimport {toArrayBuffer} from './decode-data-uri.node';\n\nconst isRequestURL = (url) => url.startsWith('http:') || url.startsWith('https:');\n\n// Returns a promise that resolves to a readable stream\nexport async function createReadStream(url, options) {\n // Handle file streams in node\n if (!isRequestURL(url)) {\n const noqueryUrl = url.split('?')[0];\n // Now open the stream\n return await new Promise((resolve, reject) => {\n // @ts-ignore\n const stream = fs.createReadStream(noqueryUrl, {encoding: null});\n stream.once('readable', () => resolve(stream));\n stream.on('error', (error) => reject(error));\n });\n }\n\n // HANDLE HTTP/HTTPS REQUESTS IN NODE\n // TODO: THIS IS BAD SINCE WE RETURN A PROMISE INSTEAD OF A STREAM\n return await new Promise((resolve, reject) => {\n const requestFunction = url.startsWith('https:') ? https.request : http.request;\n const requestOptions = getRequestOptions(url, options);\n const req = requestFunction(requestOptions, (res) => resolve(res));\n req.on('error', (error) => reject(error));\n req.end();\n });\n}\n\nexport function decompressReadStream(readStream, headers) {\n switch (headers.get('content-encoding')) {\n case 'br':\n return readStream.pipe(zlib.createBrotliDecompress());\n case 'gzip':\n return readStream.pipe(zlib.createGunzip());\n case 'deflate':\n return readStream.pipe(zlib.createDeflate());\n default:\n // No compression or an unknown one, just return it as is\n return readStream;\n }\n}\n\nexport async function concatenateReadStream(readStream) {\n let arrayBuffer = new ArrayBuffer(0);\n\n return await new Promise((resolve, reject) => {\n readStream.on('error', (error) => reject(error));\n\n // Once the readable callback has been added, stream switches to \"flowing mode\"\n // In Node 10 (but not 12 and 14) this causes `data` and `end` to never be called unless we read data here\n readStream.on('readable', () => readStream.read());\n\n readStream.on('data', (chunk) => {\n if (typeof chunk === 'string') {\n reject(new Error('Read stream not binary'));\n }\n const chunkAsArrayBuffer = toArrayBuffer(chunk);\n arrayBuffer = concatenateArrayBuffers(arrayBuffer, chunkAsArrayBuffer);\n });\n\n readStream.on('end', () => resolve(arrayBuffer));\n });\n}\n\n// HELPERS\n\nfunction getRequestOptions(url, options?: {fetch?: typeof fetch; headers?}) {\n // Ensure header keys are lower case so that we can merge without duplicates\n const originalHeaders = options?.headers || {};\n const headers = {};\n for (const key of Object.keys(originalHeaders)) {\n headers[key.toLowerCase()] = originalHeaders[key];\n }\n\n // Add default accept-encoding to headers\n headers['accept-encoding'] = headers['accept-encoding'] || 'gzip,br,deflate';\n\n const urlObject = new URL(url);\n return {\n hostname: urlObject.hostname,\n path: urlObject.pathname,\n method: 'GET',\n // Add options and user provided 'options.fetch' overrides if available\n ...options,\n ...options?.fetch,\n // Override with updated headers with accepted encodings:\n headers\n };\n}\n\nfunction concatenateArrayBuffers(source1, source2) {\n const sourceArray1 = source1 instanceof ArrayBuffer ? new Uint8Array(source1) : source1;\n const sourceArray2 = source2 instanceof ArrayBuffer ? new Uint8Array(source2) : source2;\n const temp = new Uint8Array(sourceArray1.byteLength + sourceArray2.byteLength);\n temp.set(sourceArray1, 0);\n temp.set(sourceArray2, sourceArray1.byteLength);\n return temp.buffer;\n}\n"],"file":"stream-utils.node.js"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.BlobStreamController = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
class BlobStreamController {
|
|
13
|
+
constructor(chunks) {
|
|
14
|
+
(0, _defineProperty2.default)(this, "chunks", void 0);
|
|
15
|
+
(0, _defineProperty2.default)(this, "isWorking", false);
|
|
16
|
+
(0, _defineProperty2.default)(this, "isCancelled", false);
|
|
17
|
+
this.chunks = chunks;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
start(controller) {
|
|
21
|
+
this.work(controller);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async work(controller) {
|
|
25
|
+
const {
|
|
26
|
+
chunks
|
|
27
|
+
} = this;
|
|
28
|
+
this.isWorking = true;
|
|
29
|
+
|
|
30
|
+
while (!this.isCancelled && (controller.desiredSize || 0) > 0) {
|
|
31
|
+
let next;
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
next = chunks.next();
|
|
35
|
+
} catch (error) {
|
|
36
|
+
controller.error(error);
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (next) {
|
|
41
|
+
if (!next.done && !this.isCancelled) {
|
|
42
|
+
controller.enqueue(next.value);
|
|
43
|
+
} else {
|
|
44
|
+
controller.close();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
this.isWorking = false;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
pull(controller) {
|
|
53
|
+
if (!this.isWorking) {
|
|
54
|
+
this.work(controller);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
cancel() {
|
|
59
|
+
this.isCancelled = true;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
exports.BlobStreamController = BlobStreamController;
|
|
65
|
+
//# 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":";;;;;;;;;;;AAIO,MAAMA,oBAAN,CAA2B;AAQhCC,EAAAA,WAAW,CAACC,MAAD,EAA+B;AAAA;AAAA,qDANb,KAMa;AAAA,uDALX,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"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.BlobStream = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _readableStream = require("./readable-stream");
|
|
13
|
+
|
|
14
|
+
var _blobStreamController = require("./blob-stream-controller");
|
|
15
|
+
|
|
16
|
+
let _Symbol$asyncIterator;
|
|
17
|
+
|
|
18
|
+
_Symbol$asyncIterator = Symbol.asyncIterator;
|
|
19
|
+
|
|
20
|
+
class BlobStream extends _readableStream.ReadableStreamPolyfill {
|
|
21
|
+
constructor(chunks) {
|
|
22
|
+
super(new _blobStreamController.BlobStreamController(chunks.values()), {
|
|
23
|
+
type: 'bytes'
|
|
24
|
+
});
|
|
25
|
+
(0, _defineProperty2.default)(this, "_chunks", void 0);
|
|
26
|
+
this._chunks = chunks;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async *[_Symbol$asyncIterator](_options) {
|
|
30
|
+
const reader = this.getReader();
|
|
31
|
+
yield* this._chunks;
|
|
32
|
+
reader.releaseLock();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
exports.BlobStream = BlobStream;
|
|
38
|
+
//# sourceMappingURL=blob-stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/node/file/blob-stream.ts"],"names":["Symbol","asyncIterator","BlobStream","ReadableStreamPolyfill","constructor","chunks","BlobStreamController","values","type","_chunks","_options","reader","getReader","releaseLock"],"mappings":";;;;;;;;;;;AAIA;;AACA;;;;wBAyBUA,MAAM,CAACC,a;;AAhBV,MAAMC,UAAN,SAA4BC,sCAA5B,CAAsD;AAK3DC,EAAAA,WAAW,CAACC,MAAD,EAAS;AAElB,UAAM,IAAIC,0CAAJ,CAAyBD,MAAM,CAACE,MAAP,EAAzB,CAAN,EAAiD;AAACC,MAAAA,IAAI,EAAE;AAAP,KAAjD;AAFkB;AAIlB,SAAKC,OAAL,GAAeJ,MAAf;AACD;;AAMD,iCAA8BK,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"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.BlobPolyfill = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _blobStream = require("./blob-stream");
|
|
13
|
+
|
|
14
|
+
let _Symbol$toStringTag;
|
|
15
|
+
|
|
16
|
+
_Symbol$toStringTag = Symbol.toStringTag;
|
|
17
|
+
|
|
18
|
+
class BlobPolyfill {
|
|
19
|
+
constructor(init = [], options = {}) {
|
|
20
|
+
(0, _defineProperty2.default)(this, "type", void 0);
|
|
21
|
+
(0, _defineProperty2.default)(this, "size", void 0);
|
|
22
|
+
(0, _defineProperty2.default)(this, "parts", void 0);
|
|
23
|
+
this.parts = [];
|
|
24
|
+
this.size = 0;
|
|
25
|
+
|
|
26
|
+
for (const part of init) {
|
|
27
|
+
if (typeof part === 'string') {
|
|
28
|
+
const bytes = new TextEncoder().encode(part);
|
|
29
|
+
this.parts.push(bytes);
|
|
30
|
+
this.size += bytes.byteLength;
|
|
31
|
+
} else if (part instanceof BlobPolyfill) {
|
|
32
|
+
this.size += part.size;
|
|
33
|
+
this.parts.push(...part.parts);
|
|
34
|
+
} else if (part instanceof ArrayBuffer) {
|
|
35
|
+
this.parts.push(new Uint8Array(part));
|
|
36
|
+
this.size += part.byteLength;
|
|
37
|
+
} else if (part instanceof Uint8Array) {
|
|
38
|
+
this.parts.push(part);
|
|
39
|
+
this.size += part.byteLength;
|
|
40
|
+
} else if (ArrayBuffer.isView(part)) {
|
|
41
|
+
const {
|
|
42
|
+
buffer,
|
|
43
|
+
byteOffset,
|
|
44
|
+
byteLength
|
|
45
|
+
} = part;
|
|
46
|
+
this.parts.push(new Uint8Array(buffer, byteOffset, byteLength));
|
|
47
|
+
this.size += byteLength;
|
|
48
|
+
} else {
|
|
49
|
+
const bytes = new TextEncoder().encode(String(part));
|
|
50
|
+
this.parts.push(bytes);
|
|
51
|
+
this.size += bytes.byteLength;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
this.type = readType(options.type);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
slice(start = 0, end = this.size, type = '') {
|
|
59
|
+
const {
|
|
60
|
+
size,
|
|
61
|
+
parts: parts
|
|
62
|
+
} = this;
|
|
63
|
+
let offset = start < 0 ? Math.max(size + start, 0) : Math.min(start, size);
|
|
64
|
+
let limit = end < 0 ? Math.max(size + end, 0) : Math.min(end, size);
|
|
65
|
+
const span = Math.max(limit - offset, 0);
|
|
66
|
+
const blob = new BlobPolyfill([], {
|
|
67
|
+
type
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
if (span === 0) {
|
|
71
|
+
return blob;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
let blobSize = 0;
|
|
75
|
+
const blobParts = [];
|
|
76
|
+
|
|
77
|
+
for (const part of parts) {
|
|
78
|
+
const {
|
|
79
|
+
byteLength
|
|
80
|
+
} = part;
|
|
81
|
+
|
|
82
|
+
if (offset > 0 && byteLength <= offset) {
|
|
83
|
+
offset -= byteLength;
|
|
84
|
+
limit -= byteLength;
|
|
85
|
+
} else {
|
|
86
|
+
const chunk = part.subarray(offset, Math.min(byteLength, limit));
|
|
87
|
+
blobParts.push(chunk);
|
|
88
|
+
blobSize += chunk.byteLength;
|
|
89
|
+
offset = 0;
|
|
90
|
+
|
|
91
|
+
if (blobSize >= span) {
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
blob.parts = blobParts;
|
|
98
|
+
blob.size = blobSize;
|
|
99
|
+
return blob;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async arrayBuffer() {
|
|
103
|
+
return this._toArrayBuffer();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async text() {
|
|
107
|
+
const decoder = new TextDecoder();
|
|
108
|
+
let text = '';
|
|
109
|
+
|
|
110
|
+
for (const part of this.parts) {
|
|
111
|
+
text += decoder.decode(part);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return text;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
stream() {
|
|
118
|
+
return new _blobStream.BlobStream(this.parts);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
toString() {
|
|
122
|
+
return '[object Blob]';
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
get [_Symbol$toStringTag]() {
|
|
126
|
+
return 'Blob';
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
_toArrayBuffer() {
|
|
130
|
+
const buffer = new ArrayBuffer(this.size);
|
|
131
|
+
const bytes = new Uint8Array(buffer);
|
|
132
|
+
let offset = 0;
|
|
133
|
+
|
|
134
|
+
for (const part of this.parts) {
|
|
135
|
+
bytes.set(part, offset);
|
|
136
|
+
offset += part.byteLength;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return buffer;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
exports.BlobPolyfill = BlobPolyfill;
|
|
145
|
+
|
|
146
|
+
function readType(input = '') {
|
|
147
|
+
const type = String(input).toLowerCase();
|
|
148
|
+
return /[^\u0020-\u007E]/.test(type) ? '' : type;
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=blob.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/node/file/blob.ts"],"names":["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","BlobStream","toString","set","input","toLowerCase","test"],"mappings":";;;;;;;;;;;AACA;;;;sBAsJOA,MAAM,CAACC,W;;AAhJP,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,IA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a,GAAG,EAAlC,EAA8C;AAC5C,QAAM1B,IAAI,GAAGD,MAAM,CAAC2B,KAAD,CAAN,CAAcC,WAAd,EAAb;AACA,SAAO,mBAAmBC,IAAnB,CAAwB5B,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"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.FileReaderPolyfill = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _btoa = require("../buffer/btoa.node");
|
|
13
|
+
|
|
14
|
+
class FileReaderPolyfill {
|
|
15
|
+
constructor() {
|
|
16
|
+
(0, _defineProperty2.default)(this, "onload", void 0);
|
|
17
|
+
(0, _defineProperty2.default)(this, "onabort", void 0);
|
|
18
|
+
(0, _defineProperty2.default)(this, "onerror", void 0);
|
|
19
|
+
(0, _defineProperty2.default)(this, "error", void 0);
|
|
20
|
+
(0, _defineProperty2.default)(this, "onloadstart", void 0);
|
|
21
|
+
(0, _defineProperty2.default)(this, "onloadend", void 0);
|
|
22
|
+
(0, _defineProperty2.default)(this, "onprogress", void 0);
|
|
23
|
+
(0, _defineProperty2.default)(this, "readyState", void 0);
|
|
24
|
+
(0, _defineProperty2.default)(this, "result", void 0);
|
|
25
|
+
(0, _defineProperty2.default)(this, "DONE", void 0);
|
|
26
|
+
(0, _defineProperty2.default)(this, "EMPTY", void 0);
|
|
27
|
+
(0, _defineProperty2.default)(this, "LOADING", void 0);
|
|
28
|
+
(0, _defineProperty2.default)(this, "addEventListener", void 0);
|
|
29
|
+
(0, _defineProperty2.default)(this, "removeEventListener", void 0);
|
|
30
|
+
(0, _defineProperty2.default)(this, "dispatchEvent", void 0);
|
|
31
|
+
this.onload = null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
abort() {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async readAsArrayBuffer(blob) {
|
|
39
|
+
const arrayBuffer = await blob.arrayBuffer();
|
|
40
|
+
|
|
41
|
+
if (this.onload) {
|
|
42
|
+
this.onload({
|
|
43
|
+
target: {
|
|
44
|
+
result: arrayBuffer
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async readAsBinaryString(blob) {
|
|
51
|
+
throw Error('Not implemented');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async readAsDataURL(blob) {
|
|
55
|
+
const text = await blob.text();
|
|
56
|
+
const dataUrl = "data://;base64,".concat((0, _btoa.atob)(text));
|
|
57
|
+
|
|
58
|
+
if (this.onload) {
|
|
59
|
+
this.onload({
|
|
60
|
+
target: {
|
|
61
|
+
result: dataUrl
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async readAsText(blob) {
|
|
68
|
+
const text = await blob.text();
|
|
69
|
+
|
|
70
|
+
if (this.onload) {
|
|
71
|
+
this.onload({
|
|
72
|
+
target: {
|
|
73
|
+
result: text
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
exports.FileReaderPolyfill = FileReaderPolyfill;
|
|
82
|
+
//# sourceMappingURL=file-reader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/node/file/file-reader.ts"],"names":["FileReaderPolyfill","constructor","onload","abort","readAsArrayBuffer","blob","arrayBuffer","target","result","readAsBinaryString","Error","readAsDataURL","text","dataUrl","readAsText"],"mappings":";;;;;;;;;;;AAAA;;AAEO,MAAMA,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,4BAAqB,gBAAKD,IAAL,CAArB,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"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.FilePolyfill = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _blob = require("./blob");
|
|
13
|
+
|
|
14
|
+
let _Symbol$toStringTag;
|
|
15
|
+
|
|
16
|
+
_Symbol$toStringTag = Symbol.toStringTag;
|
|
17
|
+
|
|
18
|
+
class FilePolyfill extends _blob.BlobPolyfill {
|
|
19
|
+
constructor(init, name, options = {}) {
|
|
20
|
+
super(init, options);
|
|
21
|
+
(0, _defineProperty2.default)(this, "name", '');
|
|
22
|
+
(0, _defineProperty2.default)(this, "webkitRelativePath", '');
|
|
23
|
+
(0, _defineProperty2.default)(this, "lastModified", void 0);
|
|
24
|
+
this.name = String(name).replace(/\//g, ':');
|
|
25
|
+
this.lastModified = (options === null || options === void 0 ? void 0 : options.lastModified) || Date.now();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get [_Symbol$toStringTag]() {
|
|
29
|
+
return 'File';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
exports.FilePolyfill = FilePolyfill;
|
|
35
|
+
//# sourceMappingURL=file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/node/file/file.ts"],"names":["Symbol","toStringTag","FilePolyfill","BlobPolyfill","constructor","init","name","options","String","replace","lastModified","Date","now"],"mappings":";;;;;;;;;;;AACA;;;;sBAqCOA,MAAM,CAACC,W;;AA9BP,MAAMC,YAAN,SAA2BC,kBAA3B,CAAwC;AAoB7CC,EAAAA,WAAW,CAACC,IAAD,EAAmBC,IAAnB,EAAiCC,OAAwB,GAAG,EAA5D,EAAgE;AACzE,UAAMF,IAAN,EAAYE,OAAZ;AADyE,gDAhB5D,EAgB4D;AAAA,8DAd9C,EAc8C;AAAA;AAKzE,SAAKD,IAAL,GAAYE,MAAM,CAACF,IAAD,CAAN,CAAaG,OAAb,CAAqB,KAArB,EAA4B,GAA5B,CAAZ;AAEA,SAAKC,YAAL,GAAoB,CAAAH,OAAO,SAAP,IAAAA,OAAO,WAAP,YAAAA,OAAO,CAAEG,YAAT,KAAyBC,IAAI,CAACC,GAAL,EAA7C;AACD;;AAED,8BAA2B;AACzB,WAAO,MAAP;AACD;;AAhC4C","sourcesContent":["// Forked from @gozala's web-file under MIT license https://github.com/Gozala/web-file\nimport {BlobPolyfill} from './blob';\n\n/**\n * Forked from @gozala's web-file under MIT license\n * @see https://github.com/Gozala/web-file\n */\n// @ts-ignore\nexport class FilePolyfill extends BlobPolyfill {\n // implements File {\n // public API\n /** The name of the file referenced by the File object. */\n name: string = '';\n /** The path the URL of the File is relative to. */\n webkitRelativePath: string = '';\n\n /**\n * Returns the last modified time of the file, in millisecond since the UNIX\n * epoch (January 1st, 1970 at Midnight).\n */\n lastModified: number;\n\n /**\n * @param init\n * @param name - A USVString representing the file name or the path\n * to the file.\n * @param [options]\n */\n constructor(init: BlobPart[], name: string, options: FilePropertyBag = {}) {\n super(init, options);\n // Per File API spec https://w3c.github.io/FileAPI/#file-constructor\n // Every \"/\" character of file name must be replaced with a \":\".\n /** @private */\n this.name = String(name).replace(/\\//g, ':');\n /** @private */\n this.lastModified = options?.lastModified || Date.now();\n }\n\n get [Symbol.toStringTag]() {\n return 'File';\n }\n}\n"],"file":"file.js"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.installFilePolyfills = installFilePolyfills;
|
|
7
|
+
|
|
8
|
+
var _readableStream = require("./readable-stream");
|
|
9
|
+
|
|
10
|
+
var _blob = require("./blob");
|
|
11
|
+
|
|
12
|
+
var _fileReader = require("./file-reader");
|
|
13
|
+
|
|
14
|
+
var _file = require("./file");
|
|
15
|
+
|
|
16
|
+
function installFilePolyfills() {
|
|
17
|
+
if (typeof ReadableStream === 'undefined' && global) {
|
|
18
|
+
global.ReadableStream = _readableStream.ReadableStreamPolyfill;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (typeof Blob === 'undefined' && global) {
|
|
22
|
+
global.Blob = _blob.BlobPolyfill;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (typeof FileReader === 'undefined' && global) {
|
|
26
|
+
global.FileReader = _fileReader.FileReaderPolyfill;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (typeof File === 'undefined' && global) {
|
|
30
|
+
global.File = _file.FilePolyfill;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=install-file-polyfills.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/node/file/install-file-polyfills.ts"],"names":["installFilePolyfills","ReadableStream","global","ReadableStreamPolyfill","Blob","BlobPolyfill","FileReader","FileReaderPolyfill","File","FilePolyfill"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AAEO,SAASA,oBAAT,GAAgC;AACrC,MAAI,OAAOC,cAAP,KAA0B,WAA1B,IAAyCC,MAA7C,EAAqD;AAEnDA,IAAAA,MAAM,CAACD,cAAP,GAAwBE,sCAAxB;AACD;;AAED,MAAI,OAAOC,IAAP,KAAgB,WAAhB,IAA+BF,MAAnC,EAA2C;AAEzCA,IAAAA,MAAM,CAACE,IAAP,GAAcC,kBAAd;AACD;;AAED,MAAI,OAAOC,UAAP,KAAsB,WAAtB,IAAqCJ,MAAzC,EAAiD;AAE/CA,IAAAA,MAAM,CAACI,UAAP,GAAoBC,8BAApB;AACD;;AAGD,MAAI,OAAOC,IAAP,KAAgB,WAAhB,IAA+BN,MAAnC,EAA2C;AAEzCA,IAAAA,MAAM,CAACM,IAAP,GAAcC,kBAAd;AACD;AACF","sourcesContent":["import {ReadableStreamPolyfill} from './readable-stream';\nimport {BlobPolyfill} from './blob';\nimport {FileReaderPolyfill} from './file-reader';\nimport {FilePolyfill} from './file';\n\nexport function installFilePolyfills() {\n if (typeof ReadableStream === 'undefined' && global) {\n // @ts-ignore;\n global.ReadableStream = ReadableStreamPolyfill;\n }\n\n if (typeof Blob === 'undefined' && global) {\n // @ts-ignore;\n global.Blob = BlobPolyfill;\n }\n\n if (typeof FileReader === 'undefined' && global) {\n // @ts-ignore;\n global.FileReader = FileReaderPolyfill;\n }\n\n // Install minimal Node.js File polyfill\n if (typeof File === 'undefined' && global) {\n // @ts-ignore;\n global.File = FilePolyfill;\n }\n}\n"],"file":"install-file-polyfills.js"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ReadableStreamPolyfill = void 0;
|
|
7
|
+
|
|
8
|
+
var _webStreamsPolyfill = require("web-streams-polyfill");
|
|
9
|
+
|
|
10
|
+
delete global.ReadableStream;
|
|
11
|
+
|
|
12
|
+
class ReadableStreamPolyfill extends _webStreamsPolyfill.ReadableStream {}
|
|
13
|
+
|
|
14
|
+
exports.ReadableStreamPolyfill = ReadableStreamPolyfill;
|
|
15
|
+
//# sourceMappingURL=readable-stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/node/file/readable-stream.ts"],"names":["global","ReadableStream","ReadableStreamPolyfill","WSPReadableStream"],"mappings":";;;;;;;AAAA;;AAIA,OAAOA,MAAM,CAACC,cAAd;;AAGO,MAAMC,sBAAN,SAAwCC,kCAAxC,CAAuF","sourcesContent":["import {ReadableStream as WSPReadableStream} from 'web-streams-polyfill';\n\n// Want a polyfill, but please don't install it\n// @ts-ignore\ndelete global.ReadableStream;\n\n// @ts-ignore\nexport class ReadableStreamPolyfill<T> extends WSPReadableStream<T> implements ReadableStream {}\n"],"file":"readable-stream.js"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.encodeImageToStreamNode = encodeImageToStreamNode;
|
|
9
|
+
exports.encodeImageNode = encodeImageNode;
|
|
10
|
+
|
|
11
|
+
var _savePixels = _interopRequireDefault(require("save-pixels"));
|
|
12
|
+
|
|
13
|
+
var _ndarray = _interopRequireDefault(require("ndarray"));
|
|
14
|
+
|
|
15
|
+
var _toArrayBuffer = require("../buffer/to-array-buffer.node");
|
|
16
|
+
|
|
17
|
+
function encodeImageToStreamNode(image, options) {
|
|
18
|
+
const type = options.type ? options.type.replace('image/', '') : 'jpeg';
|
|
19
|
+
const pixels = (0, _ndarray.default)(image.data, [image.width, image.height, 4], [4, image.width * 4, 1], 0);
|
|
20
|
+
return (0, _savePixels.default)(pixels, type, options);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function encodeImageNode(image, options) {
|
|
24
|
+
const imageStream = encodeImageToStreamNode(image, options);
|
|
25
|
+
return new Promise(resolve => {
|
|
26
|
+
const buffers = [];
|
|
27
|
+
imageStream.on('data', buffer => buffers.push(buffer));
|
|
28
|
+
imageStream.on('end', () => {
|
|
29
|
+
const buffer = Buffer.concat(buffers);
|
|
30
|
+
resolve((0, _toArrayBuffer.bufferToArrayBuffer)(buffer));
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=encode-image.node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/node/images/encode-image.node.ts"],"names":["encodeImageToStreamNode","image","options","type","replace","pixels","data","width","height","encodeImageNode","imageStream","Promise","resolve","buffers","on","buffer","push","Buffer","concat"],"mappings":";;;;;;;;;;AAEA;;AACA;;AACA;;AAYO,SAASA,uBAAT,CACLC,KADK,EAELC,OAFK,EAGL;AAEA,QAAMC,IAAI,GAAGD,OAAO,CAACC,IAAR,GAAeD,OAAO,CAACC,IAAR,CAAaC,OAAb,CAAqB,QAArB,EAA+B,EAA/B,CAAf,GAAoD,MAAjE;AACA,QAAMC,MAAM,GAAG,sBAAQJ,KAAK,CAACK,IAAd,EAAoB,CAACL,KAAK,CAACM,KAAP,EAAcN,KAAK,CAACO,MAApB,EAA4B,CAA5B,CAApB,EAAoD,CAAC,CAAD,EAAIP,KAAK,CAACM,KAAN,GAAc,CAAlB,EAAqB,CAArB,CAApD,EAA6E,CAA7E,CAAf;AAGA,SAAO,yBAAWF,MAAX,EAAmBF,IAAnB,EAAyBD,OAAzB,CAAP;AACD;;AAEM,SAASO,eAAT,CAAyBR,KAAzB,EAAgCC,OAAhC,EAAyC;AAC9C,QAAMQ,WAAW,GAAGV,uBAAuB,CAACC,KAAD,EAAQC,OAAR,CAA3C;AAEA,SAAO,IAAIS,OAAJ,CAAaC,OAAD,IAAa;AAC9B,UAAMC,OAAc,GAAG,EAAvB;AACAH,IAAAA,WAAW,CAACI,EAAZ,CAAe,MAAf,EAAwBC,MAAD,IAAYF,OAAO,CAACG,IAAR,CAAaD,MAAb,CAAnC;AAEAL,IAAAA,WAAW,CAACI,EAAZ,CAAe,KAAf,EAAsB,MAAM;AAC1B,YAAMC,MAAM,GAAGE,MAAM,CAACC,MAAP,CAAcL,OAAd,CAAf;AACAD,MAAAA,OAAO,CAAC,wCAAoBG,MAApB,CAAD,CAAP;AACD,KAHD;AAID,GARM,CAAP;AASD","sourcesContent":["// Use stackgl modules for DOM-less reading and writing of images\n\nimport savePixels from 'save-pixels';\nimport ndarray from 'ndarray';\nimport {bufferToArrayBuffer} from '../buffer/to-array-buffer.node';\n\n/**\n * Returns data bytes representing a compressed image in PNG or JPG format,\n * This data can be saved using file system (f) methods or\n * used in a request.\n * @param image to save\n * @param options\n * @param options.type='png' - png, jpg or image/png, image/jpg are valid\n * @param options.dataURI - Whether to include a data URI header\n * @return {*} bytes\n */\nexport function encodeImageToStreamNode(\n image: {data: any; width: number; height: number},\n options: {type?: string; dataURI?: string}\n) {\n // Support MIME type strings\n const type = options.type ? options.type.replace('image/', '') : 'jpeg';\n const pixels = ndarray(image.data, [image.width, image.height, 4], [4, image.width * 4, 1], 0);\n\n // Note: savePixels returns a stream\n return savePixels(pixels, type, options);\n}\n\nexport function encodeImageNode(image, options) {\n const imageStream = encodeImageToStreamNode(image, options);\n\n return new Promise((resolve) => {\n const buffers: any[] = [];\n imageStream.on('data', (buffer) => buffers.push(buffer));\n // TODO - convert to arraybuffer?\n imageStream.on('end', () => {\n const buffer = Buffer.concat(buffers);\n resolve(bufferToArrayBuffer(buffer));\n });\n });\n}\n"],"file":"encode-image.node.js"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.parseImageNode = parseImageNode;
|
|
9
|
+
|
|
10
|
+
var _getPixels = _interopRequireDefault(require("get-pixels"));
|
|
11
|
+
|
|
12
|
+
var _assert = require("../../utils/assert");
|
|
13
|
+
|
|
14
|
+
var _util = _interopRequireDefault(require("util"));
|
|
15
|
+
|
|
16
|
+
async function parseImageNode(arrayBuffer, mimeType) {
|
|
17
|
+
(0, _assert.assert)(mimeType, 'MIMEType is required to parse image under Node.js');
|
|
18
|
+
|
|
19
|
+
const getPixelsAsync = _util.default.promisify(_getPixels.default);
|
|
20
|
+
|
|
21
|
+
const buffer = arrayBuffer instanceof Buffer ? arrayBuffer : Buffer.from(arrayBuffer);
|
|
22
|
+
const ndarray = await getPixelsAsync(buffer, mimeType);
|
|
23
|
+
const shape = [...ndarray.shape];
|
|
24
|
+
const layers = ndarray.shape.length === 4 ? ndarray.shape.shift() : 1;
|
|
25
|
+
return {
|
|
26
|
+
shape,
|
|
27
|
+
data: ndarray.data,
|
|
28
|
+
width: ndarray.shape[0],
|
|
29
|
+
height: ndarray.shape[1],
|
|
30
|
+
components: ndarray.shape[2],
|
|
31
|
+
layers
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=parse-image.node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/node/images/parse-image.node.ts"],"names":["parseImageNode","arrayBuffer","mimeType","getPixelsAsync","util","promisify","getPixels","buffer","Buffer","from","ndarray","shape","layers","length","shift","data","width","height","components"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AAYO,eAAeA,cAAf,CAA8BC,WAA9B,EAAwDC,QAAxD,EAA4F;AACjG,sBAAOA,QAAP,EAAiB,mDAAjB;;AAIA,QAAMC,cAAc,GAAGC,cAAKC,SAAL,CAAeC,kBAAf,CAAvB;;AAEA,QAAMC,MAAM,GAAGN,WAAW,YAAYO,MAAvB,GAAgCP,WAAhC,GAA8CO,MAAM,CAACC,IAAP,CAAYR,WAAZ,CAA7D;AAEA,QAAMS,OAAO,GAAG,MAAMP,cAAc,CAACI,MAAD,EAASL,QAAT,CAApC;AAEA,QAAMS,KAAK,GAAG,CAAC,GAAGD,OAAO,CAACC,KAAZ,CAAd;AACA,QAAMC,MAAM,GAAGF,OAAO,CAACC,KAAR,CAAcE,MAAd,KAAyB,CAAzB,GAA6BH,OAAO,CAACC,KAAR,CAAcG,KAAd,EAA7B,GAAqD,CAApE;AAGA,SAAO;AACLH,IAAAA,KADK;AAELI,IAAAA,IAAI,EAAEL,OAAO,CAACK,IAFT;AAGLC,IAAAA,KAAK,EAAEN,OAAO,CAACC,KAAR,CAAc,CAAd,CAHF;AAILM,IAAAA,MAAM,EAAEP,OAAO,CAACC,KAAR,CAAc,CAAd,CAJH;AAKLO,IAAAA,UAAU,EAAER,OAAO,CAACC,KAAR,CAAc,CAAd,CALP;AAMLC,IAAAA;AANK,GAAP;AAQD","sourcesContent":["import getPixels from 'get-pixels';\nimport {assert} from '../../utils/assert';\nimport util from 'util';\n\n// Note: These types are also defined in @loaders.gl/images and need to be kept in sync\ntype NDArray = {\n shape: number[];\n data: Uint8Array;\n width: number;\n height: number;\n components: number;\n layers: number[];\n};\n\nexport async function parseImageNode(arrayBuffer: ArrayBuffer, mimeType: string): Promise<NDArray> {\n assert(mimeType, 'MIMEType is required to parse image under Node.js');\n\n // TODO - check if getPixels callback is asynchronous if provided with buffer input\n // if not, parseImage can be a sync function\n const getPixelsAsync = util.promisify(getPixels);\n\n const buffer = arrayBuffer instanceof Buffer ? arrayBuffer : Buffer.from(arrayBuffer);\n\n const ndarray = await getPixelsAsync(buffer, mimeType);\n\n const shape = [...ndarray.shape];\n const layers = ndarray.shape.length === 4 ? ndarray.shape.shift() : 1;\n\n // extract width/height etc\n return {\n shape,\n data: ndarray.data,\n width: ndarray.shape[0],\n height: ndarray.shape[1],\n components: ndarray.shape[2],\n layers\n };\n}\n"],"file":"parse-image.node.js"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.allSettled = allSettled;
|
|
7
|
+
exports.FULFILLED_STATUS = exports.REJECTED_STATUS = void 0;
|
|
8
|
+
const REJECTED_STATUS = 'rejected';
|
|
9
|
+
exports.REJECTED_STATUS = REJECTED_STATUS;
|
|
10
|
+
const FULFILLED_STATUS = 'fulfilled';
|
|
11
|
+
exports.FULFILLED_STATUS = FULFILLED_STATUS;
|
|
12
|
+
|
|
13
|
+
function allSettled(promises) {
|
|
14
|
+
const mappedPromises = promises.map(promise => {
|
|
15
|
+
return promise.then(value => {
|
|
16
|
+
return {
|
|
17
|
+
status: FULFILLED_STATUS,
|
|
18
|
+
value
|
|
19
|
+
};
|
|
20
|
+
}).catch(reason => {
|
|
21
|
+
return {
|
|
22
|
+
status: REJECTED_STATUS,
|
|
23
|
+
reason
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
return Promise.all(mappedPromises);
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=all-settled.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/promise/all-settled.ts"],"names":["REJECTED_STATUS","FULFILLED_STATUS","allSettled","promises","mappedPromises","map","promise","then","value","status","catch","reason","Promise","all"],"mappings":";;;;;;;AAAO,MAAMA,eAAe,GAAG,UAAxB;;AACA,MAAMC,gBAAgB,GAAG,WAAzB;;;AAQA,SAASC,UAAT,CAAoBC,QAApB,EAA4D;AACjE,QAAMC,cAAc,GAAGD,QAAQ,CAACE,GAAT,CAAcC,OAAD,IAAa;AAC/C,WAAOA,OAAO,CACXC,IADI,CACEC,KAAD,IAAW;AACf,aAAO;AAACC,QAAAA,MAAM,EAAER,gBAAT;AAA2BO,QAAAA;AAA3B,OAAP;AACD,KAHI,EAIJE,KAJI,CAIGC,MAAD,IAAY;AACjB,aAAO;AAACF,QAAAA,MAAM,EAAET,eAAT;AAA0BW,QAAAA;AAA1B,OAAP;AACD,KANI,CAAP;AAOD,GARsB,CAAvB;AASA,SAAOC,OAAO,CAACC,GAAR,CAAYT,cAAZ,CAAP;AACD","sourcesContent":["export const REJECTED_STATUS = 'rejected';\nexport const FULFILLED_STATUS = 'fulfilled';\n\n/**\n * Handle list of promises and return all values regardless of results.\n * Polyfill for Promise.allSettled() method.\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled\n * @param promises\n */\nexport function allSettled(promises: Promise<any>[]): Promise<any> {\n const mappedPromises = promises.map((promise) => {\n return promise\n .then((value) => {\n return {status: FULFILLED_STATUS, value};\n })\n .catch((reason) => {\n return {status: REJECTED_STATUS, reason};\n });\n });\n return Promise.all(mappedPromises);\n}\n"],"file":"all-settled.js"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.assert = assert;
|
|
7
|
+
|
|
8
|
+
function assert(condition, message) {
|
|
9
|
+
if (!condition) {
|
|
10
|
+
throw new Error("@loaders.gl/polyfills assertion ".concat(message));
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=assert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/assert.ts"],"names":["assert","condition","message","Error"],"mappings":";;;;;;;AAAO,SAASA,MAAT,CAAgBC,SAAhB,EAAgCC,OAAhC,EAAwD;AAC7D,MAAI,CAACD,SAAL,EAAgB;AACd,UAAM,IAAIE,KAAJ,2CAA6CD,OAA7C,EAAN;AACD;AACF","sourcesContent":["export function assert(condition: any, message?: string): void {\n if (!condition) {\n throw new Error(`@loaders.gl/polyfills assertion ${message}`);\n }\n}\n"],"file":"assert.js"}
|