@loaders.gl/core 3.4.14 → 3.4.15
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/dist.min.js +106 -104
- package/dist/es5/bundle.js +1 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/index.js +55 -55
- package/dist/es5/iterators/batch-iterators/timed-batch-iterator.js +14 -86
- package/dist/es5/iterators/batch-iterators/timed-batch-iterator.js.map +1 -1
- package/dist/es5/iterators/make-iterator/make-array-buffer-iterator.js +17 -33
- package/dist/es5/iterators/make-iterator/make-array-buffer-iterator.js.map +1 -1
- package/dist/es5/iterators/make-iterator/make-blob-iterator.js +10 -39
- package/dist/es5/iterators/make-iterator/make-blob-iterator.js.map +1 -1
- package/dist/es5/iterators/make-iterator/make-iterator.js +1 -1
- package/dist/es5/iterators/make-iterator/make-iterator.js.map +1 -1
- package/dist/es5/iterators/make-iterator/make-stream-iterator.js +24 -119
- package/dist/es5/iterators/make-iterator/make-stream-iterator.js.map +1 -1
- package/dist/es5/iterators/make-iterator/make-string-iterator.js +11 -30
- package/dist/es5/iterators/make-iterator/make-string-iterator.js.map +1 -1
- package/dist/es5/iterators/make-stream/make-dom-stream.js +22 -54
- package/dist/es5/iterators/make-stream/make-dom-stream.js.map +1 -1
- package/dist/es5/iterators/make-stream/make-node-stream.js +50 -152
- package/dist/es5/iterators/make-stream/make-node-stream.js.map +1 -1
- package/dist/es5/javascript-utils/is-type.js +18 -56
- package/dist/es5/javascript-utils/is-type.js.map +1 -1
- package/dist/es5/lib/api/encode.js +54 -203
- package/dist/es5/lib/api/encode.js.map +1 -1
- package/dist/es5/lib/api/load-in-batches.js +9 -41
- package/dist/es5/lib/api/load-in-batches.js.map +1 -1
- package/dist/es5/lib/api/load.js +15 -48
- package/dist/es5/lib/api/load.js.map +1 -1
- package/dist/es5/lib/api/loader-options.js +2 -2
- package/dist/es5/lib/api/parse-in-batches.js +71 -259
- package/dist/es5/lib/api/parse-in-batches.js.map +1 -1
- package/dist/es5/lib/api/parse-sync.js +9 -11
- package/dist/es5/lib/api/parse-sync.js.map +1 -1
- package/dist/es5/lib/api/parse.js +62 -125
- package/dist/es5/lib/api/parse.js.map +1 -1
- package/dist/es5/lib/api/register-loaders.js +8 -25
- package/dist/es5/lib/api/register-loaders.js.map +1 -1
- package/dist/es5/lib/api/save.js +4 -28
- package/dist/es5/lib/api/save.js.map +1 -1
- package/dist/es5/lib/api/select-loader.js +76 -170
- package/dist/es5/lib/api/select-loader.js.map +1 -1
- package/dist/es5/lib/fetch/fetch-error-message.js +13 -44
- package/dist/es5/lib/fetch/fetch-error-message.js.map +1 -1
- package/dist/es5/lib/fetch/fetch-file.js +10 -37
- package/dist/es5/lib/fetch/fetch-file.js.map +1 -1
- package/dist/es5/lib/fetch/read-array-buffer.js +19 -65
- package/dist/es5/lib/fetch/read-array-buffer.js.map +1 -1
- package/dist/es5/lib/fetch/read-file.js +2 -2
- package/dist/es5/lib/fetch/read-file.js.map +1 -1
- package/dist/es5/lib/fetch/write-file.js +8 -29
- package/dist/es5/lib/fetch/write-file.js.map +1 -1
- package/dist/es5/lib/filesystems/browser-filesystem.js +78 -227
- package/dist/es5/lib/filesystems/browser-filesystem.js.map +1 -1
- package/dist/es5/lib/filesystems/read-array-buffer.js +6 -33
- package/dist/es5/lib/filesystems/read-array-buffer.js.map +1 -1
- package/dist/es5/lib/init.js +1 -1
- package/dist/es5/lib/init.js.map +1 -1
- package/dist/es5/lib/loader-utils/check-errors.js +11 -39
- package/dist/es5/lib/loader-utils/check-errors.js.map +1 -1
- package/dist/es5/lib/loader-utils/get-data.js +62 -187
- package/dist/es5/lib/loader-utils/get-data.js.map +1 -1
- package/dist/es5/lib/loader-utils/get-fetch-function.js +3 -5
- package/dist/es5/lib/loader-utils/get-fetch-function.js.map +1 -1
- package/dist/es5/lib/loader-utils/loader-context.js +8 -12
- package/dist/es5/lib/loader-utils/loader-context.js.map +1 -1
- package/dist/es5/lib/loader-utils/loggers.js +37 -67
- package/dist/es5/lib/loader-utils/loggers.js.map +1 -1
- package/dist/es5/lib/loader-utils/normalize-loader.js +9 -9
- package/dist/es5/lib/loader-utils/normalize-loader.js.map +1 -1
- package/dist/es5/lib/loader-utils/option-defaults.js +2 -2
- package/dist/es5/lib/loader-utils/option-defaults.js.map +1 -1
- package/dist/es5/lib/loader-utils/option-utils.js +43 -59
- package/dist/es5/lib/loader-utils/option-utils.js.map +1 -1
- package/dist/es5/lib/progress/fetch-progress.js +49 -125
- package/dist/es5/lib/progress/fetch-progress.js.map +1 -1
- package/dist/es5/lib/utils/log.js +1 -1
- package/dist/es5/lib/utils/log.js.map +1 -1
- package/dist/es5/lib/utils/mime-type-utils.js +4 -4
- package/dist/es5/lib/utils/mime-type-utils.js.map +1 -1
- package/dist/es5/lib/utils/resource-utils.js +8 -8
- package/dist/es5/lib/utils/resource-utils.js.map +1 -1
- package/dist/es5/lib/utils/response-utils.js +71 -171
- package/dist/es5/lib/utils/response-utils.js.map +1 -1
- package/dist/es5/lib/utils/url-utils.js +2 -2
- package/dist/es5/lib/utils/url-utils.js.map +1 -1
- package/dist/es5/null-loader.js +14 -100
- package/dist/es5/null-loader.js.map +1 -1
- package/dist/esm/lib/init.js +1 -1
- package/dist/esm/null-loader.js +1 -1
- package/dist/null-worker.js +1 -1
- package/package.json +5 -5
- package/src/.DS_Store +0 -0
- package/src/lib/.DS_Store +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"make-node-stream.js","names":["Stream","_interopRequireWildcard","require","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","
|
|
1
|
+
{"version":3,"file":"make-node-stream.js","names":["Stream","_interopRequireWildcard","require","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","_Readable","Readable","makeStream","source","options","iterator","Symbol","asyncIterator","AsyncIterableReadable","constructor","it","_defineProperty2","_iterator","_pulling","_bytesMode","objectMode","_read","size","_pull","_destroy","error","cb","_this$_iterator","_this$_iterator$throw","throw","_this$_iterator2","_this$_iterator2$retu","return","_r","bm","r","readable","next","done","ArrayBuffer","isView","value","byteLength","push","Uint8Array","_it$return"],"sources":["../../../../src/iterators/make-stream/make-node-stream.ts"],"sourcesContent":["import type {ReadableOptions} from 'stream';\nimport * as Stream from 'stream';\n\nclass _Readable {}\n\ntype ReadableType = Stream.Readable | _Readable;\nconst Readable = Stream.Readable || _Readable;\n\nexport type MakeStreamOptions = ReadableOptions;\n\n/** Builds a node stream from an iterator */\nexport function makeStream<ArrayBuffer>(\n source: Iterable<ArrayBuffer> | AsyncIterable<ArrayBuffer>,\n options?: ReadableOptions\n): ReadableType {\n const iterator = source[Symbol.asyncIterator]\n ? source[Symbol.asyncIterator]()\n : source[Symbol.iterator]();\n return new AsyncIterableReadable(iterator, options);\n}\n\nclass AsyncIterableReadable extends Readable {\n private _pulling: boolean;\n private _bytesMode: boolean;\n private _iterator: AsyncIterator<ArrayBuffer>;\n\n constructor(it: AsyncIterator<ArrayBuffer>, options?: ReadableOptions) {\n super(options);\n this._iterator = it;\n this._pulling = false;\n this._bytesMode = !options || !options.objectMode;\n }\n\n async _read(size: number): Promise<void> {\n if (!this._pulling) {\n this._pulling = true;\n this._pulling = await this._pull(size, this._iterator);\n }\n }\n\n async _destroy(error: Error | null, cb: (e: Error | null) => void): Promise<void> {\n if (!this._iterator) {\n return;\n }\n if (error) {\n await this._iterator?.throw?.(error);\n } else {\n await this._iterator?.return?.(error);\n }\n cb?.(null);\n }\n\n // eslint-disable-next-line complexity\n private async _pull(size: number, it: AsyncIterator<ArrayBuffer>): Promise<boolean> {\n const bm = this._bytesMode;\n let r: IteratorResult<ArrayBuffer> | null = null;\n // while (this.readable && !(r = await it.next(bm ? size : null)).done) {\n while (this.readable && !(r = await it.next()).done) {\n if (size !== null) {\n size -= bm && ArrayBuffer.isView(r.value) ? r.value.byteLength : 1;\n }\n if (!this.push(new Uint8Array(r.value)) || size <= 0) {\n break;\n }\n }\n if ((r?.done || !this.readable) && (this.push(null) || true)) {\n it?.return?.();\n }\n return !this.readable;\n }\n}\n"],"mappings":";;;;;;;;AACA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAAiC,SAAAC,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAH,wBAAAO,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAX,GAAA,QAAAW,GAAA,kBAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAd,GAAA,EAAAW,GAAA,SAAAI,IAAA,GAAAR,qBAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAV,GAAA,EAAAW,GAAA,cAAAI,IAAA,KAAAA,IAAA,CAAAV,GAAA,IAAAU,IAAA,CAAAC,GAAA,KAAAR,MAAA,CAAAC,cAAA,CAAAH,MAAA,EAAAK,GAAA,EAAAI,IAAA,YAAAT,MAAA,CAAAK,GAAA,IAAAX,GAAA,CAAAW,GAAA,SAAAL,MAAA,CAAAJ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AI,CAACO,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,EAAE;MAAA,IAAAE,UAAA;MAC5D9B,EAAE,aAAFA,EAAE,wBAAA8B,UAAA,GAAF9B,EAAE,CAAEiB,MAAM,cAAAa,UAAA,uBAAVA,UAAA,CAAA3C,IAAA,CAAAa,EAAa,CAAC;IAChB;IACA,OAAO,CAAC,IAAI,CAACqB,QAAQ;EACvB;AACF"}
|
|
@@ -1,79 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.isWritableStream = exports.isWritableNodeStream = exports.isWritableDOMStream = exports.isResponse = exports.isReadableStream = exports.isReadableNodeStream = exports.isReadableDOMStream = exports.isPureObject = exports.isPromise = exports.isObject = exports.isIterator = exports.isIterable = exports.isFile = exports.isBuffer = exports.isBlob = exports.isAsyncIterable = void 0;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
12
|
-
var isFunction = function isFunction(x) {
|
|
13
|
-
return typeof x === 'function';
|
|
14
|
-
};
|
|
15
|
-
var isObject = function isObject(x) {
|
|
16
|
-
return x !== null && (0, _typeof2.default)(x) === 'object';
|
|
17
|
-
};
|
|
7
|
+
const isBoolean = x => typeof x === 'boolean';
|
|
8
|
+
const isFunction = x => typeof x === 'function';
|
|
9
|
+
const isObject = x => x !== null && typeof x === 'object';
|
|
18
10
|
exports.isObject = isObject;
|
|
19
|
-
|
|
20
|
-
return isObject(x) && x.constructor === {}.constructor;
|
|
21
|
-
};
|
|
11
|
+
const isPureObject = x => isObject(x) && x.constructor === {}.constructor;
|
|
22
12
|
exports.isPureObject = isPureObject;
|
|
23
|
-
|
|
24
|
-
return isObject(x) && isFunction(x.then);
|
|
25
|
-
};
|
|
13
|
+
const isPromise = x => isObject(x) && isFunction(x.then);
|
|
26
14
|
exports.isPromise = isPromise;
|
|
27
|
-
|
|
28
|
-
return x && typeof x[Symbol.iterator] === 'function';
|
|
29
|
-
};
|
|
15
|
+
const isIterable = x => x && typeof x[Symbol.iterator] === 'function';
|
|
30
16
|
exports.isIterable = isIterable;
|
|
31
|
-
|
|
32
|
-
return x && typeof x[Symbol.asyncIterator] === 'function';
|
|
33
|
-
};
|
|
17
|
+
const isAsyncIterable = x => x && typeof x[Symbol.asyncIterator] === 'function';
|
|
34
18
|
exports.isAsyncIterable = isAsyncIterable;
|
|
35
|
-
|
|
36
|
-
return x && isFunction(x.next);
|
|
37
|
-
};
|
|
19
|
+
const isIterator = x => x && isFunction(x.next);
|
|
38
20
|
exports.isIterator = isIterator;
|
|
39
|
-
|
|
40
|
-
return typeof Response !== 'undefined' && x instanceof Response || x && x.arrayBuffer && x.text && x.json;
|
|
41
|
-
};
|
|
21
|
+
const isResponse = x => typeof Response !== 'undefined' && x instanceof Response || x && x.arrayBuffer && x.text && x.json;
|
|
42
22
|
exports.isResponse = isResponse;
|
|
43
|
-
|
|
44
|
-
return typeof File !== 'undefined' && x instanceof File;
|
|
45
|
-
};
|
|
23
|
+
const isFile = x => typeof File !== 'undefined' && x instanceof File;
|
|
46
24
|
exports.isFile = isFile;
|
|
47
|
-
|
|
48
|
-
return typeof Blob !== 'undefined' && x instanceof Blob;
|
|
49
|
-
};
|
|
25
|
+
const isBlob = x => typeof Blob !== 'undefined' && x instanceof Blob;
|
|
50
26
|
exports.isBlob = isBlob;
|
|
51
|
-
|
|
52
|
-
return x && (0, _typeof2.default)(x) === 'object' && x.isBuffer;
|
|
53
|
-
};
|
|
27
|
+
const isBuffer = x => x && typeof x === 'object' && x.isBuffer;
|
|
54
28
|
exports.isBuffer = isBuffer;
|
|
55
|
-
|
|
56
|
-
return isObject(x) && isFunction(x.abort) && isFunction(x.getWriter);
|
|
57
|
-
};
|
|
29
|
+
const isWritableDOMStream = x => isObject(x) && isFunction(x.abort) && isFunction(x.getWriter);
|
|
58
30
|
exports.isWritableDOMStream = isWritableDOMStream;
|
|
59
|
-
|
|
60
|
-
return typeof ReadableStream !== 'undefined' && x instanceof ReadableStream || isObject(x) && isFunction(x.tee) && isFunction(x.cancel) && isFunction(x.getReader);
|
|
61
|
-
};
|
|
31
|
+
const isReadableDOMStream = x => typeof ReadableStream !== 'undefined' && x instanceof ReadableStream || isObject(x) && isFunction(x.tee) && isFunction(x.cancel) && isFunction(x.getReader);
|
|
62
32
|
exports.isReadableDOMStream = isReadableDOMStream;
|
|
63
|
-
|
|
64
|
-
return isObject(x) && isFunction(x.end) && isFunction(x.write) && isBoolean(x.writable);
|
|
65
|
-
};
|
|
33
|
+
const isWritableNodeStream = x => isObject(x) && isFunction(x.end) && isFunction(x.write) && isBoolean(x.writable);
|
|
66
34
|
exports.isWritableNodeStream = isWritableNodeStream;
|
|
67
|
-
|
|
68
|
-
return isObject(x) && isFunction(x.read) && isFunction(x.pipe) && isBoolean(x.readable);
|
|
69
|
-
};
|
|
35
|
+
const isReadableNodeStream = x => isObject(x) && isFunction(x.read) && isFunction(x.pipe) && isBoolean(x.readable);
|
|
70
36
|
exports.isReadableNodeStream = isReadableNodeStream;
|
|
71
|
-
|
|
72
|
-
return isReadableDOMStream(x) || isReadableNodeStream(x);
|
|
73
|
-
};
|
|
37
|
+
const isReadableStream = x => isReadableDOMStream(x) || isReadableNodeStream(x);
|
|
74
38
|
exports.isReadableStream = isReadableStream;
|
|
75
|
-
|
|
76
|
-
return isWritableDOMStream(x) || isWritableNodeStream(x);
|
|
77
|
-
};
|
|
39
|
+
const isWritableStream = x => isWritableDOMStream(x) || isWritableNodeStream(x);
|
|
78
40
|
exports.isWritableStream = isWritableStream;
|
|
79
41
|
//# sourceMappingURL=is-type.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-type.js","names":["isBoolean","x","isFunction","isObject","
|
|
1
|
+
{"version":3,"file":"is-type.js","names":["isBoolean","x","isFunction","isObject","exports","isPureObject","constructor","isPromise","then","isIterable","Symbol","iterator","isAsyncIterable","asyncIterator","isIterator","next","isResponse","Response","arrayBuffer","text","json","isFile","File","isBlob","Blob","isBuffer","isWritableDOMStream","abort","getWriter","isReadableDOMStream","ReadableStream","tee","cancel","getReader","isWritableNodeStream","end","write","writable","isReadableNodeStream","read","pipe","readable","isReadableStream","isWritableStream"],"sources":["../../../src/javascript-utils/is-type.ts"],"sourcesContent":["import type {Readable} from 'stream';\n\n/** A DOM or Node readable stream */\nexport type ReadableStreamType = ReadableStream | Readable;\n\nconst isBoolean: (x: any) => boolean = (x) => typeof x === 'boolean';\nconst isFunction: (x: any) => boolean = (x) => typeof x === 'function';\n\nexport const isObject: (x: any) => boolean = (x) => x !== null && typeof x === 'object';\nexport const isPureObject: (x: any) => boolean = (x) =>\n isObject(x) && x.constructor === {}.constructor;\nexport const isPromise: (x: any) => boolean = (x) => isObject(x) && isFunction(x.then);\n\nexport const isIterable: (x: any) => boolean = (x) => x && typeof x[Symbol.iterator] === 'function';\nexport const isAsyncIterable: (x: any) => boolean = (x) =>\n x && typeof x[Symbol.asyncIterator] === 'function';\nexport const isIterator: (x: any) => boolean = (x) => x && isFunction(x.next);\n\nexport const isResponse: (x: any) => boolean = (x) =>\n (typeof Response !== 'undefined' && x instanceof Response) ||\n (x && x.arrayBuffer && x.text && x.json);\n\nexport const isFile: (x: any) => boolean = (x) => typeof File !== 'undefined' && x instanceof File;\nexport const isBlob: (x: any) => boolean = (x) => typeof Blob !== 'undefined' && x instanceof Blob;\n\n/** Check for Node.js `Buffer` without triggering bundler to include buffer polyfill */\nexport const isBuffer: (x: any) => boolean = (x) => x && typeof x === 'object' && x.isBuffer;\n\nexport const isWritableDOMStream: (x: any) => boolean = (x) =>\n isObject(x) && isFunction(x.abort) && isFunction(x.getWriter);\n\nexport const isReadableDOMStream: (x: any) => boolean = (x) =>\n (typeof ReadableStream !== 'undefined' && x instanceof ReadableStream) ||\n (isObject(x) && isFunction(x.tee) && isFunction(x.cancel) && isFunction(x.getReader));\n// Not implemented in Firefox: && isFunction(x.pipeTo)\n\nexport const isWritableNodeStream: (x: any) => boolean = (x) =>\n isObject(x) && isFunction(x.end) && isFunction(x.write) && isBoolean(x.writable);\nexport const isReadableNodeStream: (x: any) => boolean = (x) =>\n isObject(x) && isFunction(x.read) && isFunction(x.pipe) && isBoolean(x.readable);\nexport const isReadableStream: (x: any) => boolean = (x) =>\n isReadableDOMStream(x) || isReadableNodeStream(x);\nexport const isWritableStream: (x: any) => boolean = (x) =>\n isWritableDOMStream(x) || isWritableNodeStream(x);\n"],"mappings":";;;;;;AAKA,MAAMA,SAA8B,GAAIC,CAAC,IAAK,OAAOA,CAAC,KAAK,SAAS;AACpE,MAAMC,UAA+B,GAAID,CAAC,IAAK,OAAOA,CAAC,KAAK,UAAU;AAE/D,MAAME,QAA6B,GAAIF,CAAC,IAAKA,CAAC,KAAK,IAAI,IAAI,OAAOA,CAAC,KAAK,QAAQ;AAACG,OAAA,CAAAD,QAAA,GAAAA,QAAA;AACjF,MAAME,YAAiC,GAAIJ,CAAC,IACjDE,QAAQ,CAACF,CAAC,CAAC,IAAIA,CAAC,CAACK,WAAW,KAAK,CAAC,CAAC,CAACA,WAAW;AAACF,OAAA,CAAAC,YAAA,GAAAA,YAAA;AAC3C,MAAME,SAA8B,GAAIN,CAAC,IAAKE,QAAQ,CAACF,CAAC,CAAC,IAAIC,UAAU,CAACD,CAAC,CAACO,IAAI,CAAC;AAACJ,OAAA,CAAAG,SAAA,GAAAA,SAAA;AAEhF,MAAME,UAA+B,GAAIR,CAAC,IAAKA,CAAC,IAAI,OAAOA,CAAC,CAACS,MAAM,CAACC,QAAQ,CAAC,KAAK,UAAU;AAACP,OAAA,CAAAK,UAAA,GAAAA,UAAA;AAC7F,MAAMG,eAAoC,GAAIX,CAAC,IACpDA,CAAC,IAAI,OAAOA,CAAC,CAACS,MAAM,CAACG,aAAa,CAAC,KAAK,UAAU;AAACT,OAAA,CAAAQ,eAA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,IAAI9B,UAAU,CAACD,CAAC,CAACgC,SAAS,CAAE;AAAC7B,OAAA,CAAAyB,mBAAA,GAAAA,mBAAA;AAGjF,MAAMK,oBAAyC,GAAIjC,CAAC,IACzDE,QAAQ,CAACF,CAAC,CAAC,IAAIC,UAAU,CAACD,CAAC,CAACkC,GAAG,CAAC,IAAIjC,UAAU,CAACD,CAAC,CAACmC,KAAK,CAAC,IAAIpC,SAAS,CAACC,CAAC,CAACoC,QAAQ,CAAC;AAACjC,OAAA,CAAA8B,oBAAA,GAAAA,oBAAA;AAC5E,MAAMI,oBAAyC,GAAIrC,CAAC,IACzDE,QAAQ,CAACF,CAAC,CAAC,IAAIC,UAAU,CAACD,CAAC,CAACsC,IAAI,CAAC,IAAIrC,UAAU,CAACD,CAAC,CAACuC,IAAI,CAAC,IAAIxC,SAAS,CAACC,CAAC,CAACwC,QAAQ,CAAC;AAACrC,OAAA,CAAAkC,oBAAA,GAAAA,oBAAA;AAC5E,MAAMI,gBAAqC,GAAIzC,CAAC,IACrD4B,mBAAmB,CAAC5B,CAAC,CAAC,IAAIqC,oBAAoB,CAACrC,CAAC,CAAC;AAACG,OAAA,CAAAsC,gBAAA,GAAAA,gBAAA;AAC7C,MAAMC,gBAAqC,GAAI1C,CAAC,IACrDyB,mBAAmB,CAACzB,CAAC,CAAC,IAAIiC,oBAAoB,CAACjC,CAAC,CAAC;AAACG,OAAA,CAAAuC,gBAAA,GAAAA,gBAAA"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
@@ -9,146 +8,46 @@ exports.encodeInBatches = encodeInBatches;
|
|
|
9
8
|
exports.encodeSync = encodeSync;
|
|
10
9
|
exports.encodeText = encodeText;
|
|
11
10
|
exports.encodeURLtoURL = encodeURLtoURL;
|
|
12
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
13
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
14
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
15
11
|
var _loaderUtils = require("@loaders.gl/loader-utils");
|
|
16
12
|
var _workerUtils = require("@loaders.gl/worker-utils");
|
|
17
13
|
var _writeFile = require("../fetch/write-file");
|
|
18
14
|
var _fetchFile = require("../fetch/fetch-file");
|
|
19
15
|
var _loaderOptions = require("./loader-options");
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
return _context.abrupt("return", writer.encodeSync(data, options));
|
|
58
|
-
case 12:
|
|
59
|
-
if (!writer.encodeText) {
|
|
60
|
-
_context.next = 18;
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
_context.t0 = new TextEncoder();
|
|
64
|
-
_context.next = 16;
|
|
65
|
-
return writer.encodeText(data, options);
|
|
66
|
-
case 16:
|
|
67
|
-
_context.t1 = _context.sent;
|
|
68
|
-
return _context.abrupt("return", _context.t0.encode.call(_context.t0, _context.t1));
|
|
69
|
-
case 18:
|
|
70
|
-
if (!writer.encodeInBatches) {
|
|
71
|
-
_context.next = 50;
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
batches = encodeInBatches(data, writer, options);
|
|
75
|
-
chunks = [];
|
|
76
|
-
_iteratorAbruptCompletion = false;
|
|
77
|
-
_didIteratorError = false;
|
|
78
|
-
_context.prev = 23;
|
|
79
|
-
_iterator = _asyncIterator(batches);
|
|
80
|
-
case 25:
|
|
81
|
-
_context.next = 27;
|
|
82
|
-
return _iterator.next();
|
|
83
|
-
case 27:
|
|
84
|
-
if (!(_iteratorAbruptCompletion = !(_step = _context.sent).done)) {
|
|
85
|
-
_context.next = 33;
|
|
86
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
batch = _step.value;
|
|
89
|
-
chunks.push(batch);
|
|
90
|
-
case 30:
|
|
91
|
-
_iteratorAbruptCompletion = false;
|
|
92
|
-
_context.next = 25;
|
|
93
|
-
break;
|
|
94
|
-
case 33:
|
|
95
|
-
_context.next = 39;
|
|
96
|
-
break;
|
|
97
|
-
case 35:
|
|
98
|
-
_context.prev = 35;
|
|
99
|
-
_context.t2 = _context["catch"](23);
|
|
100
|
-
_didIteratorError = true;
|
|
101
|
-
_iteratorError = _context.t2;
|
|
102
|
-
case 39:
|
|
103
|
-
_context.prev = 39;
|
|
104
|
-
_context.prev = 40;
|
|
105
|
-
if (!(_iteratorAbruptCompletion && _iterator.return != null)) {
|
|
106
|
-
_context.next = 44;
|
|
107
|
-
break;
|
|
108
|
-
}
|
|
109
|
-
_context.next = 44;
|
|
110
|
-
return _iterator.return();
|
|
111
|
-
case 44:
|
|
112
|
-
_context.prev = 44;
|
|
113
|
-
if (!_didIteratorError) {
|
|
114
|
-
_context.next = 47;
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
throw _iteratorError;
|
|
118
|
-
case 47:
|
|
119
|
-
return _context.finish(44);
|
|
120
|
-
case 48:
|
|
121
|
-
return _context.finish(39);
|
|
122
|
-
case 49:
|
|
123
|
-
return _context.abrupt("return", _loaderUtils.concatenateArrayBuffers.apply(void 0, chunks));
|
|
124
|
-
case 50:
|
|
125
|
-
if (!(!_loaderUtils.isBrowser && writer.encodeURLtoURL)) {
|
|
126
|
-
_context.next = 62;
|
|
127
|
-
break;
|
|
128
|
-
}
|
|
129
|
-
tmpInputFilename = getTemporaryFilename('input');
|
|
130
|
-
_context.next = 54;
|
|
131
|
-
return (0, _writeFile.writeFile)(tmpInputFilename, data);
|
|
132
|
-
case 54:
|
|
133
|
-
tmpOutputFilename = getTemporaryFilename('output');
|
|
134
|
-
_context.next = 57;
|
|
135
|
-
return encodeURLtoURL(tmpInputFilename, tmpOutputFilename, writer, options);
|
|
136
|
-
case 57:
|
|
137
|
-
outputFilename = _context.sent;
|
|
138
|
-
_context.next = 60;
|
|
139
|
-
return (0, _fetchFile.fetchFile)(outputFilename);
|
|
140
|
-
case 60:
|
|
141
|
-
response = _context.sent;
|
|
142
|
-
return _context.abrupt("return", response.arrayBuffer());
|
|
143
|
-
case 62:
|
|
144
|
-
throw new Error('Writer could not encode data');
|
|
145
|
-
case 63:
|
|
146
|
-
case "end":
|
|
147
|
-
return _context.stop();
|
|
148
|
-
}
|
|
149
|
-
}, _callee, null, [[23, 35, 39, 49], [40,, 44, 48]]);
|
|
150
|
-
}));
|
|
151
|
-
return _encode.apply(this, arguments);
|
|
16
|
+
async function encode(data, writer, options) {
|
|
17
|
+
const globalOptions = (0, _loaderOptions.getLoaderOptions)();
|
|
18
|
+
options = {
|
|
19
|
+
...globalOptions,
|
|
20
|
+
...options
|
|
21
|
+
};
|
|
22
|
+
if ((0, _loaderUtils.canEncodeWithWorker)(writer, options)) {
|
|
23
|
+
return await (0, _workerUtils.processOnWorker)(writer, data, options);
|
|
24
|
+
}
|
|
25
|
+
if (writer.encode) {
|
|
26
|
+
return await writer.encode(data, options);
|
|
27
|
+
}
|
|
28
|
+
if (writer.encodeSync) {
|
|
29
|
+
return writer.encodeSync(data, options);
|
|
30
|
+
}
|
|
31
|
+
if (writer.encodeText) {
|
|
32
|
+
return new TextEncoder().encode(await writer.encodeText(data, options));
|
|
33
|
+
}
|
|
34
|
+
if (writer.encodeInBatches) {
|
|
35
|
+
const batches = encodeInBatches(data, writer, options);
|
|
36
|
+
const chunks = [];
|
|
37
|
+
for await (const batch of batches) {
|
|
38
|
+
chunks.push(batch);
|
|
39
|
+
}
|
|
40
|
+
return (0, _loaderUtils.concatenateArrayBuffers)(...chunks);
|
|
41
|
+
}
|
|
42
|
+
if (!_loaderUtils.isBrowser && writer.encodeURLtoURL) {
|
|
43
|
+
const tmpInputFilename = getTemporaryFilename('input');
|
|
44
|
+
await (0, _writeFile.writeFile)(tmpInputFilename, data);
|
|
45
|
+
const tmpOutputFilename = getTemporaryFilename('output');
|
|
46
|
+
const outputFilename = await encodeURLtoURL(tmpInputFilename, tmpOutputFilename, writer, options);
|
|
47
|
+
const response = await (0, _fetchFile.fetchFile)(outputFilename);
|
|
48
|
+
return response.arrayBuffer();
|
|
49
|
+
}
|
|
50
|
+
throw new Error('Writer could not encode data');
|
|
152
51
|
}
|
|
153
52
|
function encodeSync(data, writer, options) {
|
|
154
53
|
if (writer.encodeSync) {
|
|
@@ -156,82 +55,34 @@ function encodeSync(data, writer, options) {
|
|
|
156
55
|
}
|
|
157
56
|
throw new Error('Writer could not synchronously encode data');
|
|
158
57
|
}
|
|
159
|
-
function encodeText(
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
return
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
if (!(writer.text && writer.encodeText)) {
|
|
169
|
-
_context2.next = 4;
|
|
170
|
-
break;
|
|
171
|
-
}
|
|
172
|
-
_context2.next = 3;
|
|
173
|
-
return writer.encodeText(data, options);
|
|
174
|
-
case 3:
|
|
175
|
-
return _context2.abrupt("return", _context2.sent);
|
|
176
|
-
case 4:
|
|
177
|
-
if (!(writer.text && (writer.encode || writer.encodeInBatches))) {
|
|
178
|
-
_context2.next = 9;
|
|
179
|
-
break;
|
|
180
|
-
}
|
|
181
|
-
_context2.next = 7;
|
|
182
|
-
return encode(data, writer, options);
|
|
183
|
-
case 7:
|
|
184
|
-
arrayBuffer = _context2.sent;
|
|
185
|
-
return _context2.abrupt("return", new TextDecoder().decode(arrayBuffer));
|
|
186
|
-
case 9:
|
|
187
|
-
throw new Error('Writer could not encode data as text');
|
|
188
|
-
case 10:
|
|
189
|
-
case "end":
|
|
190
|
-
return _context2.stop();
|
|
191
|
-
}
|
|
192
|
-
}, _callee2);
|
|
193
|
-
}));
|
|
194
|
-
return _encodeText.apply(this, arguments);
|
|
58
|
+
async function encodeText(data, writer, options) {
|
|
59
|
+
if (writer.text && writer.encodeText) {
|
|
60
|
+
return await writer.encodeText(data, options);
|
|
61
|
+
}
|
|
62
|
+
if (writer.text && (writer.encode || writer.encodeInBatches)) {
|
|
63
|
+
const arrayBuffer = await encode(data, writer, options);
|
|
64
|
+
return new TextDecoder().decode(arrayBuffer);
|
|
65
|
+
}
|
|
66
|
+
throw new Error('Writer could not encode data as text');
|
|
195
67
|
}
|
|
196
68
|
function encodeInBatches(data, writer, options) {
|
|
197
69
|
if (writer.encodeInBatches) {
|
|
198
|
-
|
|
70
|
+
const dataIterator = getIterator(data);
|
|
199
71
|
return writer.encodeInBatches(dataIterator, options);
|
|
200
72
|
}
|
|
201
73
|
throw new Error('Writer could not encode data in batches');
|
|
202
74
|
}
|
|
203
|
-
function encodeURLtoURL(
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
case 0:
|
|
212
|
-
inputUrl = (0, _loaderUtils.resolvePath)(inputUrl);
|
|
213
|
-
outputUrl = (0, _loaderUtils.resolvePath)(outputUrl);
|
|
214
|
-
if (!(_loaderUtils.isBrowser || !writer.encodeURLtoURL)) {
|
|
215
|
-
_context3.next = 4;
|
|
216
|
-
break;
|
|
217
|
-
}
|
|
218
|
-
throw new Error();
|
|
219
|
-
case 4:
|
|
220
|
-
_context3.next = 6;
|
|
221
|
-
return writer.encodeURLtoURL(inputUrl, outputUrl, options);
|
|
222
|
-
case 6:
|
|
223
|
-
outputFilename = _context3.sent;
|
|
224
|
-
return _context3.abrupt("return", outputFilename);
|
|
225
|
-
case 8:
|
|
226
|
-
case "end":
|
|
227
|
-
return _context3.stop();
|
|
228
|
-
}
|
|
229
|
-
}, _callee3);
|
|
230
|
-
}));
|
|
231
|
-
return _encodeURLtoURL.apply(this, arguments);
|
|
75
|
+
async function encodeURLtoURL(inputUrl, outputUrl, writer, options) {
|
|
76
|
+
inputUrl = (0, _loaderUtils.resolvePath)(inputUrl);
|
|
77
|
+
outputUrl = (0, _loaderUtils.resolvePath)(outputUrl);
|
|
78
|
+
if (_loaderUtils.isBrowser || !writer.encodeURLtoURL) {
|
|
79
|
+
throw new Error();
|
|
80
|
+
}
|
|
81
|
+
const outputFilename = await writer.encodeURLtoURL(inputUrl, outputUrl, options);
|
|
82
|
+
return outputFilename;
|
|
232
83
|
}
|
|
233
84
|
function getIterator(data) {
|
|
234
|
-
|
|
85
|
+
const dataIterator = [{
|
|
235
86
|
table: data,
|
|
236
87
|
start: 0,
|
|
237
88
|
end: data.length
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encode.js","names":["_loaderUtils","require","_workerUtils","_writeFile","_fetchFile","_loaderOptions","ownKeys","object","enumerableOnly","keys","Object","getOwnPropertySymbols","symbols","filter","sym","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","target","i","arguments","length","source","forEach","key","_defineProperty2","default","getOwnPropertyDescriptors","defineProperties","defineProperty","_asyncIterator","iterable","method","async","sync","retry","Symbol","asyncIterator","iterator","call","AsyncFromSyncIterator","TypeError","s","AsyncFromSyncIteratorContinuation","r","Promise","reject","done","resolve","value","then","n","next","prototype","return","_return","ret","throw","_throw","thr","encode","_x","_x2","_x3","_encode","_asyncToGenerator2","_regenerator","mark","_callee","data","writer","options","globalOptions","batches","chunks","_iteratorAbruptCompletion","_didIteratorError","_iteratorError","_iterator","_step","batch","tmpInputFilename","tmpOutputFilename","outputFilename","response","wrap","_callee$","_context","prev","getLoaderOptions","canEncodeWithWorker","processOnWorker","abrupt","sent","encodeSync","encodeText","t0","TextEncoder","t1","encodeInBatches","t2","finish","concatenateArrayBuffers","isBrowser","encodeURLtoURL","getTemporaryFilename","writeFile","fetchFile","arrayBuffer","Error","stop","_x4","_x5","_x6","_encodeText","_callee2","_callee2$","_context2","text","TextDecoder","decode","dataIterator","getIterator","_x7","_x8","_x9","_x10","_encodeURLtoURL","_callee3","inputUrl","outputUrl","_callee3$","_context3","resolvePath","table","start","end","filename","concat"],"sources":["../../../../src/lib/api/encode.ts"],"sourcesContent":["import {Writer, WriterOptions, canEncodeWithWorker} from '@loaders.gl/loader-utils';\nimport {processOnWorker} from '@loaders.gl/worker-utils';\nimport {concatenateArrayBuffers, resolvePath} from '@loaders.gl/loader-utils';\nimport {isBrowser} from '@loaders.gl/loader-utils';\nimport {writeFile} from '../fetch/write-file';\nimport {fetchFile} from '../fetch/fetch-file';\nimport {getLoaderOptions} from './loader-options';\n\n/**\n * Encode loaded data into a binary ArrayBuffer using the specified Writer.\n */\nexport async function encode(\n data: any,\n writer: Writer,\n options?: WriterOptions\n): Promise<ArrayBuffer> {\n const globalOptions = getLoaderOptions() as WriterOptions;\n // const globalOptions: WriterOptions = {}; // getWriterOptions();\n options = {...globalOptions, ...options};\n if (canEncodeWithWorker(writer, options)) {\n return await processOnWorker(writer, data, options);\n }\n\n // TODO Merge default writer options with options argument like it is done in load module.\n if (writer.encode) {\n return await writer.encode(data, options);\n }\n\n if (writer.encodeSync) {\n return writer.encodeSync(data, options);\n }\n\n if (writer.encodeText) {\n return new TextEncoder().encode(await writer.encodeText(data, options));\n }\n\n if (writer.encodeInBatches) {\n // Create an iterator representing the data\n // TODO - Assumes this is a table\n const batches = encodeInBatches(data, writer, options);\n\n // Concatenate the output\n const chunks: any[] = [];\n for await (const batch of batches) {\n chunks.push(batch);\n }\n // @ts-ignore\n return concatenateArrayBuffers(...chunks);\n }\n\n if (!isBrowser && writer.encodeURLtoURL) {\n // TODO - how to generate filenames with correct extensions?\n const tmpInputFilename = getTemporaryFilename('input');\n await writeFile(tmpInputFilename, data);\n\n const tmpOutputFilename = getTemporaryFilename('output');\n\n const outputFilename = await encodeURLtoURL(\n tmpInputFilename,\n tmpOutputFilename,\n writer,\n options\n );\n\n const response = await fetchFile(outputFilename);\n return response.arrayBuffer();\n }\n\n throw new Error('Writer could not encode data');\n}\n\n/**\n * Encode loaded data into a binary ArrayBuffer using the specified Writer.\n */\nexport function encodeSync(data: any, writer: Writer, options?: WriterOptions): ArrayBuffer {\n if (writer.encodeSync) {\n return writer.encodeSync(data, options);\n }\n throw new Error('Writer could not synchronously encode data');\n}\n\n/**\n * Encode loaded data to text using the specified Writer\n * @note This is a convenience function not intended for production use on large input data.\n * It is not optimized for performance. Data maybe converted from text to binary and back.\n * @throws if the writer does not generate text output\n */\nexport async function encodeText(\n data: any,\n writer: Writer,\n options?: WriterOptions\n): Promise<string> {\n if (writer.text && writer.encodeText) {\n return await writer.encodeText(data, options);\n }\n\n if (writer.text && (writer.encode || writer.encodeInBatches)) {\n const arrayBuffer = await encode(data, writer, options);\n return new TextDecoder().decode(arrayBuffer);\n }\n\n throw new Error('Writer could not encode data as text');\n}\n\n/**\n * Encode loaded data into a sequence (iterator) of binary ArrayBuffers using the specified Writer.\n */\nexport function encodeInBatches(\n data: any,\n writer: Writer,\n options?: WriterOptions\n): AsyncIterable<ArrayBuffer> {\n if (writer.encodeInBatches) {\n const dataIterator = getIterator(data);\n return writer.encodeInBatches(dataIterator, options);\n }\n // TODO -fall back to atomic encode?\n throw new Error('Writer could not encode data in batches');\n}\n\n/**\n * Encode data stored in a file (on disk) to another file.\n * @note Node.js only. This function enables using command-line converters as \"writers\".\n */\nexport async function encodeURLtoURL(\n inputUrl,\n outputUrl,\n writer: Writer,\n options\n): Promise<string> {\n inputUrl = resolvePath(inputUrl);\n outputUrl = resolvePath(outputUrl);\n if (isBrowser || !writer.encodeURLtoURL) {\n throw new Error();\n }\n const outputFilename = await writer.encodeURLtoURL(inputUrl, outputUrl, options);\n return outputFilename;\n}\n\n/**\n * @todo TODO - this is an unacceptable hack!!!\n */\nfunction getIterator(data) {\n const dataIterator = [{table: data, start: 0, end: data.length}];\n return dataIterator;\n}\n\n/**\n * @todo Move to utils\n */\nfunction getTemporaryFilename(filename: string): string {\n return `/tmp/${filename}`;\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAGA,IAAAE,UAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AACA,IAAAI,cAAA,GAAAJ,OAAA;AAAkD,SAAAK,QAAAC,MAAA,EAAAC,cAAA,QAAAC,IAAA,GAAAC,MAAA,CAAAD,IAAA,CAAAF,MAAA,OAAAG,MAAA,CAAAC,qBAAA,QAAAC,OAAA,GAAAF,MAAA,CAAAC,qBAAA,CAAAJ,MAAA,GAAAC,cAAA,KAAAI,OAAA,GAAAA,OAAA,CAAAC,MAAA,WAAAC,GAAA,WAAAJ,MAAA,CAAAK,wBAAA,CAAAR,MAAA,EAAAO,GAAA,EAAAE,UAAA,OAAAP,IAAA,CAAAQ,IAAA,CAAAC,KAAA,CAAAT,IAAA,EAAAG,OAAA,YAAAH,IAAA;AAAA,SAAAU,cAAAC,MAAA,aAAAC,CAAA,MAAAA,CAAA,GAAAC,SAAA,CAAAC,MAAA,EAAAF,CAAA,UAAAG,MAAA,WAAAF,SAAA,CAAAD,CAAA,IAAAC,SAAA,CAAAD,CAAA,QAAAA,CAAA,OAAAf,OAAA,CAAAI,MAAA,CAAAc,MAAA,OAAAC,OAAA,WAAAC,GAAA,QAAAC,gBAAA,CAAAC,OAAA,EAAAR,MAAA,EAAAM,GAAA,EAAAF,MAAA,CAAAE,GAAA,SAAAhB,MAAA,CAAAmB,yBAAA,GAAAnB,MAAA,CAAAoB,gBAAA,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E,IAAI;IAAEkE,KAAK,EAAE,CAAC;IAAEC,GAAG,EAAEnE,IAAI,CAAChD;EAAM,CAAC,CAAC;EAChE,OAAOoG,YAAY;AACrB;AAKA,SAAShB,oBAAoBA,CAACgC,QAAgB,EAAU;EACtD,eAAAC,MAAA,CAAeD,QAAQ;AACzB"}
|
|
1
|
+
{"version":3,"file":"encode.js","names":["_loaderUtils","require","_workerUtils","_writeFile","_fetchFile","_loaderOptions","encode","data","writer","options","globalOptions","getLoaderOptions","canEncodeWithWorker","processOnWorker","encodeSync","encodeText","TextEncoder","encodeInBatches","batches","chunks","batch","push","concatenateArrayBuffers","isBrowser","encodeURLtoURL","tmpInputFilename","getTemporaryFilename","writeFile","tmpOutputFilename","outputFilename","response","fetchFile","arrayBuffer","Error","text","TextDecoder","decode","dataIterator","getIterator","inputUrl","outputUrl","resolvePath","table","start","end","length","filename","concat"],"sources":["../../../../src/lib/api/encode.ts"],"sourcesContent":["import {Writer, WriterOptions, canEncodeWithWorker} from '@loaders.gl/loader-utils';\nimport {processOnWorker} from '@loaders.gl/worker-utils';\nimport {concatenateArrayBuffers, resolvePath} from '@loaders.gl/loader-utils';\nimport {isBrowser} from '@loaders.gl/loader-utils';\nimport {writeFile} from '../fetch/write-file';\nimport {fetchFile} from '../fetch/fetch-file';\nimport {getLoaderOptions} from './loader-options';\n\n/**\n * Encode loaded data into a binary ArrayBuffer using the specified Writer.\n */\nexport async function encode(\n data: any,\n writer: Writer,\n options?: WriterOptions\n): Promise<ArrayBuffer> {\n const globalOptions = getLoaderOptions() as WriterOptions;\n // const globalOptions: WriterOptions = {}; // getWriterOptions();\n options = {...globalOptions, ...options};\n if (canEncodeWithWorker(writer, options)) {\n return await processOnWorker(writer, data, options);\n }\n\n // TODO Merge default writer options with options argument like it is done in load module.\n if (writer.encode) {\n return await writer.encode(data, options);\n }\n\n if (writer.encodeSync) {\n return writer.encodeSync(data, options);\n }\n\n if (writer.encodeText) {\n return new TextEncoder().encode(await writer.encodeText(data, options));\n }\n\n if (writer.encodeInBatches) {\n // Create an iterator representing the data\n // TODO - Assumes this is a table\n const batches = encodeInBatches(data, writer, options);\n\n // Concatenate the output\n const chunks: any[] = [];\n for await (const batch of batches) {\n chunks.push(batch);\n }\n // @ts-ignore\n return concatenateArrayBuffers(...chunks);\n }\n\n if (!isBrowser && writer.encodeURLtoURL) {\n // TODO - how to generate filenames with correct extensions?\n const tmpInputFilename = getTemporaryFilename('input');\n await writeFile(tmpInputFilename, data);\n\n const tmpOutputFilename = getTemporaryFilename('output');\n\n const outputFilename = await encodeURLtoURL(\n tmpInputFilename,\n tmpOutputFilename,\n writer,\n options\n );\n\n const response = await fetchFile(outputFilename);\n return response.arrayBuffer();\n }\n\n throw new Error('Writer could not encode data');\n}\n\n/**\n * Encode loaded data into a binary ArrayBuffer using the specified Writer.\n */\nexport function encodeSync(data: any, writer: Writer, options?: WriterOptions): ArrayBuffer {\n if (writer.encodeSync) {\n return writer.encodeSync(data, options);\n }\n throw new Error('Writer could not synchronously encode data');\n}\n\n/**\n * Encode loaded data to text using the specified Writer\n * @note This is a convenience function not intended for production use on large input data.\n * It is not optimized for performance. Data maybe converted from text to binary and back.\n * @throws if the writer does not generate text output\n */\nexport async function encodeText(\n data: any,\n writer: Writer,\n options?: WriterOptions\n): Promise<string> {\n if (writer.text && writer.encodeText) {\n return await writer.encodeText(data, options);\n }\n\n if (writer.text && (writer.encode || writer.encodeInBatches)) {\n const arrayBuffer = await encode(data, writer, options);\n return new TextDecoder().decode(arrayBuffer);\n }\n\n throw new Error('Writer could not encode data as text');\n}\n\n/**\n * Encode loaded data into a sequence (iterator) of binary ArrayBuffers using the specified Writer.\n */\nexport function encodeInBatches(\n data: any,\n writer: Writer,\n options?: WriterOptions\n): AsyncIterable<ArrayBuffer> {\n if (writer.encodeInBatches) {\n const dataIterator = getIterator(data);\n return writer.encodeInBatches(dataIterator, options);\n }\n // TODO -fall back to atomic encode?\n throw new Error('Writer could not encode data in batches');\n}\n\n/**\n * Encode data stored in a file (on disk) to another file.\n * @note Node.js only. This function enables using command-line converters as \"writers\".\n */\nexport async function encodeURLtoURL(\n inputUrl,\n outputUrl,\n writer: Writer,\n options\n): Promise<string> {\n inputUrl = resolvePath(inputUrl);\n outputUrl = resolvePath(outputUrl);\n if (isBrowser || !writer.encodeURLtoURL) {\n throw new Error();\n }\n const outputFilename = await writer.encodeURLtoURL(inputUrl, outputUrl, options);\n return outputFilename;\n}\n\n/**\n * @todo TODO - this is an unacceptable hack!!!\n */\nfunction getIterator(data) {\n const dataIterator = [{table: data, start: 0, end: data.length}];\n return dataIterator;\n}\n\n/**\n * @todo Move to utils\n */\nfunction getTemporaryFilename(filename: string): string {\n return `/tmp/${filename}`;\n}\n"],"mappings":";;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAGA,IAAAE,UAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AACA,IAAAI,cAAA,GAAAJ,OAAA;AAKO,eAAeK,MAAMA,CAC1BC,IAAS,EACTC,MAAc,EACdC,OAAuB,EACD;EACtB,MAAMC,aAAa,GAAG,IAAAC,+BAAgB,EAAC,CAAkB;EAEzDF,OAAO,GAAG;IAAC,GAAGC,aAAa;IAAE,GAAGD;EAAO,CAAC;EACxC,IAAI,IAAAG,gCAAmB,EAACJ,MAAM,EAAEC,OAAO,CAAC,EAAE;IACxC,OAAO,MAAM,IAAAI,4BAAe,EAACL,MAAM,EAAED,IAAI,EAAEE,OAAO,CAAC;EACrD;EAGA,IAAID,MAAM,CAACF,MAAM,EAAE;IACjB,OAAO,MAAME,MAAM,CAACF,MAAM,CAACC,IAAI,EAAEE,OAAO,CAAC;EAC3C;EAEA,IAAID,MAAM,CAACM,UAAU,EAAE;IACrB,OAAON,MAAM,CAACM,UAAU,CAACP,IAAI,EAAEE,OAAO,CAAC;EACzC;EAEA,IAAID,MAAM,CAACO,UAAU,EAAE;IACrB,OAAO,IAAIC,WAAW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EC,GAAG,EAAErC,IAAI,CAACsC;EAAM,CAAC,CAAC;EAChE,OAAOR,YAAY;AACrB;AAKA,SAASX,oBAAoBA,CAACoB,QAAgB,EAAU;EACtD,eAAAC,MAAA,CAAeD,QAAQ;AACzB"}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.loadInBatches = loadInBatches;
|
|
8
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
7
|
var _normalizeLoader = require("../loader-utils/normalize-loader");
|
|
11
8
|
var _getFetchFunction = require("../loader-utils/get-fetch-function");
|
|
12
9
|
var _parseInBatches = require("./parse-in-batches");
|
|
@@ -16,48 +13,19 @@ function loadInBatches(files, loaders, options, context) {
|
|
|
16
13
|
options = loaders;
|
|
17
14
|
loaders = null;
|
|
18
15
|
}
|
|
19
|
-
|
|
16
|
+
const fetch = (0, _getFetchFunction.getFetchFunction)(options || {});
|
|
20
17
|
if (!Array.isArray(files)) {
|
|
21
18
|
return loadOneFileInBatches(files, loaders, options, fetch);
|
|
22
19
|
}
|
|
23
|
-
|
|
24
|
-
return loadOneFileInBatches(file, loaders, options, fetch);
|
|
25
|
-
});
|
|
20
|
+
const promises = files.map(file => loadOneFileInBatches(file, loaders, options, fetch));
|
|
26
21
|
return promises;
|
|
27
22
|
}
|
|
28
|
-
function loadOneFileInBatches(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
while (1) switch (_context.prev = _context.next) {
|
|
36
|
-
case 0:
|
|
37
|
-
if (!(typeof file === 'string')) {
|
|
38
|
-
_context.next = 8;
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
|
-
url = file;
|
|
42
|
-
_context.next = 4;
|
|
43
|
-
return fetch(url);
|
|
44
|
-
case 4:
|
|
45
|
-
response = _context.sent;
|
|
46
|
-
_context.next = 7;
|
|
47
|
-
return (0, _parseInBatches.parseInBatches)(response, loaders, options);
|
|
48
|
-
case 7:
|
|
49
|
-
return _context.abrupt("return", _context.sent);
|
|
50
|
-
case 8:
|
|
51
|
-
_context.next = 10;
|
|
52
|
-
return (0, _parseInBatches.parseInBatches)(file, loaders, options);
|
|
53
|
-
case 10:
|
|
54
|
-
return _context.abrupt("return", _context.sent);
|
|
55
|
-
case 11:
|
|
56
|
-
case "end":
|
|
57
|
-
return _context.stop();
|
|
58
|
-
}
|
|
59
|
-
}, _callee);
|
|
60
|
-
}));
|
|
61
|
-
return _loadOneFileInBatches.apply(this, arguments);
|
|
23
|
+
async function loadOneFileInBatches(file, loaders, options, fetch) {
|
|
24
|
+
if (typeof file === 'string') {
|
|
25
|
+
const url = file;
|
|
26
|
+
const response = await fetch(url);
|
|
27
|
+
return await (0, _parseInBatches.parseInBatches)(response, loaders, options);
|
|
28
|
+
}
|
|
29
|
+
return await (0, _parseInBatches.parseInBatches)(file, loaders, options);
|
|
62
30
|
}
|
|
63
31
|
//# sourceMappingURL=load-in-batches.js.map
|