@loaders.gl/core 4.2.0-alpha.3 → 4.2.0-alpha.5
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/core-addons/write-file-browser.js +62 -1
- package/dist/dist.dev.js +366 -332
- package/dist/dist.min.js +15 -0
- package/dist/index.cjs +55 -68
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +20 -20
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -1
- package/dist/iterators/batch-iterators/timed-batch-iterator.js +18 -13
- package/dist/iterators/make-iterator/make-array-buffer-iterator.d.ts +1 -1
- package/dist/iterators/make-iterator/make-array-buffer-iterator.d.ts.map +1 -1
- package/dist/iterators/make-iterator/make-array-buffer-iterator.js +21 -15
- package/dist/iterators/make-iterator/make-blob-iterator.d.ts +1 -1
- package/dist/iterators/make-iterator/make-blob-iterator.d.ts.map +1 -1
- package/dist/iterators/make-iterator/make-blob-iterator.js +18 -10
- package/dist/iterators/make-iterator/make-iterator.d.ts +1 -1
- package/dist/iterators/make-iterator/make-iterator.d.ts.map +1 -1
- package/dist/iterators/make-iterator/make-iterator.js +29 -18
- package/dist/iterators/make-iterator/make-stream-iterator.js +86 -23
- package/dist/iterators/make-iterator/make-string-iterator.d.ts +1 -1
- package/dist/iterators/make-iterator/make-string-iterator.d.ts.map +1 -1
- package/dist/iterators/make-iterator/make-string-iterator.js +20 -10
- package/dist/iterators/make-stream/make-stream.js +47 -29
- package/dist/javascript-utils/is-type.js +25 -19
- package/dist/lib/api/encode-table.js +40 -35
- package/dist/lib/api/encode.js +112 -73
- package/dist/lib/api/load-in-batches.js +35 -21
- package/dist/lib/api/load.js +35 -20
- package/dist/lib/api/loader-options.d.ts +2 -2
- package/dist/lib/api/loader-options.d.ts.map +1 -1
- package/dist/lib/api/loader-options.js +3 -1
- package/dist/lib/api/parse-in-batches.js +105 -69
- package/dist/lib/api/parse-sync.js +42 -33
- package/dist/lib/api/parse.js +73 -61
- package/dist/lib/api/register-loaders.js +23 -14
- package/dist/lib/api/select-loader.js +216 -163
- package/dist/lib/common.js +3 -1
- package/dist/lib/fetch/fetch-error-message.js +17 -12
- package/dist/lib/fetch/fetch-file.js +26 -15
- package/dist/lib/fetch/read-array-buffer.js +30 -15
- package/dist/lib/filesystems/browser-filesystem.js +126 -69
- package/dist/lib/filesystems/read-array-buffer.js +14 -6
- package/dist/lib/init.js +13 -7
- package/dist/lib/loader-utils/check-errors.js +37 -16
- package/dist/lib/loader-utils/get-data.js +110 -88
- package/dist/lib/loader-utils/get-fetch-function.js +24 -13
- package/dist/lib/loader-utils/loader-context.js +50 -31
- package/dist/lib/loader-utils/loggers.js +34 -44
- package/dist/lib/loader-utils/normalize-loader.js +45 -32
- package/dist/lib/loader-utils/option-defaults.js +38 -34
- package/dist/lib/loader-utils/option-utils.d.ts.map +1 -1
- package/dist/lib/loader-utils/option-utils.js +133 -80
- package/dist/lib/progress/fetch-progress.js +54 -47
- package/dist/lib/utils/log.js +4 -4
- package/dist/lib/utils/mime-type-utils.js +34 -11
- package/dist/lib/utils/resource-utils.js +77 -45
- package/dist/lib/utils/response-utils.js +97 -74
- package/dist/lib/utils/url-utils.js +6 -4
- package/dist/null-loader.js +44 -30
- package/dist/null-worker-node.js +1 -1
- package/dist/null-worker.js +1 -1
- package/dist/workers/null-worker-node.js +3 -1
- package/dist/workers/null-worker.js +3 -1
- package/package.json +7 -7
- package/src/lib/loader-utils/option-utils.ts +3 -1
- package/dist/core-addons/README.md +0 -1
- package/dist/core-addons/write-file-browser.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/iterators/batch-iterators/timed-batch-iterator.js.map +0 -1
- package/dist/iterators/make-iterator/make-array-buffer-iterator.js.map +0 -1
- package/dist/iterators/make-iterator/make-blob-iterator.js.map +0 -1
- package/dist/iterators/make-iterator/make-iterator.js.map +0 -1
- package/dist/iterators/make-iterator/make-stream-iterator.js.map +0 -1
- package/dist/iterators/make-iterator/make-string-iterator.js.map +0 -1
- package/dist/iterators/make-stream/make-stream.js.map +0 -1
- package/dist/javascript-utils/is-type.js.map +0 -1
- package/dist/lib/api/encode-table.js.map +0 -1
- package/dist/lib/api/encode.js.map +0 -1
- package/dist/lib/api/load-in-batches.js.map +0 -1
- package/dist/lib/api/load.js.map +0 -1
- package/dist/lib/api/loader-options.js.map +0 -1
- package/dist/lib/api/parse-in-batches.js.map +0 -1
- package/dist/lib/api/parse-sync.js.map +0 -1
- package/dist/lib/api/parse.js.map +0 -1
- package/dist/lib/api/register-loaders.js.map +0 -1
- package/dist/lib/api/select-loader.js.map +0 -1
- package/dist/lib/common.js.map +0 -1
- package/dist/lib/fetch/fetch-error-message.js.map +0 -1
- package/dist/lib/fetch/fetch-file.js.map +0 -1
- package/dist/lib/fetch/read-array-buffer.js.map +0 -1
- package/dist/lib/filesystems/browser-filesystem.js.map +0 -1
- package/dist/lib/filesystems/read-array-buffer.js.map +0 -1
- package/dist/lib/init.js.map +0 -1
- package/dist/lib/loader-utils/check-errors.js.map +0 -1
- package/dist/lib/loader-utils/get-data.js.map +0 -1
- package/dist/lib/loader-utils/get-fetch-function.js.map +0 -1
- package/dist/lib/loader-utils/loader-context.js.map +0 -1
- package/dist/lib/loader-utils/loggers.js.map +0 -1
- package/dist/lib/loader-utils/normalize-loader.js.map +0 -1
- package/dist/lib/loader-utils/option-defaults.js.map +0 -1
- package/dist/lib/loader-utils/option-utils.js.map +0 -1
- package/dist/lib/progress/fetch-progress.js.map +0 -1
- package/dist/lib/utils/log.js.map +0 -1
- package/dist/lib/utils/mime-type-utils.js.map +0 -1
- package/dist/lib/utils/resource-utils.js.map +0 -1
- package/dist/lib/utils/response-utils.js.map +0 -1
- package/dist/lib/utils/url-utils.js.map +0 -1
- package/dist/null-loader.js.map +0 -1
- package/dist/workers/null-worker-node.js.map +0 -1
- package/dist/workers/null-worker.js.map +0 -1
|
@@ -1,52 +1,59 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (!(totalBytes > 0)) {
|
|
15
|
-
return response;
|
|
16
|
-
}
|
|
17
|
-
if (typeof ReadableStream === 'undefined' || !body.getReader) {
|
|
18
|
-
return response;
|
|
19
|
-
}
|
|
20
|
-
const progressStream = new ReadableStream({
|
|
21
|
-
async start(controller) {
|
|
22
|
-
const reader = body.getReader();
|
|
23
|
-
await read(controller, reader, 0, totalBytes, onProgress, onDone, onError);
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
// Forked from github AnthumChris/fetch-progress-indicators under MIT license
|
|
5
|
+
/**
|
|
6
|
+
* Intercepts the Response stream and creates a new Response
|
|
7
|
+
*/
|
|
8
|
+
export async function fetchProgress(response, onProgress, // TODO better callback types
|
|
9
|
+
onDone = () => { }, onError = () => { }) {
|
|
10
|
+
response = await response;
|
|
11
|
+
if (!response.ok) {
|
|
12
|
+
// ERROR checking needs to be done separately
|
|
13
|
+
return response;
|
|
24
14
|
}
|
|
25
|
-
|
|
26
|
-
|
|
15
|
+
const body = response.body;
|
|
16
|
+
if (!body) {
|
|
17
|
+
// 'ReadableStream not yet supported in this browser.
|
|
18
|
+
return response;
|
|
19
|
+
}
|
|
20
|
+
const contentLength = response.headers.get('content-length') || 0;
|
|
21
|
+
const totalBytes = contentLength ? parseInt(contentLength) : 0;
|
|
22
|
+
if (!(totalBytes > 0)) {
|
|
23
|
+
return response;
|
|
24
|
+
}
|
|
25
|
+
// Currently override only implemented in browser
|
|
26
|
+
if (typeof ReadableStream === 'undefined' || !body.getReader) {
|
|
27
|
+
return response;
|
|
28
|
+
}
|
|
29
|
+
// Create a new stream that invisbly wraps original stream
|
|
30
|
+
const progressStream = new ReadableStream({
|
|
31
|
+
async start(controller) {
|
|
32
|
+
const reader = body.getReader();
|
|
33
|
+
await read(controller, reader, 0, totalBytes, onProgress, onDone, onError);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return new Response(progressStream);
|
|
27
37
|
}
|
|
38
|
+
// Forward to original streams controller
|
|
39
|
+
// TODO - this causes a crazy deep "async stack"... rewrite as async iterator?
|
|
40
|
+
// eslint-disable-next-line max-params
|
|
28
41
|
async function read(controller, reader, loadedBytes, totalBytes, onProgress, onDone, onError) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
42
|
+
try {
|
|
43
|
+
const { done, value } = await reader.read();
|
|
44
|
+
if (done) {
|
|
45
|
+
onDone();
|
|
46
|
+
controller.close();
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
loadedBytes += value.byteLength;
|
|
50
|
+
const percent = Math.round((loadedBytes / totalBytes) * 100);
|
|
51
|
+
onProgress(percent, { loadedBytes, totalBytes });
|
|
52
|
+
controller.enqueue(value);
|
|
53
|
+
await read(controller, reader, loadedBytes, totalBytes, onProgress, onDone, onError);
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
controller.error(error);
|
|
57
|
+
onError(error);
|
|
38
58
|
}
|
|
39
|
-
loadedBytes += value.byteLength;
|
|
40
|
-
const percent = Math.round(loadedBytes / totalBytes * 100);
|
|
41
|
-
onProgress(percent, {
|
|
42
|
-
loadedBytes,
|
|
43
|
-
totalBytes
|
|
44
|
-
});
|
|
45
|
-
controller.enqueue(value);
|
|
46
|
-
await read(controller, reader, loadedBytes, totalBytes, onProgress, onDone, onError);
|
|
47
|
-
} catch (error) {
|
|
48
|
-
controller.error(error);
|
|
49
|
-
onError(error);
|
|
50
|
-
}
|
|
51
59
|
}
|
|
52
|
-
//# sourceMappingURL=fetch-progress.js.map
|
package/dist/lib/utils/log.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
import { Log } from '@probe.gl/log';
|
|
2
|
-
export const log = new Log({
|
|
3
|
-
id: 'loaders.gl'
|
|
4
|
-
});
|
|
5
|
-
//# sourceMappingURL=log.js.map
|
|
5
|
+
export const log = new Log({ id: 'loaders.gl' });
|
|
@@ -1,17 +1,40 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
// TODO - build/integrate proper MIME type parsing
|
|
5
|
+
// https://mimesniff.spec.whatwg.org/
|
|
1
6
|
const DATA_URL_PATTERN = /^data:([-\w.]+\/[-\w.+]+)(;|,)/;
|
|
2
7
|
const MIME_TYPE_PATTERN = /^([-\w.]+\/[-\w.+]+)/;
|
|
8
|
+
/**
|
|
9
|
+
* Remove extra data like `charset` from MIME types
|
|
10
|
+
* @param mimeString
|
|
11
|
+
* @returns A clean MIME type, or an empty string
|
|
12
|
+
*
|
|
13
|
+
* @todo - handle more advanced MIMETYpes, multiple types
|
|
14
|
+
* @todo - extract charset etc
|
|
15
|
+
*/
|
|
3
16
|
export function parseMIMEType(mimeString) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
17
|
+
// If resource is a data url, extract any embedded mime type
|
|
18
|
+
const matches = MIME_TYPE_PATTERN.exec(mimeString);
|
|
19
|
+
if (matches) {
|
|
20
|
+
return matches[1];
|
|
21
|
+
}
|
|
22
|
+
return mimeString;
|
|
9
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Extract MIME type from data URL
|
|
26
|
+
*
|
|
27
|
+
* @param mimeString
|
|
28
|
+
* @returns A clean MIME type, or an empty string
|
|
29
|
+
*
|
|
30
|
+
* @todo - handle more advanced MIMETYpes, multiple types
|
|
31
|
+
* @todo - extract charset etc
|
|
32
|
+
*/
|
|
10
33
|
export function parseMIMETypeFromURL(url) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
34
|
+
// If resource is a data URL, extract any embedded mime type
|
|
35
|
+
const matches = DATA_URL_PATTERN.exec(url);
|
|
36
|
+
if (matches) {
|
|
37
|
+
return matches[1];
|
|
38
|
+
}
|
|
39
|
+
return '';
|
|
16
40
|
}
|
|
17
|
-
//# sourceMappingURL=mime-type-utils.js.map
|
|
@@ -1,54 +1,86 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
import { isResponse, isBlob } from "../../javascript-utils/is-type.js";
|
|
2
5
|
import { parseMIMEType, parseMIMETypeFromURL } from "./mime-type-utils.js";
|
|
3
6
|
import { stripQueryString } from "./url-utils.js";
|
|
7
|
+
/**
|
|
8
|
+
* Returns the URL associated with this resource.
|
|
9
|
+
* The returned value may include a query string and need further processing.
|
|
10
|
+
* If it cannot determine url, the corresponding value will be an empty string
|
|
11
|
+
*
|
|
12
|
+
* @todo string parameters are assumed to be URLs
|
|
13
|
+
*/
|
|
4
14
|
export function getResourceUrl(resource) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
// If resource is a `Response`, it contains the information directly as a field
|
|
16
|
+
if (isResponse(resource)) {
|
|
17
|
+
const response = resource;
|
|
18
|
+
return response.url;
|
|
19
|
+
}
|
|
20
|
+
// If the resource is a Blob or a File (subclass of Blob)
|
|
21
|
+
if (isBlob(resource)) {
|
|
22
|
+
const blob = resource;
|
|
23
|
+
// File objects have a "name" property. Blob objects don't have any
|
|
24
|
+
// url (name) information
|
|
25
|
+
return blob.name || '';
|
|
26
|
+
}
|
|
27
|
+
if (typeof resource === 'string') {
|
|
28
|
+
return resource;
|
|
29
|
+
}
|
|
30
|
+
// Unknown
|
|
31
|
+
return '';
|
|
17
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Returns the URL associated with this resource.
|
|
35
|
+
* The returned value may include a query string and need further processing.
|
|
36
|
+
* If it cannot determine url, the corresponding value will be an empty string
|
|
37
|
+
*
|
|
38
|
+
* @todo string parameters are assumed to be URLs
|
|
39
|
+
*/
|
|
18
40
|
export function getResourceMIMEType(resource) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
41
|
+
// If resource is a response, it contains the information directly
|
|
42
|
+
if (isResponse(resource)) {
|
|
43
|
+
const response = resource;
|
|
44
|
+
const contentTypeHeader = response.headers.get('content-type') || '';
|
|
45
|
+
const noQueryUrl = stripQueryString(response.url);
|
|
46
|
+
return parseMIMEType(contentTypeHeader) || parseMIMETypeFromURL(noQueryUrl);
|
|
47
|
+
}
|
|
48
|
+
// If the resource is a Blob or a File (subclass of Blob)
|
|
49
|
+
if (isBlob(resource)) {
|
|
50
|
+
const blob = resource;
|
|
51
|
+
return blob.type || '';
|
|
52
|
+
}
|
|
53
|
+
if (typeof resource === 'string') {
|
|
54
|
+
return parseMIMETypeFromURL(resource);
|
|
55
|
+
}
|
|
56
|
+
// Unknown
|
|
57
|
+
return '';
|
|
33
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Returns (approximate) content length for a resource if it can be determined.
|
|
61
|
+
* Returns -1 if content length cannot be determined.
|
|
62
|
+
* @param resource
|
|
63
|
+
|
|
64
|
+
* @note string parameters are NOT assumed to be URLs
|
|
65
|
+
*/
|
|
34
66
|
export function getResourceContentLength(resource) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
67
|
+
if (isResponse(resource)) {
|
|
68
|
+
const response = resource;
|
|
69
|
+
return response.headers['content-length'] || -1;
|
|
70
|
+
}
|
|
71
|
+
if (isBlob(resource)) {
|
|
72
|
+
const blob = resource;
|
|
73
|
+
return blob.size;
|
|
74
|
+
}
|
|
75
|
+
if (typeof resource === 'string') {
|
|
76
|
+
// TODO - handle data URL?
|
|
77
|
+
return resource.length;
|
|
78
|
+
}
|
|
79
|
+
if (resource instanceof ArrayBuffer) {
|
|
80
|
+
return resource.byteLength;
|
|
81
|
+
}
|
|
82
|
+
if (ArrayBuffer.isView(resource)) {
|
|
83
|
+
return resource.byteLength;
|
|
84
|
+
}
|
|
85
|
+
return -1;
|
|
53
86
|
}
|
|
54
|
-
//# sourceMappingURL=resource-utils.js.map
|
|
@@ -1,89 +1,112 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
import { isResponse } from "../../javascript-utils/is-type.js";
|
|
2
5
|
import { getResourceContentLength, getResourceUrl, getResourceMIMEType } from "./resource-utils.js";
|
|
6
|
+
/**
|
|
7
|
+
* Returns a Response object
|
|
8
|
+
* Adds content-length header when possible
|
|
9
|
+
*
|
|
10
|
+
* @param resource
|
|
11
|
+
*/
|
|
3
12
|
export async function makeResponse(resource) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
13
|
+
if (isResponse(resource)) {
|
|
14
|
+
return resource;
|
|
15
|
+
}
|
|
16
|
+
// Add content-length header if possible
|
|
17
|
+
const headers = {};
|
|
18
|
+
const contentLength = getResourceContentLength(resource);
|
|
19
|
+
if (contentLength >= 0) {
|
|
20
|
+
headers['content-length'] = String(contentLength);
|
|
21
|
+
}
|
|
22
|
+
// `new Response(File)` does not preserve content-type and URL
|
|
23
|
+
// so we add them here
|
|
24
|
+
const url = getResourceUrl(resource);
|
|
25
|
+
const type = getResourceMIMEType(resource);
|
|
26
|
+
if (type) {
|
|
27
|
+
headers['content-type'] = type;
|
|
28
|
+
}
|
|
29
|
+
// Add a custom header with initial bytes if available
|
|
30
|
+
const initialDataUrl = await getInitialDataUrl(resource);
|
|
31
|
+
if (initialDataUrl) {
|
|
32
|
+
headers['x-first-bytes'] = initialDataUrl;
|
|
33
|
+
}
|
|
34
|
+
// TODO - is this the best way of handling strings?
|
|
35
|
+
// Maybe package as data URL instead?
|
|
36
|
+
if (typeof resource === 'string') {
|
|
37
|
+
// Convert to ArrayBuffer to avoid Response treating it as a URL
|
|
38
|
+
resource = new TextEncoder().encode(resource);
|
|
39
|
+
}
|
|
40
|
+
// Attempt to create a Response from the resource, adding headers and setting url
|
|
41
|
+
const response = new Response(resource, { headers });
|
|
42
|
+
// We can't control `Response.url` via constructor, use a property override to record URL.
|
|
43
|
+
Object.defineProperty(response, 'url', { value: url });
|
|
44
|
+
return response;
|
|
31
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Checks response status (async) and throws a helpful error message if status is not OK.
|
|
48
|
+
* @param response
|
|
49
|
+
*/
|
|
32
50
|
export async function checkResponse(response) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
51
|
+
if (!response.ok) {
|
|
52
|
+
const message = await getResponseError(response);
|
|
53
|
+
throw new Error(message);
|
|
54
|
+
}
|
|
37
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Checks response status (sync) and throws a helpful error message if status is not OK.
|
|
58
|
+
* @param response
|
|
59
|
+
*/
|
|
38
60
|
export function checkResponseSync(response) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
61
|
+
if (!response.ok) {
|
|
62
|
+
let message = `${response.status} ${response.statusText}`;
|
|
63
|
+
message = message.length > 60 ? `${message.slice(0, 60)}...` : message;
|
|
64
|
+
throw new Error(message);
|
|
65
|
+
}
|
|
44
66
|
}
|
|
67
|
+
// HELPERS
|
|
45
68
|
async function getResponseError(response) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
69
|
+
let message = `Failed to fetch resource ${response.url} (${response.status}): `;
|
|
70
|
+
try {
|
|
71
|
+
const contentType = response.headers.get('Content-Type');
|
|
72
|
+
let text = response.statusText;
|
|
73
|
+
if (contentType?.includes('application/json')) {
|
|
74
|
+
text += ` ${await response.text()}`;
|
|
75
|
+
}
|
|
76
|
+
message += text;
|
|
77
|
+
message = message.length > 60 ? `${message.slice(0, 60)}...` : message;
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
// eslint forbids return in a finally statement, so we just catch here
|
|
52
81
|
}
|
|
53
|
-
message
|
|
54
|
-
message = message.length > 60 ? `${message.slice(0, 60)}...` : message;
|
|
55
|
-
} catch (error) {}
|
|
56
|
-
return message;
|
|
82
|
+
return message;
|
|
57
83
|
}
|
|
58
84
|
async function getInitialDataUrl(resource) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return `data:base64,${base64}`;
|
|
78
|
-
}
|
|
79
|
-
return null;
|
|
85
|
+
const INITIAL_DATA_LENGTH = 5;
|
|
86
|
+
if (typeof resource === 'string') {
|
|
87
|
+
return `data:,${resource.slice(0, INITIAL_DATA_LENGTH)}`;
|
|
88
|
+
}
|
|
89
|
+
if (resource instanceof Blob) {
|
|
90
|
+
const blobSlice = resource.slice(0, 5);
|
|
91
|
+
return await new Promise((resolve) => {
|
|
92
|
+
const reader = new FileReader();
|
|
93
|
+
reader.onload = (event) => resolve(event?.target?.result);
|
|
94
|
+
reader.readAsDataURL(blobSlice);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
if (resource instanceof ArrayBuffer) {
|
|
98
|
+
const slice = resource.slice(0, INITIAL_DATA_LENGTH);
|
|
99
|
+
const base64 = arrayBufferToBase64(slice);
|
|
100
|
+
return `data:base64,${base64}`;
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
80
103
|
}
|
|
104
|
+
// https://stackoverflow.com/questions/9267899/arraybuffer-to-base64-encoded-string
|
|
81
105
|
function arrayBufferToBase64(buffer) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
106
|
+
let binary = '';
|
|
107
|
+
const bytes = new Uint8Array(buffer);
|
|
108
|
+
for (let i = 0; i < bytes.byteLength; i++) {
|
|
109
|
+
binary += String.fromCharCode(bytes[i]);
|
|
110
|
+
}
|
|
111
|
+
return btoa(binary);
|
|
88
112
|
}
|
|
89
|
-
//# sourceMappingURL=response-utils.js.map
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
const QUERY_STRING_PATTERN = /\?.*/;
|
|
2
5
|
export function extractQueryString(url) {
|
|
3
|
-
|
|
4
|
-
|
|
6
|
+
const matches = url.match(QUERY_STRING_PATTERN);
|
|
7
|
+
return matches && matches[0];
|
|
5
8
|
}
|
|
6
9
|
export function stripQueryString(url) {
|
|
7
|
-
|
|
10
|
+
return url.replace(QUERY_STRING_PATTERN, '');
|
|
8
11
|
}
|
|
9
|
-
//# sourceMappingURL=url-utils.js.map
|
package/dist/null-loader.js
CHANGED
|
@@ -1,37 +1,51 @@
|
|
|
1
|
-
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
// __VERSION__ is injected by babel-plugin-version-inline
|
|
5
|
+
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
6
|
+
const VERSION = typeof "4.2.0-alpha.4" !== 'undefined' ? "4.2.0-alpha.4" : 'latest';
|
|
7
|
+
/**
|
|
8
|
+
* Loads any data and returns null (or optionally passes through data unparsed)
|
|
9
|
+
*/
|
|
2
10
|
export const NullWorkerLoader = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
name: 'Null loader',
|
|
12
|
+
id: 'null',
|
|
13
|
+
module: 'core',
|
|
14
|
+
version: VERSION,
|
|
15
|
+
worker: true,
|
|
16
|
+
mimeTypes: ['application/x.empty'],
|
|
17
|
+
extensions: ['null'],
|
|
18
|
+
tests: [() => false],
|
|
19
|
+
options: {
|
|
20
|
+
null: {}
|
|
21
|
+
}
|
|
14
22
|
};
|
|
23
|
+
/**
|
|
24
|
+
* Loads any data and returns null (or optionally passes through data unparsed)
|
|
25
|
+
*/
|
|
15
26
|
export const NullLoader = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
name: 'Null loader',
|
|
28
|
+
id: 'null',
|
|
29
|
+
module: 'core',
|
|
30
|
+
version: VERSION,
|
|
31
|
+
mimeTypes: ['application/x.empty'],
|
|
32
|
+
extensions: ['null'],
|
|
33
|
+
parse: async (arrayBuffer, options, context) => parseSync(arrayBuffer, options || {}, context),
|
|
34
|
+
parseSync,
|
|
35
|
+
parseInBatches: async function* generator(asyncIterator, options, context) {
|
|
36
|
+
for await (const batch of asyncIterator) {
|
|
37
|
+
yield parseSync(batch, options, context);
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
tests: [() => false],
|
|
41
|
+
options: {
|
|
42
|
+
null: {}
|
|
27
43
|
}
|
|
28
|
-
},
|
|
29
|
-
tests: [() => false],
|
|
30
|
-
options: {
|
|
31
|
-
null: {}
|
|
32
|
-
}
|
|
33
44
|
};
|
|
45
|
+
/**
|
|
46
|
+
* Returns arguments passed to the parse API in a format that can be transferred to a
|
|
47
|
+
* web worker. The `context` parameter is stripped using JSON.stringify & parse.
|
|
48
|
+
*/
|
|
34
49
|
function parseSync(arrayBuffer, options, context) {
|
|
35
|
-
|
|
50
|
+
return null;
|
|
36
51
|
}
|
|
37
|
-
//# sourceMappingURL=null-loader.js.map
|
package/dist/null-worker-node.js
CHANGED
package/dist/null-worker.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
import { createLoaderWorker } from '@loaders.gl/loader-utils';
|
|
2
5
|
import { NullLoader } from "../null-loader.js";
|
|
3
6
|
createLoaderWorker(NullLoader);
|
|
4
|
-
//# sourceMappingURL=null-worker-node.js.map
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
import { createLoaderWorker } from '@loaders.gl/loader-utils';
|
|
2
5
|
import { NullLoader } from "../null-loader.js";
|
|
3
6
|
createLoaderWorker(NullLoader);
|
|
4
|
-
//# sourceMappingURL=null-worker.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/core",
|
|
3
|
-
"version": "4.2.0-alpha.
|
|
3
|
+
"version": "4.2.0-alpha.5",
|
|
4
4
|
"description": "The core API for working with loaders.gl loaders and writers",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -48,16 +48,16 @@
|
|
|
48
48
|
"README.md"
|
|
49
49
|
],
|
|
50
50
|
"scripts": {
|
|
51
|
-
"pre-build": "npm run build-bundle && npm run build-bundle
|
|
52
|
-
"build-bundle": "ocular-bundle ./
|
|
51
|
+
"pre-build": "npm run build-bundle && npm run build-bundle-dev && npm run build-worker && npm run build-worker-node",
|
|
52
|
+
"build-bundle": "ocular-bundle ./bundle.ts --output=dist/dist.min.js",
|
|
53
|
+
"build-bundle-dev": "ocular-bundle ./bundle.ts --env=dev --output=dist/dist.dev.js",
|
|
53
54
|
"build-worker": "esbuild src/workers/null-worker.ts --outfile=dist/null-worker.js --bundle --target=esnext --define:__VERSION__=\\\"$npm_package_version\\\"",
|
|
54
55
|
"build-worker-node": "esbuild src/workers/null-worker.ts --outfile=dist/null-worker-node.js --bundle --platform=node --target=node16 --define:__VERSION__=\\\"$npm_package_version\\\""
|
|
55
56
|
},
|
|
56
57
|
"dependencies": {
|
|
57
|
-
"@
|
|
58
|
-
"@loaders.gl/
|
|
59
|
-
"@loaders.gl/worker-utils": "4.2.0-alpha.3",
|
|
58
|
+
"@loaders.gl/loader-utils": "4.2.0-alpha.5",
|
|
59
|
+
"@loaders.gl/worker-utils": "4.2.0-alpha.5",
|
|
60
60
|
"@probe.gl/log": "^4.0.2"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "32d95a81971f104e4dfeb88ab57065f05321a76a"
|
|
63
63
|
}
|