@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,7 @@
|
|
|
1
|
+
import { Loader } from '@loaders.gl/loader-utils';
|
|
2
|
+
/** Register a list of global loaders */
|
|
3
|
+
export declare function registerLoaders(loaders: Loader[]): void;
|
|
4
|
+
export declare function getRegisteredLoaders(): Loader[];
|
|
5
|
+
/** @deprecated For testing only */
|
|
6
|
+
export declare function _unregisterLoaders(): void;
|
|
7
|
+
//# sourceMappingURL=register-loaders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register-loaders.d.ts","sourceRoot":"","sources":["../../../src/lib/api/register-loaders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,0BAA0B,CAAC;AAYhD,wCAAwC;AACxC,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,QAYhD;AAED,wBAAgB,oBAAoB,IAAI,MAAM,EAAE,CAE/C;AAED,oCAAoC;AACpC,wBAAgB,kBAAkB,SAGjC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports._unregisterLoaders = exports.getRegisteredLoaders = exports.registerLoaders = void 0;
|
|
4
|
+
const normalize_loader_1 = require("../loader-utils/normalize-loader");
|
|
5
|
+
const option_utils_1 = require("../loader-utils/option-utils");
|
|
6
|
+
// Store global registered loaders on the global object to increase chances of cross loaders-version interoperability
|
|
7
|
+
// This use case is not reliable but can help when testing new versions of loaders.gl with existing frameworks
|
|
8
|
+
const getGlobalLoaderRegistry = () => {
|
|
9
|
+
const state = (0, option_utils_1.getGlobalLoaderState)();
|
|
10
|
+
state.loaderRegistry = state.loaderRegistry || [];
|
|
11
|
+
return state.loaderRegistry;
|
|
12
|
+
};
|
|
13
|
+
/** Register a list of global loaders */
|
|
14
|
+
function registerLoaders(loaders) {
|
|
15
|
+
const loaderRegistry = getGlobalLoaderRegistry();
|
|
16
|
+
loaders = Array.isArray(loaders) ? loaders : [loaders];
|
|
17
|
+
for (const loader of loaders) {
|
|
18
|
+
const normalizedLoader = (0, normalize_loader_1.normalizeLoader)(loader);
|
|
19
|
+
if (!loaderRegistry.find((registeredLoader) => normalizedLoader === registeredLoader)) {
|
|
20
|
+
// add to the beginning of the loaderRegistry, so the last registeredLoader get picked
|
|
21
|
+
loaderRegistry.unshift(normalizedLoader);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.registerLoaders = registerLoaders;
|
|
26
|
+
function getRegisteredLoaders() {
|
|
27
|
+
return getGlobalLoaderRegistry();
|
|
28
|
+
}
|
|
29
|
+
exports.getRegisteredLoaders = getRegisteredLoaders;
|
|
30
|
+
/** @deprecated For testing only */
|
|
31
|
+
function _unregisterLoaders() {
|
|
32
|
+
const state = (0, option_utils_1.getGlobalLoaderState)();
|
|
33
|
+
state.loaderRegistry = [];
|
|
34
|
+
}
|
|
35
|
+
exports._unregisterLoaders = _unregisterLoaders;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Writer, WriterOptions } from '@loaders.gl/loader-utils';
|
|
2
|
+
export declare function save(data: any, url: any, writer: Writer, options: WriterOptions): Promise<void>;
|
|
3
|
+
export declare function saveSync(data: any, url: any, writer: any, options: any): void;
|
|
4
|
+
//# sourceMappingURL=save.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"save.d.ts","sourceRoot":"","sources":["../../../src/lib/api/save.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAIpE,wBAAsB,IAAI,CAAC,IAAI,KAAA,EAAE,GAAG,KAAA,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,iBAG3E;AAED,wBAAgB,QAAQ,CAAC,IAAI,KAAA,EAAE,GAAG,KAAA,EAAE,MAAM,KAAA,EAAE,OAAO,KAAA,QAGlD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.saveSync = exports.save = void 0;
|
|
4
|
+
const encode_1 = require("./encode");
|
|
5
|
+
const write_file_1 = require("../fetch/write-file");
|
|
6
|
+
async function save(data, url, writer, options) {
|
|
7
|
+
const encodedData = await (0, encode_1.encode)(data, writer, options);
|
|
8
|
+
return await (0, write_file_1.writeFile)(url, encodedData);
|
|
9
|
+
}
|
|
10
|
+
exports.save = save;
|
|
11
|
+
function saveSync(data, url, writer, options) {
|
|
12
|
+
const encodedData = (0, encode_1.encodeSync)(data, writer, options);
|
|
13
|
+
return (0, write_file_1.writeFileSync)(url, encodedData);
|
|
14
|
+
}
|
|
15
|
+
exports.saveSync = saveSync;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { LoaderContext, LoaderOptions, Loader } from '@loaders.gl/loader-utils';
|
|
2
|
+
/**
|
|
3
|
+
* Find a loader that matches file extension and/or initial file content
|
|
4
|
+
* Search the loaders array argument for a loader that matches url extension or initial data
|
|
5
|
+
* Returns: a normalized loader
|
|
6
|
+
* @param data data to assist
|
|
7
|
+
* @param loaders
|
|
8
|
+
* @param options
|
|
9
|
+
* @param context used internally, applications should not provide this parameter
|
|
10
|
+
*/
|
|
11
|
+
export declare function selectLoader(data: Response | Blob | ArrayBuffer | string, loaders?: Loader[] | Loader, options?: LoaderOptions, context?: LoaderContext): Promise<Loader | null>;
|
|
12
|
+
/**
|
|
13
|
+
* Find a loader that matches file extension and/or initial file content
|
|
14
|
+
* Search the loaders array argument for a loader that matches url extension or initial data
|
|
15
|
+
* Returns: a normalized loader
|
|
16
|
+
* @param data data to assist
|
|
17
|
+
* @param loaders
|
|
18
|
+
* @param options
|
|
19
|
+
* @param context used internally, applications should not provide this parameter
|
|
20
|
+
*/
|
|
21
|
+
export declare function selectLoaderSync(data: Response | Blob | ArrayBuffer | string, loaders?: Loader[] | Loader, options?: LoaderOptions, context?: LoaderContext): Loader | null;
|
|
22
|
+
//# sourceMappingURL=select-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select-loader.d.ts","sourceRoot":"","sources":["../../../src/lib/api/select-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,aAAa,EAAE,aAAa,EAAE,MAAM,EAAC,MAAM,0BAA0B,CAAC;AAanF;;;;;;;;GAQG;AACH,wBAAsB,YAAY,CAChC,IAAI,EAAE,QAAQ,GAAG,IAAI,GAAG,WAAW,GAAG,MAAM,EAC5C,OAAO,GAAE,MAAM,EAAE,GAAG,MAAW,EAC/B,OAAO,CAAC,EAAE,aAAa,EACvB,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAwBxB;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,QAAQ,GAAG,IAAI,GAAG,WAAW,GAAG,MAAM,EAC5C,OAAO,GAAE,MAAM,EAAE,GAAG,MAAW,EAC/B,OAAO,CAAC,EAAE,aAAa,EACvB,OAAO,CAAC,EAAE,aAAa,GACtB,MAAM,GAAG,IAAI,CAmCf"}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.selectLoaderSync = exports.selectLoader = void 0;
|
|
4
|
+
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
5
|
+
const normalize_loader_1 = require("../loader-utils/normalize-loader");
|
|
6
|
+
const resource_utils_1 = require("../utils/resource-utils");
|
|
7
|
+
const register_loaders_1 = require("./register-loaders");
|
|
8
|
+
const is_type_1 = require("../../javascript-utils/is-type");
|
|
9
|
+
const EXT_PATTERN = /\.([^.]+)$/;
|
|
10
|
+
// TODO - Need a variant that peeks at streams for parseInBatches
|
|
11
|
+
// TODO - Detect multiple matching loaders? Use heuristics to grade matches?
|
|
12
|
+
// TODO - Allow apps to pass context to disambiguate between multiple matches (e.g. multiple .json formats)?
|
|
13
|
+
/**
|
|
14
|
+
* Find a loader that matches file extension and/or initial file content
|
|
15
|
+
* Search the loaders array argument for a loader that matches url extension or initial data
|
|
16
|
+
* Returns: a normalized loader
|
|
17
|
+
* @param data data to assist
|
|
18
|
+
* @param loaders
|
|
19
|
+
* @param options
|
|
20
|
+
* @param context used internally, applications should not provide this parameter
|
|
21
|
+
*/
|
|
22
|
+
async function selectLoader(data, loaders = [], options, context) {
|
|
23
|
+
if (!validHTTPResponse(data)) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
// First make a sync attempt, disabling exceptions
|
|
27
|
+
let loader = selectLoaderSync(data, loaders, { ...options, nothrow: true }, context);
|
|
28
|
+
if (loader) {
|
|
29
|
+
return loader;
|
|
30
|
+
}
|
|
31
|
+
// For Blobs and Files, try to asynchronously read a small initial slice and test again with that
|
|
32
|
+
// to see if we can detect by initial content
|
|
33
|
+
if ((0, is_type_1.isBlob)(data)) {
|
|
34
|
+
data = await data.slice(0, 10).arrayBuffer();
|
|
35
|
+
loader = selectLoaderSync(data, loaders, options, context);
|
|
36
|
+
}
|
|
37
|
+
// no loader available
|
|
38
|
+
if (!loader && !options?.nothrow) {
|
|
39
|
+
throw new Error(getNoValidLoaderMessage(data));
|
|
40
|
+
}
|
|
41
|
+
return loader;
|
|
42
|
+
}
|
|
43
|
+
exports.selectLoader = selectLoader;
|
|
44
|
+
/**
|
|
45
|
+
* Find a loader that matches file extension and/or initial file content
|
|
46
|
+
* Search the loaders array argument for a loader that matches url extension or initial data
|
|
47
|
+
* Returns: a normalized loader
|
|
48
|
+
* @param data data to assist
|
|
49
|
+
* @param loaders
|
|
50
|
+
* @param options
|
|
51
|
+
* @param context used internally, applications should not provide this parameter
|
|
52
|
+
*/
|
|
53
|
+
function selectLoaderSync(data, loaders = [], options, context) {
|
|
54
|
+
if (!validHTTPResponse(data)) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
// eslint-disable-next-line complexity
|
|
58
|
+
// if only a single loader was provided (not as array), force its use
|
|
59
|
+
// TODO - Should this behavior be kept and documented?
|
|
60
|
+
if (loaders && !Array.isArray(loaders)) {
|
|
61
|
+
// TODO - remove support for legacy loaders
|
|
62
|
+
return (0, normalize_loader_1.normalizeLoader)(loaders);
|
|
63
|
+
}
|
|
64
|
+
// Build list of candidate loaders that will be searched in order for a match
|
|
65
|
+
let candidateLoaders = [];
|
|
66
|
+
// First search supplied loaders
|
|
67
|
+
if (loaders) {
|
|
68
|
+
candidateLoaders = candidateLoaders.concat(loaders);
|
|
69
|
+
}
|
|
70
|
+
// Then fall back to registered loaders
|
|
71
|
+
if (!options?.ignoreRegisteredLoaders) {
|
|
72
|
+
candidateLoaders.push(...(0, register_loaders_1.getRegisteredLoaders)());
|
|
73
|
+
}
|
|
74
|
+
// TODO - remove support for legacy loaders
|
|
75
|
+
normalizeLoaders(candidateLoaders);
|
|
76
|
+
const loader = selectLoaderInternal(data, candidateLoaders, options, context);
|
|
77
|
+
// no loader available
|
|
78
|
+
if (!loader && !options?.nothrow) {
|
|
79
|
+
throw new Error(getNoValidLoaderMessage(data));
|
|
80
|
+
}
|
|
81
|
+
return loader;
|
|
82
|
+
}
|
|
83
|
+
exports.selectLoaderSync = selectLoaderSync;
|
|
84
|
+
/** Implements loaders selection logic */
|
|
85
|
+
function selectLoaderInternal(data, loaders, options, context) {
|
|
86
|
+
const { url, type } = (0, resource_utils_1.getResourceUrlAndType)(data);
|
|
87
|
+
const testUrl = url || context?.url;
|
|
88
|
+
let loader = null;
|
|
89
|
+
// if options.mimeType is supplied, it takes precedence
|
|
90
|
+
if (options?.mimeType) {
|
|
91
|
+
loader = findLoaderByMIMEType(loaders, options?.mimeType);
|
|
92
|
+
}
|
|
93
|
+
// Look up loader by url
|
|
94
|
+
loader = loader || findLoaderByUrl(loaders, testUrl);
|
|
95
|
+
// Look up loader by mime type
|
|
96
|
+
loader = loader || findLoaderByMIMEType(loaders, type);
|
|
97
|
+
// Look for loader via initial bytes (Note: not always accessible (e.g. Response, stream, async iterator)
|
|
98
|
+
loader = loader || findLoaderByInitialBytes(loaders, data);
|
|
99
|
+
// Look up loader by fallback mime type
|
|
100
|
+
loader = loader || findLoaderByMIMEType(loaders, options?.fallbackMimeType);
|
|
101
|
+
return loader;
|
|
102
|
+
}
|
|
103
|
+
/** Check HTTP Response */
|
|
104
|
+
function validHTTPResponse(data) {
|
|
105
|
+
// HANDLE HTTP status
|
|
106
|
+
if (data instanceof Response) {
|
|
107
|
+
// 204 - NO CONTENT. This handles cases where e.g. a tile server responds with 204 for a missing tile
|
|
108
|
+
if (data.status === 204) {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
/** Generate a helpful message to help explain why loader selection failed. */
|
|
115
|
+
function getNoValidLoaderMessage(data) {
|
|
116
|
+
const { url, type } = (0, resource_utils_1.getResourceUrlAndType)(data);
|
|
117
|
+
let message = 'No valid loader found (';
|
|
118
|
+
message += url ? `${loader_utils_1.path.filename(url)}, ` : 'no url provided, ';
|
|
119
|
+
message += `MIME type: ${type ? `"${type}"` : 'not provided'}, `;
|
|
120
|
+
// First characters are only accessible when called on data (string or arrayBuffer).
|
|
121
|
+
const firstCharacters = data ? getFirstCharacters(data) : '';
|
|
122
|
+
message += firstCharacters ? ` first bytes: "${firstCharacters}"` : 'first bytes: not available';
|
|
123
|
+
message += ')';
|
|
124
|
+
return message;
|
|
125
|
+
}
|
|
126
|
+
function normalizeLoaders(loaders) {
|
|
127
|
+
for (const loader of loaders) {
|
|
128
|
+
(0, normalize_loader_1.normalizeLoader)(loader);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
// TODO - Would be nice to support http://example.com/file.glb?parameter=1
|
|
132
|
+
// E.g: x = new URL('http://example.com/file.glb?load=1'; x.pathname
|
|
133
|
+
function findLoaderByUrl(loaders, url) {
|
|
134
|
+
// Get extension
|
|
135
|
+
const match = url && EXT_PATTERN.exec(url);
|
|
136
|
+
const extension = match && match[1];
|
|
137
|
+
return extension ? findLoaderByExtension(loaders, extension) : null;
|
|
138
|
+
}
|
|
139
|
+
function findLoaderByExtension(loaders, extension) {
|
|
140
|
+
extension = extension.toLowerCase();
|
|
141
|
+
for (const loader of loaders) {
|
|
142
|
+
for (const loaderExtension of loader.extensions) {
|
|
143
|
+
if (loaderExtension.toLowerCase() === extension) {
|
|
144
|
+
return loader;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
function findLoaderByMIMEType(loaders, mimeType) {
|
|
151
|
+
for (const loader of loaders) {
|
|
152
|
+
if (loader.mimeTypes && loader.mimeTypes.includes(mimeType)) {
|
|
153
|
+
return loader;
|
|
154
|
+
}
|
|
155
|
+
// Support referring to loaders using the "unregistered tree"
|
|
156
|
+
// https://en.wikipedia.org/wiki/Media_type#Unregistered_tree
|
|
157
|
+
if (mimeType === `application/x.${loader.id}`) {
|
|
158
|
+
return loader;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
function findLoaderByInitialBytes(loaders, data) {
|
|
164
|
+
if (!data) {
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
for (const loader of loaders) {
|
|
168
|
+
if (typeof data === 'string') {
|
|
169
|
+
if (testDataAgainstText(data, loader)) {
|
|
170
|
+
return loader;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
else if (ArrayBuffer.isView(data)) {
|
|
174
|
+
// Typed Arrays can have offsets into underlying buffer
|
|
175
|
+
if (testDataAgainstBinary(data.buffer, data.byteOffset, loader)) {
|
|
176
|
+
return loader;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
else if (data instanceof ArrayBuffer) {
|
|
180
|
+
const byteOffset = 0;
|
|
181
|
+
if (testDataAgainstBinary(data, byteOffset, loader)) {
|
|
182
|
+
return loader;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
// TODO Handle streaming case (requires creating a new AsyncIterator)
|
|
186
|
+
}
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
function testDataAgainstText(data, loader) {
|
|
190
|
+
if (loader.testText) {
|
|
191
|
+
return loader.testText(data);
|
|
192
|
+
}
|
|
193
|
+
const tests = Array.isArray(loader.tests) ? loader.tests : [loader.tests];
|
|
194
|
+
return tests.some((test) => data.startsWith(test));
|
|
195
|
+
}
|
|
196
|
+
function testDataAgainstBinary(data, byteOffset, loader) {
|
|
197
|
+
const tests = Array.isArray(loader.tests) ? loader.tests : [loader.tests];
|
|
198
|
+
return tests.some((test) => testBinary(data, byteOffset, loader, test));
|
|
199
|
+
}
|
|
200
|
+
function testBinary(data, byteOffset, loader, test) {
|
|
201
|
+
if (test instanceof ArrayBuffer) {
|
|
202
|
+
return (0, loader_utils_1.compareArrayBuffers)(test, data, test.byteLength);
|
|
203
|
+
}
|
|
204
|
+
switch (typeof test) {
|
|
205
|
+
case 'function':
|
|
206
|
+
return test(data, loader);
|
|
207
|
+
case 'string':
|
|
208
|
+
// Magic bytes check: If `test` is a string, check if binary data starts with that strings
|
|
209
|
+
const magic = getMagicString(data, byteOffset, test.length);
|
|
210
|
+
return test === magic;
|
|
211
|
+
default:
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
function getFirstCharacters(data, length = 5) {
|
|
216
|
+
if (typeof data === 'string') {
|
|
217
|
+
return data.slice(0, length);
|
|
218
|
+
}
|
|
219
|
+
else if (ArrayBuffer.isView(data)) {
|
|
220
|
+
// Typed Arrays can have offsets into underlying buffer
|
|
221
|
+
return getMagicString(data.buffer, data.byteOffset, length);
|
|
222
|
+
}
|
|
223
|
+
else if (data instanceof ArrayBuffer) {
|
|
224
|
+
const byteOffset = 0;
|
|
225
|
+
return getMagicString(data, byteOffset, length);
|
|
226
|
+
}
|
|
227
|
+
return '';
|
|
228
|
+
}
|
|
229
|
+
function getMagicString(arrayBuffer, byteOffset, length) {
|
|
230
|
+
if (arrayBuffer.byteLength < byteOffset + length) {
|
|
231
|
+
return '';
|
|
232
|
+
}
|
|
233
|
+
const dataView = new DataView(arrayBuffer);
|
|
234
|
+
let magic = '';
|
|
235
|
+
for (let i = 0; i < length; i++) {
|
|
236
|
+
magic += String.fromCharCode(dataView.getUint8(byteOffset + i));
|
|
237
|
+
}
|
|
238
|
+
return magic;
|
|
239
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set-loader-options.d.ts","sourceRoot":"","sources":["../../../src/lib/api/set-loader-options.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAEtD"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setLoaderOptions = void 0;
|
|
4
|
+
const option_utils_1 = require("../loader-utils/option-utils");
|
|
5
|
+
/**
|
|
6
|
+
* Set global loader options
|
|
7
|
+
* @param options
|
|
8
|
+
*/
|
|
9
|
+
function setLoaderOptions(options) {
|
|
10
|
+
(0, option_utils_1.setGlobalOptions)(options);
|
|
11
|
+
}
|
|
12
|
+
exports.setLoaderOptions = setLoaderOptions;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/lib/common.ts"],"names":[],"mappings":"AAAA,YAAY,EAAC,gBAAgB,EAAC,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-error-message.d.ts","sourceRoot":"","sources":["../../../src/lib/fetch/fetch-error-message.ts"],"names":[],"mappings":"AAAA,wBAAgB,+BAA+B,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAE1E;AAED,wBAAsB,2BAA2B,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAcrF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getErrorMessageFromResponse = exports.getErrorMessageFromResponseSync = void 0;
|
|
4
|
+
function getErrorMessageFromResponseSync(response) {
|
|
5
|
+
return `Failed to fetch resource ${response.url}(${response.status}): ${response.statusText} `;
|
|
6
|
+
}
|
|
7
|
+
exports.getErrorMessageFromResponseSync = getErrorMessageFromResponseSync;
|
|
8
|
+
async function getErrorMessageFromResponse(response) {
|
|
9
|
+
let message = `Failed to fetch resource ${response.url} (${response.status}): `;
|
|
10
|
+
try {
|
|
11
|
+
const contentType = response.headers.get('Content-Type') || '';
|
|
12
|
+
if (contentType.includes('application/json')) {
|
|
13
|
+
message += await response.text();
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
message += response.statusText;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
// eslint forbids return in finally statement
|
|
21
|
+
return message;
|
|
22
|
+
}
|
|
23
|
+
return message;
|
|
24
|
+
}
|
|
25
|
+
exports.getErrorMessageFromResponse = getErrorMessageFromResponse;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fetch compatible function
|
|
3
|
+
* Reads file data from:
|
|
4
|
+
* - http/http urls
|
|
5
|
+
* - data urls
|
|
6
|
+
* - File/Blob objects
|
|
7
|
+
* Leverages `@loaders.gl/polyfills` for Node.js support
|
|
8
|
+
* Respects pathPrefix and file aliases
|
|
9
|
+
*/
|
|
10
|
+
export declare function fetchFile(url: string | Blob, options?: RequestInit & {
|
|
11
|
+
fetch?: RequestInit | Function;
|
|
12
|
+
}): Promise<Response>;
|
|
13
|
+
//# sourceMappingURL=fetch-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-file.d.ts","sourceRoot":"","sources":["../../../src/lib/fetch/fetch-file.ts"],"names":[],"mappings":"AAIA;;;;;;;;GAQG;AACH,wBAAsB,SAAS,CAC7B,GAAG,EAAE,MAAM,GAAG,IAAI,EAClB,OAAO,CAAC,EAAE,WAAW,GAAG;IAAC,KAAK,CAAC,EAAE,WAAW,GAAG,QAAQ,CAAA;CAAC,GACvD,OAAO,CAAC,QAAQ,CAAC,CAanB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchFile = void 0;
|
|
4
|
+
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
5
|
+
const response_utils_1 = require("../utils/response-utils");
|
|
6
|
+
// import {getErrorMessageFromResponse} from './fetch-error-message';
|
|
7
|
+
/**
|
|
8
|
+
* fetch compatible function
|
|
9
|
+
* Reads file data from:
|
|
10
|
+
* - http/http urls
|
|
11
|
+
* - data urls
|
|
12
|
+
* - File/Blob objects
|
|
13
|
+
* Leverages `@loaders.gl/polyfills` for Node.js support
|
|
14
|
+
* Respects pathPrefix and file aliases
|
|
15
|
+
*/
|
|
16
|
+
async function fetchFile(url, options) {
|
|
17
|
+
if (typeof url === 'string') {
|
|
18
|
+
url = (0, loader_utils_1.resolvePath)(url);
|
|
19
|
+
let fetchOptions = options;
|
|
20
|
+
if (options?.fetch && typeof options?.fetch !== 'function') {
|
|
21
|
+
fetchOptions = options.fetch;
|
|
22
|
+
}
|
|
23
|
+
return await fetch(url, fetchOptions);
|
|
24
|
+
}
|
|
25
|
+
return await (0, response_utils_1.makeResponse)(url);
|
|
26
|
+
}
|
|
27
|
+
exports.fetchFile = fetchFile;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads a chunk from a random access file
|
|
3
|
+
* @param file
|
|
4
|
+
* @param start
|
|
5
|
+
* @param length
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export declare function readArrayBuffer(file: Blob | ArrayBuffer | string | number, start: number, length: number): Promise<ArrayBuffer>;
|
|
9
|
+
/**
|
|
10
|
+
* Read a slice of a Blob or File, without loading the entire file into memory
|
|
11
|
+
* The trick when reading File objects is to read successive "slices" of the File
|
|
12
|
+
* Per spec https://w3c.github.io/FileAPI/, slicing a File only updates the start and end fields
|
|
13
|
+
* Actually reading from file happens in `readAsArrayBuffer`
|
|
14
|
+
* @param blob to read
|
|
15
|
+
*/
|
|
16
|
+
export declare function readBlob(blob: Blob): Promise<ArrayBuffer>;
|
|
17
|
+
//# sourceMappingURL=read-array-buffer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-array-buffer.d.ts","sourceRoot":"","sources":["../../../src/lib/fetch/read-array-buffer.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,wBAAsB,eAAe,CACnC,IAAI,EAAE,IAAI,GAAG,WAAW,GAAG,MAAM,GAAG,MAAM,EAC1C,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,WAAW,CAAC,CAUtB;AAED;;;;;;GAMG;AACH,wBAAsB,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC,CAS/D"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readBlob = exports.readArrayBuffer = void 0;
|
|
4
|
+
//
|
|
5
|
+
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
6
|
+
/**
|
|
7
|
+
* Reads a chunk from a random access file
|
|
8
|
+
* @param file
|
|
9
|
+
* @param start
|
|
10
|
+
* @param length
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
async function readArrayBuffer(file, start, length) {
|
|
14
|
+
if (typeof file === 'number') {
|
|
15
|
+
return await loader_utils_1.fs._readToArrayBuffer(file, start, length);
|
|
16
|
+
}
|
|
17
|
+
// TODO - we can do better for ArrayBuffer and string
|
|
18
|
+
if (!(file instanceof Blob)) {
|
|
19
|
+
file = new Blob([file]);
|
|
20
|
+
}
|
|
21
|
+
const slice = file.slice(start, start + length);
|
|
22
|
+
return await readBlob(slice);
|
|
23
|
+
}
|
|
24
|
+
exports.readArrayBuffer = readArrayBuffer;
|
|
25
|
+
/**
|
|
26
|
+
* Read a slice of a Blob or File, without loading the entire file into memory
|
|
27
|
+
* The trick when reading File objects is to read successive "slices" of the File
|
|
28
|
+
* Per spec https://w3c.github.io/FileAPI/, slicing a File only updates the start and end fields
|
|
29
|
+
* Actually reading from file happens in `readAsArrayBuffer`
|
|
30
|
+
* @param blob to read
|
|
31
|
+
*/
|
|
32
|
+
async function readBlob(blob) {
|
|
33
|
+
return await new Promise((resolve, reject) => {
|
|
34
|
+
const fileReader = new FileReader();
|
|
35
|
+
fileReader.onload = (event) => resolve(event?.target?.result);
|
|
36
|
+
// TODO - reject with a proper Error
|
|
37
|
+
fileReader.onerror = (error) => reject(error);
|
|
38
|
+
fileReader.readAsArrayBuffer(blob);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
exports.readBlob = readBlob;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-file.d.ts","sourceRoot":"","sources":["../../../src/lib/fetch/read-file.ts"],"names":[],"mappings":"AAOA;;GAEG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,MAAW,sBAoB7D"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readFileSync = void 0;
|
|
4
|
+
// File read
|
|
5
|
+
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
6
|
+
const loader_utils_2 = require("@loaders.gl/loader-utils");
|
|
7
|
+
// TODO - this is not tested
|
|
8
|
+
// const isDataURL = (url) => url.startsWith('data:');
|
|
9
|
+
/**
|
|
10
|
+
* In a few cases (data URIs, node.js) "files" can be read synchronously
|
|
11
|
+
*/
|
|
12
|
+
function readFileSync(url, options = {}) {
|
|
13
|
+
url = (0, loader_utils_1.resolvePath)(url);
|
|
14
|
+
// Only support this if we can also support sync data URL decoding in browser
|
|
15
|
+
// if (isDataURL(url)) {
|
|
16
|
+
// return decodeDataUri(url);
|
|
17
|
+
// }
|
|
18
|
+
if (!loader_utils_1.isBrowser) {
|
|
19
|
+
const buffer = loader_utils_1.fs.readFileSync(url, options);
|
|
20
|
+
return typeof buffer !== 'string' ? (0, loader_utils_1.toArrayBuffer)(buffer) : buffer;
|
|
21
|
+
}
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
if (!options.nothrow) {
|
|
24
|
+
// throw new Error('Cant load URI synchronously');
|
|
25
|
+
(0, loader_utils_2.assert)(false);
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
exports.readFileSync = readFileSync;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare function writeFile(filePath: string, arrayBufferOrString: ArrayBuffer | string, options?: any): Promise<void>;
|
|
2
|
+
export declare function writeFileSync(filePath: string, arrayBufferOrString: ArrayBuffer | string, options?: any): void;
|
|
3
|
+
//# sourceMappingURL=write-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write-file.d.ts","sourceRoot":"","sources":["../../../src/lib/fetch/write-file.ts"],"names":[],"mappings":"AAIA,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,MAAM,EAChB,mBAAmB,EAAE,WAAW,GAAG,MAAM,EACzC,OAAO,CAAC,KAAA,GACP,OAAO,CAAC,IAAI,CAAC,CAMf;AAED,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,EAChB,mBAAmB,EAAE,WAAW,GAAG,MAAM,EACzC,OAAO,CAAC,KAAA,GACP,IAAI,CAMN"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.writeFileSync = exports.writeFile = void 0;
|
|
4
|
+
// file write
|
|
5
|
+
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
6
|
+
const loader_utils_2 = require("@loaders.gl/loader-utils");
|
|
7
|
+
async function writeFile(filePath, arrayBufferOrString, options) {
|
|
8
|
+
filePath = (0, loader_utils_1.resolvePath)(filePath);
|
|
9
|
+
if (!loader_utils_1.isBrowser) {
|
|
10
|
+
await loader_utils_2.fs.writeFile(filePath, (0, loader_utils_2.toBuffer)(arrayBufferOrString), { flag: 'w' });
|
|
11
|
+
}
|
|
12
|
+
(0, loader_utils_1.assert)(false);
|
|
13
|
+
}
|
|
14
|
+
exports.writeFile = writeFile;
|
|
15
|
+
function writeFileSync(filePath, arrayBufferOrString, options) {
|
|
16
|
+
filePath = (0, loader_utils_1.resolvePath)(filePath);
|
|
17
|
+
if (!loader_utils_1.isBrowser) {
|
|
18
|
+
loader_utils_2.fs.writeFileSync(filePath, (0, loader_utils_2.toBuffer)(arrayBufferOrString), { flag: 'w' });
|
|
19
|
+
}
|
|
20
|
+
(0, loader_utils_1.assert)(false);
|
|
21
|
+
}
|
|
22
|
+
exports.writeFileSync = writeFileSync;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { FileSystem } from './filesystem';
|
|
2
|
+
declare type BrowserFileSystemOptions = {
|
|
3
|
+
fetch?: typeof fetch;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* FileSystem adapter for a browser FileList.
|
|
7
|
+
* Holds a list of browser 'File' objects.
|
|
8
|
+
*/
|
|
9
|
+
export default class BrowserFileSystem implements FileSystem {
|
|
10
|
+
private _fetch;
|
|
11
|
+
private files;
|
|
12
|
+
private lowerCaseFiles;
|
|
13
|
+
private usedFiles;
|
|
14
|
+
/**
|
|
15
|
+
* A FileSystem API wrapper around a list of browser 'File' objects
|
|
16
|
+
* @param files
|
|
17
|
+
* @param options
|
|
18
|
+
*/
|
|
19
|
+
constructor(files: FileList | File[], options?: BrowserFileSystemOptions);
|
|
20
|
+
/**
|
|
21
|
+
* Implementation of fetch against this file system
|
|
22
|
+
* Delegates to global fetch for http{s}:// or data://
|
|
23
|
+
*/
|
|
24
|
+
fetch(path: string, options?: RequestInit): Promise<Response>;
|
|
25
|
+
/**
|
|
26
|
+
* List filenames in this filesystem
|
|
27
|
+
* @param dirname
|
|
28
|
+
* @returns
|
|
29
|
+
*/
|
|
30
|
+
readdir(dirname?: string): Promise<string[]>;
|
|
31
|
+
/**
|
|
32
|
+
* Return information (size) about files in this file system
|
|
33
|
+
*/
|
|
34
|
+
stat(path: string, options?: object): Promise<{
|
|
35
|
+
size: number;
|
|
36
|
+
}>;
|
|
37
|
+
/**
|
|
38
|
+
* Just removes the file from the list
|
|
39
|
+
*/
|
|
40
|
+
unlink(path: string): Promise<void>;
|
|
41
|
+
open(pathname: string, flags: any, mode?: any): Promise<any>;
|
|
42
|
+
/**
|
|
43
|
+
* Read a range into a buffer
|
|
44
|
+
* @todo - handle position memory
|
|
45
|
+
* @param buffer is the buffer that the data (read from the fd) will be written to.
|
|
46
|
+
* @param offset is the offset in the buffer to start writing at.
|
|
47
|
+
* @param length is an integer specifying the number of bytes to read.
|
|
48
|
+
* @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.
|
|
49
|
+
*/
|
|
50
|
+
read(fd: any, buffer: ArrayBuffer, offset?: number, length?: number, position?: number | null): Promise<{
|
|
51
|
+
bytesRead: number;
|
|
52
|
+
buffer: ArrayBuffer;
|
|
53
|
+
}>;
|
|
54
|
+
close(fd: number): Promise<void>;
|
|
55
|
+
_getFile(path: any, used: any): File;
|
|
56
|
+
}
|
|
57
|
+
export {};
|
|
58
|
+
//# sourceMappingURL=browser-filesystem.d.ts.map
|