@loaders.gl/core 3.1.0-alpha.4 → 3.1.0-beta.3
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 +3380 -0
- package/dist/core-addons/write-file-browser.d.ts +1 -0
- package/dist/core-addons/write-file-browser.d.ts.map +1 -0
- package/dist/core-addons/write-file-browser.js +60 -0
- package/dist/es5/bundle.js +1 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/index.js +56 -56
- package/dist/es5/iterators/batch-iterators/timed-batch-iterator.js +14 -119
- 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 -53
- package/dist/es5/iterators/make-iterator/make-array-buffer-iterator.js.map +1 -1
- package/dist/es5/iterators/make-iterator/make-blob-iterator.js +12 -53
- 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 -161
- package/dist/es5/iterators/make-iterator/make-stream-iterator.js.map +1 -1
- package/dist/es5/iterators/make-iterator/make-string-iterator.js +13 -41
- package/dist/es5/iterators/make-iterator/make-string-iterator.js.map +1 -1
- package/dist/es5/iterators/make-stream/make-dom-stream.js +24 -69
- package/dist/es5/iterators/make-stream/make-dom-stream.js.map +1 -1
- package/dist/es5/iterators/make-stream/make-node-stream.js +53 -189
- package/dist/es5/iterators/make-stream/make-node-stream.js.map +1 -1
- package/dist/es5/javascript-utils/is-type.js +18 -58
- package/dist/es5/javascript-utils/is-type.js.map +1 -1
- package/dist/es5/lib/api/encode.js +46 -242
- package/dist/es5/lib/api/encode.js.map +1 -1
- package/dist/es5/lib/api/load-in-batches.js +9 -52
- package/dist/es5/lib/api/load-in-batches.js.map +1 -1
- package/dist/es5/lib/api/load.js +15 -60
- package/dist/es5/lib/api/load.js.map +1 -1
- package/dist/es5/lib/api/parse-in-batches.js +81 -333
- package/dist/es5/lib/api/parse-in-batches.js.map +1 -1
- package/dist/es5/lib/api/parse-sync.js +11 -15
- package/dist/es5/lib/api/parse-sync.js.map +1 -1
- package/dist/es5/lib/api/parse.js +50 -142
- package/dist/es5/lib/api/parse.js.map +1 -1
- package/dist/es5/lib/api/register-loaders.js +8 -30
- package/dist/es5/lib/api/register-loaders.js.map +1 -1
- package/dist/es5/lib/api/save.js +4 -37
- package/dist/es5/lib/api/save.js.map +1 -1
- package/dist/es5/lib/api/select-loader.js +74 -209
- package/dist/es5/lib/api/select-loader.js.map +1 -1
- package/dist/es5/lib/fetch/fetch-error-message.js +13 -55
- package/dist/es5/lib/fetch/fetch-error-message.js.map +1 -1
- package/dist/es5/lib/fetch/fetch-file.js +10 -47
- package/dist/es5/lib/fetch/fetch-file.js.map +1 -1
- package/dist/es5/lib/fetch/read-array-buffer.js +19 -80
- package/dist/es5/lib/fetch/read-array-buffer.js.map +1 -1
- package/dist/es5/lib/fetch/read-file.js +2 -3
- package/dist/es5/lib/fetch/read-file.js.map +1 -1
- package/dist/es5/lib/fetch/write-file.js +9 -38
- package/dist/es5/lib/fetch/write-file.js.map +1 -1
- package/dist/es5/lib/filesystems/browser-filesystem.js +77 -266
- package/dist/es5/lib/filesystems/browser-filesystem.js.map +1 -1
- package/dist/es5/lib/filesystems/read-array-buffer.js +6 -43
- 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 +12 -50
- package/dist/es5/lib/loader-utils/check-errors.js.map +1 -1
- package/dist/es5/lib/loader-utils/get-data.js +71 -238
- package/dist/es5/lib/loader-utils/get-data.js.map +1 -1
- package/dist/es5/lib/loader-utils/loader-context.js +8 -19
- package/dist/es5/lib/loader-utils/loader-context.js.map +1 -1
- package/dist/es5/lib/loader-utils/loggers.js +36 -81
- package/dist/es5/lib/loader-utils/loggers.js.map +1 -1
- package/dist/es5/lib/loader-utils/normalize-loader.js +7 -13
- 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 +51 -85
- package/dist/es5/lib/loader-utils/option-utils.js.map +1 -1
- package/dist/es5/lib/progress/fetch-progress.js +49 -150
- package/dist/es5/lib/progress/fetch-progress.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 +4 -4
- package/dist/es5/lib/utils/resource-utils.js.map +1 -1
- package/dist/es5/lib/utils/response-utils.js +88 -215
- package/dist/es5/lib/utils/response-utils.js.map +1 -1
- package/dist/es5/null-loader.js +10 -137
- package/dist/es5/null-loader.js.map +1 -1
- package/dist/esm/lib/api/encode.js +1 -1
- package/dist/esm/lib/api/encode.js.map +1 -1
- package/dist/esm/lib/api/parse-sync.js +1 -1
- package/dist/esm/lib/api/parse-sync.js.map +1 -1
- package/dist/esm/lib/api/parse.js +1 -1
- package/dist/esm/lib/api/parse.js.map +1 -1
- package/dist/esm/lib/api/register-loaders.js.map +1 -1
- package/dist/esm/lib/api/select-loader.js +4 -4
- package/dist/esm/lib/api/select-loader.js.map +1 -1
- package/dist/esm/lib/fetch/fetch-error-message.js +2 -2
- package/dist/esm/lib/fetch/fetch-error-message.js.map +1 -1
- package/dist/esm/lib/init.js +1 -1
- package/dist/esm/lib/init.js.map +1 -1
- package/dist/esm/lib/loader-utils/check-errors.js +4 -4
- package/dist/esm/lib/loader-utils/check-errors.js.map +1 -1
- package/dist/esm/lib/loader-utils/option-utils.js +5 -5
- package/dist/esm/lib/loader-utils/option-utils.js.map +1 -1
- package/dist/esm/lib/utils/response-utils.js +7 -7
- package/dist/esm/lib/utils/response-utils.js.map +1 -1
- package/dist/esm/null-loader.js +1 -1
- package/dist/esm/null-loader.js.map +1 -1
- package/dist/index.d.ts +31 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +106 -0
- package/dist/iterators/batch-iterators/timed-batch-iterator.d.ts +5 -0
- package/dist/iterators/batch-iterators/timed-batch-iterator.d.ts.map +1 -0
- package/dist/iterators/batch-iterators/timed-batch-iterator.js +22 -0
- package/dist/iterators/make-iterator/make-array-buffer-iterator.d.ts +9 -0
- package/dist/iterators/make-iterator/make-array-buffer-iterator.d.ts.map +1 -0
- package/dist/iterators/make-iterator/make-array-buffer-iterator.js +27 -0
- package/dist/iterators/make-iterator/make-blob-iterator.d.ts +9 -0
- package/dist/iterators/make-iterator/make-blob-iterator.d.ts.map +1 -0
- package/dist/iterators/make-iterator/make-blob-iterator.js +21 -0
- package/dist/iterators/make-iterator/make-iterator.d.ts +19 -0
- package/dist/iterators/make-iterator/make-iterator.d.ts.map +1 -0
- package/dist/iterators/make-iterator/make-iterator.js +37 -0
- package/dist/iterators/make-iterator/make-stream-iterator.d.ts +11 -0
- package/dist/iterators/make-iterator/make-stream-iterator.d.ts.map +1 -0
- package/dist/iterators/make-iterator/make-stream-iterator.js +96 -0
- package/dist/iterators/make-iterator/make-string-iterator.d.ts +9 -0
- package/dist/iterators/make-iterator/make-string-iterator.d.ts.map +1 -0
- package/dist/iterators/make-iterator/make-string-iterator.js +24 -0
- package/dist/iterators/make-stream/make-dom-stream.d.ts +9 -0
- package/dist/iterators/make-stream/make-dom-stream.d.ts.map +1 -0
- package/dist/iterators/make-stream/make-dom-stream.js +41 -0
- package/dist/iterators/make-stream/make-node-stream.d.ts +7 -0
- package/dist/iterators/make-stream/make-node-stream.d.ts.map +1 -0
- package/dist/iterators/make-stream/make-node-stream.js +58 -0
- package/dist/iterators/make-stream/make-stream.d.ts +9 -0
- package/dist/iterators/make-stream/make-stream.d.ts.map +1 -0
- package/dist/iterators/make-stream/make-stream.js +16 -0
- package/dist/javascript-utils/is-type.d.ts +22 -0
- package/dist/javascript-utils/is-type.d.ts.map +1 -0
- package/dist/javascript-utils/is-type.js +41 -0
- package/dist/lib/api/encode.d.ts +26 -0
- package/dist/lib/api/encode.d.ts.map +1 -0
- package/dist/lib/api/encode.js +111 -0
- package/dist/lib/api/load-in-batches.d.ts +13 -0
- package/dist/lib/api/load-in-batches.d.ts.map +1 -0
- package/dist/lib/api/load-in-batches.js +33 -0
- package/dist/lib/api/load.d.ts +12 -0
- package/dist/lib/api/load.d.ts.map +1 -0
- package/dist/lib/api/load.js +41 -0
- package/dist/lib/api/parse-in-batches.d.ts +10 -0
- package/dist/lib/api/parse-in-batches.d.ts.map +1 -0
- package/dist/lib/api/parse-in-batches.js +120 -0
- package/dist/lib/api/parse-sync.d.ts +10 -0
- package/dist/lib/api/parse-sync.d.ts.map +1 -0
- package/dist/lib/api/parse-sync.js +59 -0
- package/dist/lib/api/parse.d.ts +10 -0
- package/dist/lib/api/parse.d.ts.map +1 -0
- package/dist/lib/api/parse.js +74 -0
- package/dist/lib/api/register-loaders.d.ts +7 -0
- package/dist/lib/api/register-loaders.d.ts.map +1 -0
- package/dist/lib/api/register-loaders.js +35 -0
- package/dist/lib/api/save.d.ts +4 -0
- package/dist/lib/api/save.d.ts.map +1 -0
- package/dist/lib/api/save.js +15 -0
- package/dist/lib/api/select-loader.d.ts +22 -0
- package/dist/lib/api/select-loader.d.ts.map +1 -0
- package/dist/lib/api/select-loader.js +239 -0
- package/dist/lib/api/set-loader-options.d.ts +6 -0
- package/dist/lib/api/set-loader-options.d.ts.map +1 -0
- package/dist/lib/api/set-loader-options.js +12 -0
- package/dist/lib/common.d.ts +2 -0
- package/dist/lib/common.d.ts.map +1 -0
- package/dist/lib/common.js +2 -0
- package/dist/lib/fetch/fetch-error-message.d.ts +3 -0
- package/dist/lib/fetch/fetch-error-message.d.ts.map +1 -0
- package/dist/lib/fetch/fetch-error-message.js +25 -0
- package/dist/lib/fetch/fetch-file.d.ts +13 -0
- package/dist/lib/fetch/fetch-file.d.ts.map +1 -0
- package/dist/lib/fetch/fetch-file.js +27 -0
- package/dist/lib/fetch/read-array-buffer.d.ts +17 -0
- package/dist/lib/fetch/read-array-buffer.d.ts.map +1 -0
- package/dist/lib/fetch/read-array-buffer.js +41 -0
- package/dist/lib/fetch/read-file.d.ts +5 -0
- package/dist/lib/fetch/read-file.d.ts.map +1 -0
- package/dist/lib/fetch/read-file.js +29 -0
- package/dist/lib/fetch/write-file.d.ts +3 -0
- package/dist/lib/fetch/write-file.d.ts.map +1 -0
- package/dist/lib/fetch/write-file.js +22 -0
- package/dist/lib/filesystems/browser-filesystem.d.ts +58 -0
- package/dist/lib/filesystems/browser-filesystem.d.ts.map +1 -0
- package/dist/lib/filesystems/browser-filesystem.js +126 -0
- package/dist/lib/filesystems/filesystem.d.ts +46 -0
- package/dist/lib/filesystems/filesystem.d.ts.map +1 -0
- package/dist/lib/filesystems/filesystem.js +2 -0
- package/dist/lib/filesystems/read-array-buffer.d.ts +19 -0
- package/dist/lib/filesystems/read-array-buffer.d.ts.map +1 -0
- package/dist/lib/filesystems/read-array-buffer.js +29 -0
- package/dist/lib/init.d.ts +3 -0
- package/dist/lib/init.d.ts.map +1 -0
- package/dist/lib/init.js +10 -0
- package/dist/lib/loader-utils/check-errors.d.ts +3 -0
- package/dist/lib/loader-utils/check-errors.d.ts.map +1 -0
- package/dist/lib/loader-utils/check-errors.js +30 -0
- package/dist/lib/loader-utils/get-data.d.ts +6 -0
- package/dist/lib/loader-utils/get-data.d.ts.map +1 -0
- package/dist/lib/loader-utils/get-data.js +129 -0
- package/dist/lib/loader-utils/loader-context.d.ts +13 -0
- package/dist/lib/loader-utils/loader-context.d.ts.map +1 -0
- package/dist/lib/loader-utils/loader-context.js +49 -0
- package/dist/lib/loader-utils/loggers.d.ts +16 -0
- package/dist/lib/loader-utils/loggers.d.ts.map +1 -0
- package/dist/lib/loader-utils/loggers.js +41 -0
- package/dist/lib/loader-utils/normalize-loader.d.ts +4 -0
- package/dist/lib/loader-utils/normalize-loader.d.ts.map +1 -0
- package/dist/lib/loader-utils/normalize-loader.js +52 -0
- package/dist/lib/loader-utils/option-defaults.d.ts +20 -0
- package/dist/lib/loader-utils/option-defaults.d.ts.map +1 -0
- package/dist/lib/loader-utils/option-defaults.js +41 -0
- package/dist/lib/loader-utils/option-utils.d.ts +36 -0
- package/dist/lib/loader-utils/option-utils.d.ts.map +1 -0
- package/dist/lib/loader-utils/option-utils.js +177 -0
- package/dist/lib/progress/fetch-progress.d.ts +6 -0
- package/dist/lib/progress/fetch-progress.d.ts.map +1 -0
- package/dist/lib/progress/fetch-progress.js +59 -0
- package/dist/lib/utils/mime-type-utils.d.ts +20 -0
- package/dist/lib/utils/mime-type-utils.d.ts.map +1 -0
- package/dist/lib/utils/mime-type-utils.js +42 -0
- package/dist/lib/utils/resource-utils.d.ts +21 -0
- package/dist/lib/utils/resource-utils.d.ts.map +1 -0
- package/dist/lib/utils/resource-utils.js +78 -0
- package/dist/lib/utils/response-utils.d.ts +18 -0
- package/dist/lib/utils/response-utils.d.ts.map +1 -0
- package/dist/lib/utils/response-utils.js +114 -0
- package/dist/null-loader.d.ts +10 -0
- package/dist/null-loader.d.ts.map +1 -0
- package/dist/null-loader.js +44 -0
- package/dist/null-worker.js +178 -2
- package/dist/workers/null-worker.d.ts +2 -0
- package/dist/workers/null-worker.d.ts.map +1 -0
- package/dist/workers/null-worker.js +5 -0
- package/package.json +7 -7
- package/src/lib/api/encode.ts +1 -0
- package/src/lib/api/register-loaders.ts +2 -1
- package/src/lib/{init.js → init.ts} +0 -0
- package/dist/dist.min.js +0 -2
- package/dist/dist.min.js.map +0 -1
- package/dist/null-worker.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-filesystem.d.ts","sourceRoot":"","sources":["../../../src/lib/filesystems/browser-filesystem.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AAE7C,aAAK,wBAAwB,GAAG;IAC9B,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACtB,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,iBAAkB,YAAW,UAAU;IAC1D,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,KAAK,CAAkC;IAC/C,OAAO,CAAC,cAAc,CAAkC;IACxD,OAAO,CAAC,SAAS,CAAqC;IAEtD;;;;OAIG;gBACS,KAAK,EAAE,QAAQ,GAAG,IAAI,EAAE,EAAE,OAAO,CAAC,EAAE,wBAAwB;IAexE;;;OAGG;IACG,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC;IAkCnE;;;;OAIG;IACG,OAAO,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IASlD;;OAEG;IACG,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAC,CAAC;IAQnE;;OAEG;IACG,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IASnC,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,KAAA,EAAE,IAAI,CAAC,KAAA,GAAG,OAAO,CAAC,GAAG,CAAC;IAIxD;;;;;;;OAOG;IACG,IAAI,CACR,EAAE,EAAE,GAAG,EACP,MAAM,EAAE,WAAW,EACnB,MAAM,GAAE,MAAU,EAClB,MAAM,GAAE,MAA0B,EAClC,QAAQ,GAAE,MAAM,GAAG,IAAW,GAC7B,OAAO,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,WAAW,CAAA;KAAC,CAAC;IAQ9C,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAStC,QAAQ,CAAC,IAAI,KAAA,EAAE,IAAI,KAAA;CAQpB"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* FileSystem adapter for a browser FileList.
|
|
5
|
+
* Holds a list of browser 'File' objects.
|
|
6
|
+
*/
|
|
7
|
+
class BrowserFileSystem {
|
|
8
|
+
/**
|
|
9
|
+
* A FileSystem API wrapper around a list of browser 'File' objects
|
|
10
|
+
* @param files
|
|
11
|
+
* @param options
|
|
12
|
+
*/
|
|
13
|
+
constructor(files, options) {
|
|
14
|
+
this.files = {};
|
|
15
|
+
this.lowerCaseFiles = {};
|
|
16
|
+
this.usedFiles = {};
|
|
17
|
+
this._fetch = options?.fetch || fetch;
|
|
18
|
+
for (let i = 0; i < files.length; ++i) {
|
|
19
|
+
const file = files[i];
|
|
20
|
+
this.files[file.name] = file;
|
|
21
|
+
this.lowerCaseFiles[file.name.toLowerCase()] = file;
|
|
22
|
+
this.usedFiles[file.name] = false;
|
|
23
|
+
}
|
|
24
|
+
this.fetch = this.fetch.bind(this);
|
|
25
|
+
}
|
|
26
|
+
// implements IFileSystem
|
|
27
|
+
/**
|
|
28
|
+
* Implementation of fetch against this file system
|
|
29
|
+
* Delegates to global fetch for http{s}:// or data://
|
|
30
|
+
*/
|
|
31
|
+
async fetch(path, options) {
|
|
32
|
+
// Fallback to handle https:/http:/data: etc fetches
|
|
33
|
+
if (path.includes('://')) {
|
|
34
|
+
return this._fetch(path, options);
|
|
35
|
+
}
|
|
36
|
+
// Local fetches are served from the list of files
|
|
37
|
+
const file = this.files[path];
|
|
38
|
+
if (!file) {
|
|
39
|
+
return new Response(path, { status: 400, statusText: 'NOT FOUND' });
|
|
40
|
+
}
|
|
41
|
+
const headers = new Headers(options?.headers);
|
|
42
|
+
const range = headers.get('Range');
|
|
43
|
+
const bytes = range && /bytes=($1)-($2)/.exec(range);
|
|
44
|
+
if (bytes) {
|
|
45
|
+
const start = parseInt(bytes[1]);
|
|
46
|
+
const end = parseInt(bytes[2]);
|
|
47
|
+
// The trick when reading File objects is to read successive "slices" of the File
|
|
48
|
+
// Per spec https://w3c.github.io/FileAPI/, slicing a File should only update the start and end fields
|
|
49
|
+
// Actually reading from file should happen in `readAsArrayBuffer` (and as far we can tell it does)
|
|
50
|
+
const data = await file.slice(start, end).arrayBuffer();
|
|
51
|
+
const response = new Response(data);
|
|
52
|
+
Object.defineProperty(response, 'url', { value: path });
|
|
53
|
+
return response;
|
|
54
|
+
}
|
|
55
|
+
// return makeResponse()
|
|
56
|
+
const response = new Response(file);
|
|
57
|
+
Object.defineProperty(response, 'url', { value: path });
|
|
58
|
+
return response;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* List filenames in this filesystem
|
|
62
|
+
* @param dirname
|
|
63
|
+
* @returns
|
|
64
|
+
*/
|
|
65
|
+
async readdir(dirname) {
|
|
66
|
+
const files = [];
|
|
67
|
+
for (const path in this.files) {
|
|
68
|
+
files.push(path);
|
|
69
|
+
}
|
|
70
|
+
// TODO filter by dirname
|
|
71
|
+
return files;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Return information (size) about files in this file system
|
|
75
|
+
*/
|
|
76
|
+
async stat(path, options) {
|
|
77
|
+
const file = this.files[path];
|
|
78
|
+
if (!file) {
|
|
79
|
+
throw new Error(path);
|
|
80
|
+
}
|
|
81
|
+
return { size: file.size };
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Just removes the file from the list
|
|
85
|
+
*/
|
|
86
|
+
async unlink(path) {
|
|
87
|
+
delete this.files[path];
|
|
88
|
+
delete this.lowerCaseFiles[path];
|
|
89
|
+
this.usedFiles[path] = true;
|
|
90
|
+
}
|
|
91
|
+
// implements IRandomAccessFileSystem
|
|
92
|
+
// RANDOM ACCESS
|
|
93
|
+
async open(pathname, flags, mode) {
|
|
94
|
+
return this.files[pathname];
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Read a range into a buffer
|
|
98
|
+
* @todo - handle position memory
|
|
99
|
+
* @param buffer is the buffer that the data (read from the fd) will be written to.
|
|
100
|
+
* @param offset is the offset in the buffer to start writing at.
|
|
101
|
+
* @param length is an integer specifying the number of bytes to read.
|
|
102
|
+
* @param position is an argument specifying where to begin reading from in the file. If position is null, data will be read from the current file position, and the file position will be updated. If position is an integer, the file position will remain unchanged.
|
|
103
|
+
*/
|
|
104
|
+
async read(fd, buffer, offset = 0, length = buffer.byteLength, position = null) {
|
|
105
|
+
const file = fd;
|
|
106
|
+
const startPosition = 0; // position
|
|
107
|
+
const arrayBuffer = await file.slice(startPosition, startPosition + length).arrayBuffer();
|
|
108
|
+
// copy into target buffer
|
|
109
|
+
return { bytesRead: length, buffer: arrayBuffer };
|
|
110
|
+
}
|
|
111
|
+
async close(fd) {
|
|
112
|
+
// NO OP
|
|
113
|
+
}
|
|
114
|
+
// fstat(fd: number): Promise<object>; // Stat
|
|
115
|
+
// PRIVATE
|
|
116
|
+
// Supports case independent paths, and file usage tracking
|
|
117
|
+
_getFile(path, used) {
|
|
118
|
+
// Prefer case match, but fall back to case indepent.
|
|
119
|
+
const file = this.files[path] || this.lowerCaseFiles[path];
|
|
120
|
+
if (file && used) {
|
|
121
|
+
this.usedFiles[path] = true;
|
|
122
|
+
}
|
|
123
|
+
return file;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
exports.default = BrowserFileSystem;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export declare type ReadOptions = {};
|
|
2
|
+
export declare type Stat = {
|
|
3
|
+
size: number;
|
|
4
|
+
isDirectory: () => boolean;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* A FileSystem interface can encapsulate various file sources,
|
|
8
|
+
* a FileList, a ZipFile, a GoogleDrive etc.
|
|
9
|
+
*/
|
|
10
|
+
export interface FileSystem {
|
|
11
|
+
/**
|
|
12
|
+
* Return a list of file names
|
|
13
|
+
* @param dirname directory name. file system root directory if omitted
|
|
14
|
+
*/
|
|
15
|
+
readdir(dirname?: string, options?: {
|
|
16
|
+
recursive?: boolean;
|
|
17
|
+
}): Promise<string[]>;
|
|
18
|
+
/**
|
|
19
|
+
* Gets information from a local file from the filesystem
|
|
20
|
+
* @param filename file name to stat
|
|
21
|
+
* @param options currently unused
|
|
22
|
+
* @throws if filename is not in local filesystem
|
|
23
|
+
*/
|
|
24
|
+
stat(filename: string, options?: object): Promise<{
|
|
25
|
+
size: number;
|
|
26
|
+
}>;
|
|
27
|
+
/**
|
|
28
|
+
* Fetches a local file from the filesystem (or a URL)
|
|
29
|
+
* @param filename
|
|
30
|
+
* @param options
|
|
31
|
+
*/
|
|
32
|
+
fetch(filename: RequestInfo, options?: RequestInit): Promise<Response>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A random access file system
|
|
36
|
+
*/
|
|
37
|
+
export interface RandomAccessReadFileSystem extends FileSystem {
|
|
38
|
+
open(path: string, flags: any, mode?: any): Promise<any>;
|
|
39
|
+
close(fd: any): Promise<void>;
|
|
40
|
+
fstat(fd: any): Promise<Stat>;
|
|
41
|
+
read(fd: any, buffer: ArrayBuffer | ArrayBufferView, offset?: number, length?: number, position?: number): Promise<{
|
|
42
|
+
bytesRead: number;
|
|
43
|
+
buffer: ArrayBuffer;
|
|
44
|
+
}>;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=filesystem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filesystem.d.ts","sourceRoot":"","sources":["../../../src/lib/filesystems/filesystem.ts"],"names":[],"mappings":"AAAA,oBAAY,WAAW,GAAG,EAAE,CAAC;AAE7B,oBAAY,IAAI,GAAG;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,OAAO,CAAC;CAC5B,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB;;;OAGG;IACH,OAAO,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAC,SAAS,CAAC,EAAE,OAAO,CAAA;KAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAE9E;;;;;OAKG;IACH,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAC,CAAC,CAAC;IAElE;;;;OAIG;IACH,KAAK,CAAC,QAAQ,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CACxE;AAED;;GAEG;AACH,MAAM,WAAW,0BAA2B,SAAQ,UAAU;IAC5D,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,KAAA,EAAE,IAAI,CAAC,KAAA,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAC/C,KAAK,CAAC,EAAE,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,KAAK,CAAC,EAAE,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,IAAI,CACF,EAAE,EAAE,GAAG,EACP,MAAM,EAAE,WAAW,GAAG,eAAe,EACrC,MAAM,CAAC,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,MAAM,EACf,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,WAAW,CAAA;KAAC,CAAC,CAAC;CACtD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare function readArrayBuffer(file: Blob | ArrayBuffer | any, start: number, length: number): Promise<ArrayBuffer>;
|
|
2
|
+
/**
|
|
3
|
+
* Read a slice of a Blob or File, without loading the entire file into memory
|
|
4
|
+
* The trick when reading File objects is to read successive "slices" of the File
|
|
5
|
+
* Per spec https://w3c.github.io/FileAPI/, slicing a File only updates the start and end fields
|
|
6
|
+
* Actually reading from file happens in `readAsArrayBuffer`
|
|
7
|
+
* @param blob to read
|
|
8
|
+
export async function readBlob(blob: Blob): Promise<ArrayBuffer> {
|
|
9
|
+
return await new Promise((resolve, reject) => {
|
|
10
|
+
const fileReader = new FileReader();
|
|
11
|
+
fileReader.onload = (event: ProgressEvent<FileReader>) =>
|
|
12
|
+
resolve(event?.target?.result as ArrayBuffer);
|
|
13
|
+
// TODO - reject with a proper Error
|
|
14
|
+
fileReader.onerror = (error: ProgressEvent<FileReader>) => reject(error);
|
|
15
|
+
fileReader.readAsArrayBuffer(blob);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
*/
|
|
19
|
+
//# sourceMappingURL=read-array-buffer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-array-buffer.d.ts","sourceRoot":"","sources":["../../../src/lib/filesystems/read-array-buffer.ts"],"names":[],"mappings":"AAEA,wBAAsB,eAAe,CACnC,IAAI,EAAE,IAAI,GAAG,WAAW,GAAG,GAAG,EAC9B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,WAAW,CAAC,CAMtB;AAED;;;;;;;;;;;;;;;;EAgBE"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Random-Access read
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.readArrayBuffer = void 0;
|
|
5
|
+
async function readArrayBuffer(file, start, length) {
|
|
6
|
+
if (file instanceof Blob) {
|
|
7
|
+
const slice = file.slice(start, start + length);
|
|
8
|
+
return await slice.arrayBuffer();
|
|
9
|
+
}
|
|
10
|
+
return await file.read(start, start + length);
|
|
11
|
+
}
|
|
12
|
+
exports.readArrayBuffer = readArrayBuffer;
|
|
13
|
+
/**
|
|
14
|
+
* Read a slice of a Blob or File, without loading the entire file into memory
|
|
15
|
+
* The trick when reading File objects is to read successive "slices" of the File
|
|
16
|
+
* Per spec https://w3c.github.io/FileAPI/, slicing a File only updates the start and end fields
|
|
17
|
+
* Actually reading from file happens in `readAsArrayBuffer`
|
|
18
|
+
* @param blob to read
|
|
19
|
+
export async function readBlob(blob: Blob): Promise<ArrayBuffer> {
|
|
20
|
+
return await new Promise((resolve, reject) => {
|
|
21
|
+
const fileReader = new FileReader();
|
|
22
|
+
fileReader.onload = (event: ProgressEvent<FileReader>) =>
|
|
23
|
+
resolve(event?.target?.result as ArrayBuffer);
|
|
24
|
+
// TODO - reject with a proper Error
|
|
25
|
+
fileReader.onerror = (error: ProgressEvent<FileReader>) => reject(error);
|
|
26
|
+
fileReader.readAsArrayBuffer(blob);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/lib/init.ts"],"names":[],"mappings":";AASA,wBAAkC"}
|
package/dist/lib/init.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
4
|
+
const version = typeof __VERSION__ !== 'undefined' ? __VERSION__ : '';
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
globalThis.loaders = Object.assign(globalThis.loaders || {}, {
|
|
7
|
+
VERSION: version
|
|
8
|
+
});
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
exports.default = globalThis.loaders;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-errors.d.ts","sourceRoot":"","sources":["../../../src/lib/loader-utils/check-errors.ts"],"names":[],"mappings":"AAAA,wBAAsB,wBAAwB,CAAC,QAAQ,KAAA,iBAatD;AAED,wBAAgB,4BAA4B,CAAC,QAAQ,KAAA,QAIpD"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkFetchResponseStatusSync = exports.checkFetchResponseStatus = void 0;
|
|
4
|
+
async function checkFetchResponseStatus(response) {
|
|
5
|
+
if (!response.ok) {
|
|
6
|
+
let errorMessage = `fetch failed ${response.status} ${response.statusText}`;
|
|
7
|
+
try {
|
|
8
|
+
const text = await response.text();
|
|
9
|
+
if (text) {
|
|
10
|
+
errorMessage += `: ${getErrorText(text)}`;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
// ignore error
|
|
15
|
+
}
|
|
16
|
+
throw new Error(errorMessage);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.checkFetchResponseStatus = checkFetchResponseStatus;
|
|
20
|
+
function checkFetchResponseStatusSync(response) {
|
|
21
|
+
if (!response.ok) {
|
|
22
|
+
throw new Error(`fetch failed ${response.status}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.checkFetchResponseStatusSync = checkFetchResponseStatusSync;
|
|
26
|
+
function getErrorText(text) {
|
|
27
|
+
// Look for HTML error texts
|
|
28
|
+
const matches = text.match('<pre>(.*)</pre>');
|
|
29
|
+
return matches ? matches[1] : ` ${text.slice(0, 10)}...`;
|
|
30
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { DataType, SyncDataType, BatchableDataType, Loader, LoaderOptions } from '@loaders.gl/loader-utils';
|
|
2
|
+
export declare function getArrayBufferOrStringFromDataSync(data: SyncDataType, loader: Loader, options: LoaderOptions): ArrayBuffer | string;
|
|
3
|
+
export declare function getArrayBufferOrStringFromData(data: DataType, loader: Loader, options: LoaderOptions): Promise<ArrayBuffer | string>;
|
|
4
|
+
export declare function getAsyncIterableFromData(data: BatchableDataType, options: LoaderOptions): Promise<AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>>;
|
|
5
|
+
export declare function getReadableStream(data: BatchableDataType): Promise<ReadableStream>;
|
|
6
|
+
//# sourceMappingURL=get-data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-data.d.ts","sourceRoot":"","sources":["../../../src/lib/loader-utils/get-data.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,YAAY,EACZ,iBAAiB,EACjB,MAAM,EACN,aAAa,EACd,MAAM,0BAA0B,CAAC;AAiBlC,wBAAgB,kCAAkC,CAChD,IAAI,EAAE,YAAY,EAClB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,aAAa,GACrB,WAAW,GAAG,MAAM,CAyCtB;AAGD,wBAAsB,8BAA8B,CAClD,IAAI,EAAE,QAAQ,EACd,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,WAAW,GAAG,MAAM,CAAC,CA4B/B;AAED,wBAAsB,wBAAwB,CAC5C,IAAI,EAAE,iBAAiB,EACvB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,aAAa,CAAC,WAAW,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC,CAAC,CAyB7D;AAED,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,cAAc,CAAC,CAWxF"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getReadableStream = exports.getAsyncIterableFromData = exports.getArrayBufferOrStringFromData = exports.getArrayBufferOrStringFromDataSync = void 0;
|
|
4
|
+
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
5
|
+
const is_type_1 = require("../../javascript-utils/is-type");
|
|
6
|
+
const make_iterator_1 = require("../../iterators/make-iterator/make-iterator");
|
|
7
|
+
const response_utils_1 = require("../utils/response-utils");
|
|
8
|
+
const ERR_DATA = 'Cannot convert supplied data type';
|
|
9
|
+
// eslint-disable-next-line complexity
|
|
10
|
+
function getArrayBufferOrStringFromDataSync(data, loader, options) {
|
|
11
|
+
if (loader.text && typeof data === 'string') {
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
if ((0, is_type_1.isBuffer)(data)) {
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
data = data.buffer;
|
|
17
|
+
}
|
|
18
|
+
if (data instanceof ArrayBuffer) {
|
|
19
|
+
const arrayBuffer = data;
|
|
20
|
+
if (loader.text && !loader.binary) {
|
|
21
|
+
const textDecoder = new TextDecoder('utf8');
|
|
22
|
+
return textDecoder.decode(arrayBuffer);
|
|
23
|
+
}
|
|
24
|
+
return arrayBuffer;
|
|
25
|
+
}
|
|
26
|
+
// We may need to handle offsets
|
|
27
|
+
if (ArrayBuffer.isView(data)) {
|
|
28
|
+
// TextDecoder is invoked on typed arrays and will handle offsets
|
|
29
|
+
if (loader.text && !loader.binary) {
|
|
30
|
+
const textDecoder = new TextDecoder('utf8');
|
|
31
|
+
return textDecoder.decode(data);
|
|
32
|
+
}
|
|
33
|
+
let arrayBuffer = data.buffer;
|
|
34
|
+
// Since we are returning the underlying arrayBuffer, we must create a new copy
|
|
35
|
+
// if this typed array / Buffer is a partial view into the ArryayBuffer
|
|
36
|
+
// TODO - this is a potentially unnecessary copy
|
|
37
|
+
const byteLength = data.byteLength || data.length;
|
|
38
|
+
if (data.byteOffset !== 0 || byteLength !== arrayBuffer.byteLength) {
|
|
39
|
+
// console.warn(`loaders.gl copying arraybuffer of length ${byteLength}`);
|
|
40
|
+
arrayBuffer = arrayBuffer.slice(data.byteOffset, data.byteOffset + byteLength);
|
|
41
|
+
}
|
|
42
|
+
return arrayBuffer;
|
|
43
|
+
}
|
|
44
|
+
throw new Error(ERR_DATA);
|
|
45
|
+
}
|
|
46
|
+
exports.getArrayBufferOrStringFromDataSync = getArrayBufferOrStringFromDataSync;
|
|
47
|
+
// Convert async iterator to a promise
|
|
48
|
+
async function getArrayBufferOrStringFromData(data, loader, options) {
|
|
49
|
+
const isArrayBuffer = data instanceof ArrayBuffer || ArrayBuffer.isView(data);
|
|
50
|
+
if (typeof data === 'string' || isArrayBuffer) {
|
|
51
|
+
return getArrayBufferOrStringFromDataSync(data, loader, options);
|
|
52
|
+
}
|
|
53
|
+
// Blobs and files are FileReader compatible
|
|
54
|
+
if ((0, is_type_1.isBlob)(data)) {
|
|
55
|
+
data = await (0, response_utils_1.makeResponse)(data);
|
|
56
|
+
}
|
|
57
|
+
if ((0, is_type_1.isResponse)(data)) {
|
|
58
|
+
const response = data;
|
|
59
|
+
await (0, response_utils_1.checkResponse)(response);
|
|
60
|
+
return loader.binary ? await response.arrayBuffer() : await response.text();
|
|
61
|
+
}
|
|
62
|
+
if ((0, is_type_1.isReadableStream)(data)) {
|
|
63
|
+
// @ts-expect-error TS2559 options type
|
|
64
|
+
data = (0, make_iterator_1.makeIterator)(data, options);
|
|
65
|
+
}
|
|
66
|
+
if ((0, is_type_1.isIterable)(data) || (0, is_type_1.isAsyncIterable)(data)) {
|
|
67
|
+
// Assume arrayBuffer iterator - attempt to concatenate
|
|
68
|
+
return (0, loader_utils_1.concatenateArrayBuffersAsync)(data);
|
|
69
|
+
}
|
|
70
|
+
throw new Error(ERR_DATA);
|
|
71
|
+
}
|
|
72
|
+
exports.getArrayBufferOrStringFromData = getArrayBufferOrStringFromData;
|
|
73
|
+
async function getAsyncIterableFromData(data, options) {
|
|
74
|
+
if ((0, is_type_1.isIterator)(data)) {
|
|
75
|
+
return data;
|
|
76
|
+
}
|
|
77
|
+
if ((0, is_type_1.isResponse)(data)) {
|
|
78
|
+
const response = data;
|
|
79
|
+
// Note Since this function is not async, we currently can't load error message, just status
|
|
80
|
+
await (0, response_utils_1.checkResponse)(response);
|
|
81
|
+
// TODO - bug in polyfill, body can be a Promise under Node.js
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/await-thenable
|
|
83
|
+
const body = await response.body;
|
|
84
|
+
// TODO - body can be null?
|
|
85
|
+
return (0, make_iterator_1.makeIterator)(body, options);
|
|
86
|
+
}
|
|
87
|
+
if ((0, is_type_1.isBlob)(data) || (0, is_type_1.isReadableStream)(data)) {
|
|
88
|
+
return (0, make_iterator_1.makeIterator)(data, options);
|
|
89
|
+
}
|
|
90
|
+
if ((0, is_type_1.isAsyncIterable)(data)) {
|
|
91
|
+
return data[Symbol.asyncIterator]();
|
|
92
|
+
}
|
|
93
|
+
return getIterableFromData(data);
|
|
94
|
+
}
|
|
95
|
+
exports.getAsyncIterableFromData = getAsyncIterableFromData;
|
|
96
|
+
async function getReadableStream(data) {
|
|
97
|
+
if ((0, is_type_1.isReadableStream)(data)) {
|
|
98
|
+
return data;
|
|
99
|
+
}
|
|
100
|
+
if ((0, is_type_1.isResponse)(data)) {
|
|
101
|
+
// @ts-ignore
|
|
102
|
+
return data.body;
|
|
103
|
+
}
|
|
104
|
+
const response = await (0, response_utils_1.makeResponse)(data);
|
|
105
|
+
// @ts-ignore
|
|
106
|
+
return response.body;
|
|
107
|
+
}
|
|
108
|
+
exports.getReadableStream = getReadableStream;
|
|
109
|
+
// HELPERS
|
|
110
|
+
function getIterableFromData(data) {
|
|
111
|
+
// generate an iterator that emits a single chunk
|
|
112
|
+
if (ArrayBuffer.isView(data)) {
|
|
113
|
+
return (function* oneChunk() {
|
|
114
|
+
yield data.buffer;
|
|
115
|
+
})();
|
|
116
|
+
}
|
|
117
|
+
if (data instanceof ArrayBuffer) {
|
|
118
|
+
return (function* oneChunk() {
|
|
119
|
+
yield data;
|
|
120
|
+
})();
|
|
121
|
+
}
|
|
122
|
+
if ((0, is_type_1.isIterator)(data)) {
|
|
123
|
+
return data;
|
|
124
|
+
}
|
|
125
|
+
if ((0, is_type_1.isIterable)(data)) {
|
|
126
|
+
return data[Symbol.iterator]();
|
|
127
|
+
}
|
|
128
|
+
throw new Error(ERR_DATA);
|
|
129
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Loader, LoaderOptions, LoaderContext } from '@loaders.gl/loader-utils';
|
|
2
|
+
/**
|
|
3
|
+
* "sub" loaders invoked by other loaders get a "context" injected on `this`
|
|
4
|
+
* The context will inject core methods like `parse` and contain information
|
|
5
|
+
* about loaders and options passed in to the top-level `parse` call.
|
|
6
|
+
*
|
|
7
|
+
* @param context
|
|
8
|
+
* @param options
|
|
9
|
+
* @param previousContext
|
|
10
|
+
*/
|
|
11
|
+
export declare function getLoaderContext(context: Omit<LoaderContext, 'fetch'> & Partial<Pick<LoaderContext, 'fetch'>>, options?: LoaderOptions, previousContext?: LoaderContext | null): LoaderContext;
|
|
12
|
+
export declare function getLoadersFromContext(loaders: Loader[] | Loader | undefined, context?: LoaderContext): any;
|
|
13
|
+
//# sourceMappingURL=loader-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader-context.d.ts","sourceRoot":"","sources":["../../../src/lib/loader-utils/loader-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAE,aAAa,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAGnF;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC,EAC7E,OAAO,CAAC,EAAE,aAAa,EACvB,eAAe,GAAE,aAAa,GAAG,IAAW,GAC3C,aAAa,CAkBf;AAGD,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS,EACtC,OAAO,CAAC,EAAE,aAAa,OAkBxB"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLoadersFromContext = exports.getLoaderContext = void 0;
|
|
4
|
+
const option_utils_1 = require("./option-utils");
|
|
5
|
+
/**
|
|
6
|
+
* "sub" loaders invoked by other loaders get a "context" injected on `this`
|
|
7
|
+
* The context will inject core methods like `parse` and contain information
|
|
8
|
+
* about loaders and options passed in to the top-level `parse` call.
|
|
9
|
+
*
|
|
10
|
+
* @param context
|
|
11
|
+
* @param options
|
|
12
|
+
* @param previousContext
|
|
13
|
+
*/
|
|
14
|
+
function getLoaderContext(context, options, previousContext = null) {
|
|
15
|
+
// For recursive calls, we already have a context
|
|
16
|
+
// TODO - add any additional loaders to context?
|
|
17
|
+
if (previousContext) {
|
|
18
|
+
return previousContext;
|
|
19
|
+
}
|
|
20
|
+
const resolvedContext = {
|
|
21
|
+
fetch: (0, option_utils_1.getFetchFunction)(options, context),
|
|
22
|
+
...context
|
|
23
|
+
};
|
|
24
|
+
// Recursive loading does not use single loader
|
|
25
|
+
if (!Array.isArray(resolvedContext.loaders)) {
|
|
26
|
+
resolvedContext.loaders = null;
|
|
27
|
+
}
|
|
28
|
+
return resolvedContext;
|
|
29
|
+
}
|
|
30
|
+
exports.getLoaderContext = getLoaderContext;
|
|
31
|
+
// eslint-disable-next-line complexity
|
|
32
|
+
function getLoadersFromContext(loaders, context) {
|
|
33
|
+
// A single non-array loader is force selected, but only on top-level (context === null)
|
|
34
|
+
if (!context && loaders && !Array.isArray(loaders)) {
|
|
35
|
+
return loaders;
|
|
36
|
+
}
|
|
37
|
+
// Create a merged list
|
|
38
|
+
let candidateLoaders;
|
|
39
|
+
if (loaders) {
|
|
40
|
+
candidateLoaders = Array.isArray(loaders) ? loaders : [loaders];
|
|
41
|
+
}
|
|
42
|
+
if (context && context.loaders) {
|
|
43
|
+
const contextLoaders = Array.isArray(context.loaders) ? context.loaders : [context.loaders];
|
|
44
|
+
candidateLoaders = candidateLoaders ? [...candidateLoaders, ...contextLoaders] : contextLoaders;
|
|
45
|
+
}
|
|
46
|
+
// If no loaders, return null to look in globally registered loaders
|
|
47
|
+
return candidateLoaders && candidateLoaders.length ? candidateLoaders : null;
|
|
48
|
+
}
|
|
49
|
+
exports.getLoadersFromContext = getLoadersFromContext;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const probeLog: any;
|
|
2
|
+
export declare class NullLog {
|
|
3
|
+
log(): () => void;
|
|
4
|
+
info(): () => void;
|
|
5
|
+
warn(): () => void;
|
|
6
|
+
error(): () => void;
|
|
7
|
+
}
|
|
8
|
+
export declare class ConsoleLog {
|
|
9
|
+
console: any;
|
|
10
|
+
constructor();
|
|
11
|
+
log(...args: any[]): any;
|
|
12
|
+
info(...args: any[]): any;
|
|
13
|
+
warn(...args: any[]): any;
|
|
14
|
+
error(...args: any[]): any;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=loggers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loggers.d.ts","sourceRoot":"","sources":["../../../src/lib/loader-utils/loggers.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,QAAQ,KAA8B,CAAC;AAGpD,qBAAa,OAAO;IAClB,GAAG;IAGH,IAAI;IAGJ,IAAI;IAGJ,KAAK;CAGN;AAGD,qBAAa,UAAU;IACrB,OAAO,MAAC;;IAKR,GAAG,CAAC,GAAG,IAAI,OAAA;IAGX,IAAI,CAAC,GAAG,IAAI,OAAA;IAGZ,IAAI,CAAC,GAAG,IAAI,OAAA;IAGZ,KAAK,CAAC,GAAG,IAAI,OAAA;CAGd"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConsoleLog = exports.NullLog = exports.probeLog = void 0;
|
|
4
|
+
// probe.gl Log compatible loggers
|
|
5
|
+
const probe_gl_1 = require("probe.gl");
|
|
6
|
+
exports.probeLog = new probe_gl_1.Log({ id: 'loaders.gl' });
|
|
7
|
+
// Logs nothing
|
|
8
|
+
class NullLog {
|
|
9
|
+
log() {
|
|
10
|
+
return () => { };
|
|
11
|
+
}
|
|
12
|
+
info() {
|
|
13
|
+
return () => { };
|
|
14
|
+
}
|
|
15
|
+
warn() {
|
|
16
|
+
return () => { };
|
|
17
|
+
}
|
|
18
|
+
error() {
|
|
19
|
+
return () => { };
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.NullLog = NullLog;
|
|
23
|
+
// Logs to console
|
|
24
|
+
class ConsoleLog {
|
|
25
|
+
constructor() {
|
|
26
|
+
this.console = console; // eslint-disable-line
|
|
27
|
+
}
|
|
28
|
+
log(...args) {
|
|
29
|
+
return this.console.log.bind(this.console, ...args);
|
|
30
|
+
}
|
|
31
|
+
info(...args) {
|
|
32
|
+
return this.console.info.bind(this.console, ...args);
|
|
33
|
+
}
|
|
34
|
+
warn(...args) {
|
|
35
|
+
return this.console.warn.bind(this.console, ...args);
|
|
36
|
+
}
|
|
37
|
+
error(...args) {
|
|
38
|
+
return this.console.error.bind(this.console, ...args);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.ConsoleLog = ConsoleLog;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize-loader.d.ts","sourceRoot":"","sources":["../../../src/lib/loader-utils/normalize-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,0BAA0B,CAAC;AAGrD,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,GAAG,GAAG,OAAO,CAqBpD;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAiCtD"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeLoader = exports.isLoaderObject = void 0;
|
|
4
|
+
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
5
|
+
function isLoaderObject(loader) {
|
|
6
|
+
if (!loader) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
if (Array.isArray(loader)) {
|
|
10
|
+
loader = loader[0];
|
|
11
|
+
}
|
|
12
|
+
const hasExtensions = Array.isArray(loader?.extensions);
|
|
13
|
+
/* Now handled by types and worker loaders do not have these
|
|
14
|
+
let hasParser =
|
|
15
|
+
loader.parseTextSync ||
|
|
16
|
+
loader.parseSync ||
|
|
17
|
+
loader.parse ||
|
|
18
|
+
loader.parseStream || // TODO Remove, Replace with parseInBatches
|
|
19
|
+
loader.parseInBatches;
|
|
20
|
+
*/
|
|
21
|
+
return hasExtensions;
|
|
22
|
+
}
|
|
23
|
+
exports.isLoaderObject = isLoaderObject;
|
|
24
|
+
function normalizeLoader(loader) {
|
|
25
|
+
// This error is fairly easy to trigger by mixing up import statements etc
|
|
26
|
+
// So we make an exception and add a developer error message for this case
|
|
27
|
+
// To help new users from getting stuck here
|
|
28
|
+
(0, loader_utils_1.assert)(loader, 'null loader');
|
|
29
|
+
(0, loader_utils_1.assert)(isLoaderObject(loader), 'invalid loader');
|
|
30
|
+
// NORMALIZE [LOADER, OPTIONS] => LOADER
|
|
31
|
+
// If [loader, options], create a new loaders object with options merged in
|
|
32
|
+
let options;
|
|
33
|
+
if (Array.isArray(loader)) {
|
|
34
|
+
options = loader[1];
|
|
35
|
+
loader = loader[0];
|
|
36
|
+
loader = {
|
|
37
|
+
...loader,
|
|
38
|
+
options: { ...loader.options, ...options }
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
// NORMALIZE text and binary flags
|
|
42
|
+
// Ensure at least one of text/binary flags are properly set
|
|
43
|
+
// @ts-expect-error
|
|
44
|
+
if (loader?.parseTextSync || loader?.parseText) {
|
|
45
|
+
loader.text = true;
|
|
46
|
+
}
|
|
47
|
+
if (!loader.text) {
|
|
48
|
+
loader.binary = true;
|
|
49
|
+
}
|
|
50
|
+
return loader;
|
|
51
|
+
}
|
|
52
|
+
exports.normalizeLoader = normalizeLoader;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { LoaderOptions } from '@loaders.gl/loader-utils';
|
|
2
|
+
export declare const DEFAULT_LOADER_OPTIONS: LoaderOptions;
|
|
3
|
+
export declare const REMOVED_LOADER_OPTIONS: {
|
|
4
|
+
throws: string;
|
|
5
|
+
dataType: string;
|
|
6
|
+
uri: string;
|
|
7
|
+
method: string;
|
|
8
|
+
headers: string;
|
|
9
|
+
body: string;
|
|
10
|
+
mode: string;
|
|
11
|
+
credentials: string;
|
|
12
|
+
cache: string;
|
|
13
|
+
redirect: string;
|
|
14
|
+
referrer: string;
|
|
15
|
+
referrerPolicy: string;
|
|
16
|
+
integrity: string;
|
|
17
|
+
keepalive: string;
|
|
18
|
+
signal: string;
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=option-defaults.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"option-defaults.d.ts","sourceRoot":"","sources":["../../../src/lib/loader-utils/option-defaults.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAG5D,eAAO,MAAM,sBAAsB,EAAE,aAoBpC,CAAC;AAEF,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;CAiBlC,CAAC"}
|