@loaders.gl/loader-utils 4.2.0-alpha.4 → 4.2.0-alpha.6
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/index.cjs +103 -95
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +46 -46
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -1
- package/dist/json-loader.d.ts +1 -1
- package/dist/json-loader.d.ts.map +1 -1
- package/dist/json-loader.js +20 -14
- package/dist/lib/binary-utils/array-buffer-utils.js +75 -46
- package/dist/lib/binary-utils/dataview-copy-utils.d.ts +1 -1
- package/dist/lib/binary-utils/dataview-copy-utils.d.ts.map +1 -1
- package/dist/lib/binary-utils/dataview-copy-utils.js +75 -34
- package/dist/lib/binary-utils/get-first-characters.js +39 -21
- package/dist/lib/binary-utils/memory-conversion-utils.js +38 -23
- package/dist/lib/binary-utils/memory-copy-utils.js +49 -20
- package/dist/lib/env-utils/assert.js +7 -4
- package/dist/lib/env-utils/globals.js +15 -7
- package/dist/lib/file-provider/data-view-file.d.ts +1 -1
- package/dist/lib/file-provider/data-view-file.d.ts.map +1 -1
- package/dist/lib/file-provider/data-view-file.js +60 -29
- package/dist/lib/file-provider/file-handle-file.d.ts +1 -1
- package/dist/lib/file-provider/file-handle-file.d.ts.map +1 -1
- package/dist/lib/file-provider/file-handle-file.js +98 -58
- package/dist/lib/file-provider/file-provider.js +8 -3
- package/dist/lib/files/blob-file.d.ts +1 -1
- package/dist/lib/files/blob-file.d.ts.map +1 -1
- package/dist/lib/files/blob-file.js +28 -23
- package/dist/lib/files/file.js +3 -1
- package/dist/lib/files/http-file.d.ts +1 -1
- package/dist/lib/files/http-file.d.ts.map +1 -1
- package/dist/lib/files/http-file.js +93 -71
- package/dist/lib/files/node-file-facade.d.ts +1 -1
- package/dist/lib/files/node-file-facade.d.ts.map +1 -1
- package/dist/lib/files/node-file-facade.js +38 -29
- package/dist/lib/files/sources.js +150 -1
- package/dist/lib/filesystems/filesystem.d.ts +1 -1
- package/dist/lib/filesystems/filesystem.d.ts.map +1 -1
- package/dist/lib/filesystems/filesystem.js +3 -1
- package/dist/lib/filesystems/node-filesystem-facade.d.ts +3 -3
- package/dist/lib/filesystems/node-filesystem-facade.d.ts.map +1 -1
- package/dist/lib/filesystems/node-filesystem-facade.js +41 -31
- package/dist/lib/iterators/async-iteration.js +39 -24
- package/dist/lib/iterators/text-iterators.js +46 -39
- package/dist/lib/node/buffer.browser.js +15 -3
- package/dist/lib/node/buffer.js +30 -16
- package/dist/lib/node/fs.browser.js +0 -1
- package/dist/lib/node/promisify.js +10 -4
- package/dist/lib/node/stream.browser.js +0 -1
- package/dist/lib/node/stream.js +4 -1
- package/dist/lib/option-utils/merge-loader-options.d.ts +1 -1
- package/dist/lib/option-utils/merge-loader-options.d.ts.map +1 -1
- package/dist/lib/option-utils/merge-loader-options.js +25 -17
- package/dist/lib/parser-utils/parse-json.js +9 -6
- package/dist/lib/path-utils/file-aliases.js +29 -13
- package/dist/lib/path-utils/get-cwd.js +6 -7
- package/dist/lib/path-utils/path.js +149 -105
- package/dist/lib/request-utils/request-scheduler.d.ts +2 -1
- package/dist/lib/request-utils/request-scheduler.d.ts.map +1 -1
- package/dist/lib/request-utils/request-scheduler.js +132 -102
- package/dist/lib/sources/data-source.js +53 -38
- package/dist/lib/sources/image-source.d.ts +3 -3
- package/dist/lib/sources/image-source.d.ts.map +1 -1
- package/dist/lib/sources/image-source.js +12 -4
- package/dist/lib/sources/image-tile-source.d.ts +3 -3
- package/dist/lib/sources/image-tile-source.d.ts.map +1 -1
- package/dist/lib/sources/image-tile-source.js +3 -1
- package/dist/lib/sources/tile-source-adapter.d.ts +3 -3
- package/dist/lib/sources/tile-source-adapter.d.ts.map +1 -1
- package/dist/lib/sources/tile-source-adapter.js +44 -36
- package/dist/lib/sources/tile-source.js +3 -1
- package/dist/lib/sources/utils/image-type.js +0 -1
- package/dist/lib/sources/utils/utils.js +31 -17
- package/dist/lib/sources/vector-tile-source.d.ts +2 -2
- package/dist/lib/sources/vector-tile-source.d.ts.map +1 -1
- package/dist/lib/sources/vector-tile-source.js +3 -1
- package/dist/lib/worker-loader-utils/create-loader-worker.d.ts +1 -1
- package/dist/lib/worker-loader-utils/create-loader-worker.d.ts.map +1 -1
- package/dist/lib/worker-loader-utils/create-loader-worker.js +87 -87
- package/dist/lib/worker-loader-utils/encode-with-worker.d.ts +1 -1
- package/dist/lib/worker-loader-utils/encode-with-worker.d.ts.map +1 -1
- package/dist/lib/worker-loader-utils/encode-with-worker.js +13 -8
- package/dist/lib/worker-loader-utils/parse-with-worker.d.ts +1 -1
- package/dist/lib/worker-loader-utils/parse-with-worker.d.ts.map +1 -1
- package/dist/lib/worker-loader-utils/parse-with-worker.js +68 -55
- package/dist/loader-types.d.ts +2 -2
- package/dist/loader-types.d.ts.map +1 -1
- package/dist/loader-types.js +26 -10
- package/dist/service-types.d.ts +1 -1
- package/dist/service-types.d.ts.map +1 -1
- package/dist/service-types.js +3 -1
- package/dist/types.js +1 -1
- package/dist/workers/json-worker.js +0 -1
- package/dist/writer-types.js +3 -1
- package/package.json +10 -8
- package/src/lib/request-utils/request-scheduler.ts +17 -8
- package/src/lib/sources/tile-source-adapter.ts +1 -1
- package/dist/index.js.map +0 -1
- package/dist/json-loader.js.map +0 -1
- package/dist/lib/binary-utils/array-buffer-utils.js.map +0 -1
- package/dist/lib/binary-utils/dataview-copy-utils.js.map +0 -1
- package/dist/lib/binary-utils/get-first-characters.js.map +0 -1
- package/dist/lib/binary-utils/memory-conversion-utils.js.map +0 -1
- package/dist/lib/binary-utils/memory-copy-utils.js.map +0 -1
- package/dist/lib/env-utils/assert.js.map +0 -1
- package/dist/lib/env-utils/globals.js.map +0 -1
- package/dist/lib/file-provider/data-view-file.js.map +0 -1
- package/dist/lib/file-provider/file-handle-file.js.map +0 -1
- package/dist/lib/file-provider/file-provider.js.map +0 -1
- package/dist/lib/files/blob-file.js.map +0 -1
- package/dist/lib/files/file.js.map +0 -1
- package/dist/lib/files/http-file.js.map +0 -1
- package/dist/lib/files/node-file-facade.js.map +0 -1
- package/dist/lib/files/sources.js.map +0 -1
- package/dist/lib/filesystems/filesystem.js.map +0 -1
- package/dist/lib/filesystems/node-filesystem-facade.js.map +0 -1
- package/dist/lib/iterators/async-iteration.js.map +0 -1
- package/dist/lib/iterators/text-iterators.js.map +0 -1
- package/dist/lib/node/buffer.browser.js.map +0 -1
- package/dist/lib/node/buffer.js.map +0 -1
- package/dist/lib/node/fs.browser.js.map +0 -1
- package/dist/lib/node/promisify.js.map +0 -1
- package/dist/lib/node/stream.browser.js.map +0 -1
- package/dist/lib/node/stream.js.map +0 -1
- package/dist/lib/option-utils/merge-loader-options.js.map +0 -1
- package/dist/lib/parser-utils/parse-json.js.map +0 -1
- package/dist/lib/path-utils/file-aliases.js.map +0 -1
- package/dist/lib/path-utils/get-cwd.js.map +0 -1
- package/dist/lib/path-utils/path.js.map +0 -1
- package/dist/lib/request-utils/request-scheduler.js.map +0 -1
- package/dist/lib/sources/data-source.js.map +0 -1
- package/dist/lib/sources/image-source.js.map +0 -1
- package/dist/lib/sources/image-tile-source.js.map +0 -1
- package/dist/lib/sources/tile-source-adapter.js.map +0 -1
- package/dist/lib/sources/tile-source.js.map +0 -1
- package/dist/lib/sources/utils/image-type.js.map +0 -1
- package/dist/lib/sources/utils/utils.js.map +0 -1
- package/dist/lib/sources/vector-tile-source.js.map +0 -1
- package/dist/lib/worker-loader-utils/create-loader-worker.js.map +0 -1
- package/dist/lib/worker-loader-utils/encode-with-worker.js.map +0 -1
- package/dist/lib/worker-loader-utils/parse-with-worker.js.map +0 -1
- package/dist/loader-types.js.map +0 -1
- package/dist/service-types.js.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/workers/json-worker.js.map +0 -1
- package/dist/writer-types.js.map +0 -1
|
@@ -1,48 +1,89 @@
|
|
|
1
|
+
// loaders./gl, MIT license
|
|
1
2
|
import { padToNBytes } from "./memory-copy-utils.js";
|
|
3
|
+
/**
|
|
4
|
+
* Helper function that pads a string with spaces to fit a certain byte alignment
|
|
5
|
+
* @param string
|
|
6
|
+
* @param byteAlignment
|
|
7
|
+
* @returns
|
|
8
|
+
*
|
|
9
|
+
* @todo PERFORMANCE IDEA: No need to copy string twice...
|
|
10
|
+
*/
|
|
2
11
|
export function padStringToByteAlignment(string, byteAlignment) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
const length = string.length;
|
|
13
|
+
const paddedLength = Math.ceil(length / byteAlignment) * byteAlignment; // Round up to the required alignment
|
|
14
|
+
const padding = paddedLength - length;
|
|
15
|
+
let whitespace = '';
|
|
16
|
+
for (let i = 0; i < padding; ++i) {
|
|
17
|
+
whitespace += ' ';
|
|
18
|
+
}
|
|
19
|
+
return string + whitespace;
|
|
11
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @param dataView
|
|
24
|
+
* @param byteOffset
|
|
25
|
+
* @param string
|
|
26
|
+
* @param byteLength
|
|
27
|
+
* @returns
|
|
28
|
+
*/
|
|
12
29
|
export function copyStringToDataView(dataView, byteOffset, string, byteLength) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
30
|
+
if (dataView) {
|
|
31
|
+
for (let i = 0; i < byteLength; i++) {
|
|
32
|
+
dataView.setUint8(byteOffset + i, string.charCodeAt(i));
|
|
33
|
+
}
|
|
16
34
|
}
|
|
17
|
-
|
|
18
|
-
return byteOffset + byteLength;
|
|
35
|
+
return byteOffset + byteLength;
|
|
19
36
|
}
|
|
20
37
|
export function copyBinaryToDataView(dataView, byteOffset, binary, byteLength) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
38
|
+
if (dataView) {
|
|
39
|
+
for (let i = 0; i < byteLength; i++) {
|
|
40
|
+
dataView.setUint8(byteOffset + i, binary[i]);
|
|
41
|
+
}
|
|
24
42
|
}
|
|
25
|
-
|
|
26
|
-
return byteOffset + byteLength;
|
|
43
|
+
return byteOffset + byteLength;
|
|
27
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Copy sourceBuffer to dataView with some padding
|
|
47
|
+
*
|
|
48
|
+
* @param dataView - destination data container. If null - only new offset is calculated
|
|
49
|
+
* @param byteOffset - destination byte offset to copy to
|
|
50
|
+
* @param sourceBuffer - source data buffer
|
|
51
|
+
* @param padding - pad the resulting array to multiple of "padding" bytes. Additional bytes are filled with 0x20 (ASCII space)
|
|
52
|
+
*
|
|
53
|
+
* @return new byteOffset of resulting dataView
|
|
54
|
+
*/
|
|
28
55
|
export function copyPaddedArrayBufferToDataView(dataView, byteOffset, sourceBuffer, padding) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
56
|
+
const paddedLength = padToNBytes(sourceBuffer.byteLength, padding);
|
|
57
|
+
const padLength = paddedLength - sourceBuffer.byteLength;
|
|
58
|
+
if (dataView) {
|
|
59
|
+
// Copy array
|
|
60
|
+
const targetArray = new Uint8Array(dataView.buffer, dataView.byteOffset + byteOffset, sourceBuffer.byteLength);
|
|
61
|
+
const sourceArray = new Uint8Array(sourceBuffer);
|
|
62
|
+
targetArray.set(sourceArray);
|
|
63
|
+
// Add PADDING
|
|
64
|
+
for (let i = 0; i < padLength; ++i) {
|
|
65
|
+
// json chunk is padded with spaces (ASCII 0x20)
|
|
66
|
+
dataView.setUint8(byteOffset + sourceBuffer.byteLength + i, 0x20);
|
|
67
|
+
}
|
|
37
68
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return byteOffset;
|
|
69
|
+
byteOffset += paddedLength;
|
|
70
|
+
return byteOffset;
|
|
41
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Copy string to dataView with some padding
|
|
74
|
+
*
|
|
75
|
+
* @param {DataView | null} dataView - destination data container. If null - only new offset is calculated
|
|
76
|
+
* @param {number} byteOffset - destination byte offset to copy to
|
|
77
|
+
* @param {string} string - source string
|
|
78
|
+
* @param {number} padding - pad the resulting array to multiple of "padding" bytes. Additional bytes are filled with 0x20 (ASCII space)
|
|
79
|
+
*
|
|
80
|
+
* @return new byteOffset of resulting dataView
|
|
81
|
+
*/
|
|
42
82
|
export function copyPaddedStringToDataView(dataView, byteOffset, string, padding) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
83
|
+
const textEncoder = new TextEncoder();
|
|
84
|
+
// PERFORMANCE IDEA: We encode twice, once to get size and once to store
|
|
85
|
+
// PERFORMANCE IDEA: Use TextEncoder.encodeInto() to avoid temporary copy
|
|
86
|
+
const stringBuffer = textEncoder.encode(string);
|
|
87
|
+
byteOffset = copyPaddedArrayBufferToDataView(dataView, byteOffset, stringBuffer, padding);
|
|
88
|
+
return byteOffset;
|
|
47
89
|
}
|
|
48
|
-
//# sourceMappingURL=dataview-copy-utils.js.map
|
|
@@ -1,24 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
/**
|
|
5
|
+
* Get the first characters from a binary file (interpret the first bytes as an ASCII string)
|
|
6
|
+
* @param data
|
|
7
|
+
* @param length
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export function getFirstCharacters(data, length = 5) {
|
|
11
|
+
if (typeof data === 'string') {
|
|
12
|
+
return data.slice(0, length);
|
|
13
|
+
}
|
|
14
|
+
else if (ArrayBuffer.isView(data)) {
|
|
15
|
+
// Typed Arrays can have offsets into underlying buffer
|
|
16
|
+
return getMagicString(data.buffer, data.byteOffset, length);
|
|
17
|
+
}
|
|
18
|
+
else if (data instanceof ArrayBuffer) {
|
|
19
|
+
const byteOffset = 0;
|
|
20
|
+
return getMagicString(data, byteOffset, length);
|
|
21
|
+
}
|
|
22
|
+
return '';
|
|
12
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Gets a magic string from a "file"
|
|
26
|
+
* Typically used to check or detect file format
|
|
27
|
+
* @param arrayBuffer
|
|
28
|
+
* @param byteOffset
|
|
29
|
+
* @param length
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
13
32
|
export function getMagicString(arrayBuffer, byteOffset, length) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
33
|
+
if (arrayBuffer.byteLength <= byteOffset + length) {
|
|
34
|
+
return '';
|
|
35
|
+
}
|
|
36
|
+
const dataView = new DataView(arrayBuffer);
|
|
37
|
+
let magic = '';
|
|
38
|
+
for (let i = 0; i < length; i++) {
|
|
39
|
+
magic += String.fromCharCode(dataView.getUint8(byteOffset + i));
|
|
40
|
+
}
|
|
41
|
+
return magic;
|
|
23
42
|
}
|
|
24
|
-
//# sourceMappingURL=get-first-characters.js.map
|
|
@@ -1,31 +1,46 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
import * as node from "../node/buffer.js";
|
|
5
|
+
/**
|
|
6
|
+
* Check for Node.js `Buffer` (without triggering bundler to include Buffer polyfill on browser)
|
|
7
|
+
*/
|
|
2
8
|
export function isBuffer(value) {
|
|
3
|
-
|
|
9
|
+
return value && typeof value === 'object' && value.isBuffer;
|
|
4
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Converts to Node.js `Buffer` (without triggering bundler to include Buffer polyfill on browser)
|
|
13
|
+
* @todo better data type
|
|
14
|
+
*/
|
|
5
15
|
export function toBuffer(data) {
|
|
6
|
-
|
|
16
|
+
return node.toBuffer ? node.toBuffer(data) : data;
|
|
7
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Convert an object to an array buffer
|
|
20
|
+
*/
|
|
8
21
|
export function toArrayBuffer(data) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (data instanceof ArrayBuffer) {
|
|
13
|
-
return data;
|
|
14
|
-
}
|
|
15
|
-
if (ArrayBuffer.isView(data)) {
|
|
16
|
-
if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) {
|
|
17
|
-
return data.buffer;
|
|
22
|
+
// Note: Should be called first, Buffers can trigger other detections below
|
|
23
|
+
if (isBuffer(data)) {
|
|
24
|
+
return node.toArrayBuffer(data);
|
|
18
25
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
if (data instanceof ArrayBuffer) {
|
|
27
|
+
return data;
|
|
28
|
+
}
|
|
29
|
+
// Careful - Node Buffers look like Uint8Arrays (keep after isBuffer)
|
|
30
|
+
if (ArrayBuffer.isView(data)) {
|
|
31
|
+
if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) {
|
|
32
|
+
return data.buffer;
|
|
33
|
+
}
|
|
34
|
+
return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
|
|
35
|
+
}
|
|
36
|
+
if (typeof data === 'string') {
|
|
37
|
+
const text = data;
|
|
38
|
+
const uint8Array = new TextEncoder().encode(text);
|
|
39
|
+
return uint8Array.buffer;
|
|
40
|
+
}
|
|
41
|
+
// HACK to support Blob polyfill
|
|
42
|
+
if (data && typeof data === 'object' && data._toArrayBuffer) {
|
|
43
|
+
return data._toArrayBuffer();
|
|
44
|
+
}
|
|
45
|
+
throw new Error('toArrayBuffer');
|
|
30
46
|
}
|
|
31
|
-
//# sourceMappingURL=memory-conversion-utils.js.map
|
|
@@ -1,26 +1,55 @@
|
|
|
1
1
|
import { assert } from "../env-utils/assert.js";
|
|
2
|
+
/**
|
|
3
|
+
* Calculate new size of an arrayBuffer to be aligned to an n-byte boundary
|
|
4
|
+
* This function increases `byteLength` by the minimum delta,
|
|
5
|
+
* allowing the total length to be divided by `padding`
|
|
6
|
+
* @param byteLength
|
|
7
|
+
* @param padding
|
|
8
|
+
*/
|
|
2
9
|
export function padToNBytes(byteLength, padding) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
10
|
+
assert(byteLength >= 0); // `Incorrect 'byteLength' value: ${byteLength}`
|
|
11
|
+
assert(padding > 0); // `Incorrect 'padding' value: ${padding}`
|
|
12
|
+
return (byteLength + (padding - 1)) & ~(padding - 1);
|
|
6
13
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Creates a new Uint8Array based on two different ArrayBuffers
|
|
16
|
+
* @param targetBuffer The first buffer.
|
|
17
|
+
* @param sourceBuffer The second buffer.
|
|
18
|
+
* @return The new ArrayBuffer created out of the two.
|
|
19
|
+
*/
|
|
20
|
+
export function copyArrayBuffer(targetBuffer, sourceBuffer, byteOffset, byteLength = sourceBuffer.byteLength) {
|
|
21
|
+
const targetArray = new Uint8Array(targetBuffer, byteOffset, byteLength);
|
|
22
|
+
const sourceArray = new Uint8Array(sourceBuffer);
|
|
23
|
+
targetArray.set(sourceArray);
|
|
24
|
+
return targetBuffer;
|
|
13
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Copy from source to target at the targetOffset
|
|
28
|
+
*
|
|
29
|
+
* @param source - The data to copy
|
|
30
|
+
* @param target - The destination to copy data into
|
|
31
|
+
* @param targetOffset - The start offset into target to place the copied data
|
|
32
|
+
* @returns the new offset taking into account proper padding
|
|
33
|
+
*/
|
|
14
34
|
export function copyToArray(source, target, targetOffset) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
35
|
+
let sourceArray;
|
|
36
|
+
if (source instanceof ArrayBuffer) {
|
|
37
|
+
sourceArray = new Uint8Array(source);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
// Pack buffer onto the big target array
|
|
41
|
+
//
|
|
42
|
+
// 'source.data.buffer' could be a view onto a larger buffer.
|
|
43
|
+
// We MUST use this constructor to ensure the byteOffset and byteLength is
|
|
44
|
+
// set to correct values from 'source.data' and not the underlying
|
|
45
|
+
// buffer for target.set() to work properly.
|
|
46
|
+
const srcByteOffset = source.byteOffset;
|
|
47
|
+
const srcByteLength = source.byteLength;
|
|
48
|
+
// In gltf parser it is set as "arrayBuffer" instead of "buffer"
|
|
49
|
+
// https://github.com/visgl/loaders.gl/blob/1e3a82a0a65d7b6a67b1e60633453e5edda2960a/modules/gltf/src/lib/parse-gltf.js#L85
|
|
50
|
+
sourceArray = new Uint8Array(source.buffer || source.arrayBuffer, srcByteOffset, srcByteLength);
|
|
51
|
+
}
|
|
52
|
+
// Pack buffer onto the big target array
|
|
53
|
+
target.set(sourceArray, targetOffset);
|
|
54
|
+
return targetOffset + padToNBytes(sourceArray.byteLength, 4);
|
|
25
55
|
}
|
|
26
|
-
//# sourceMappingURL=memory-copy-utils.js.map
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Throws an `Error` with the optional `message` if `condition` is falsy
|
|
3
|
+
* @note Replacement for the external assert method to reduce bundle size
|
|
4
|
+
*/
|
|
1
5
|
export function assert(condition, message) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
6
|
+
if (!condition) {
|
|
7
|
+
throw new Error(message || 'loader assertion failed.');
|
|
8
|
+
}
|
|
5
9
|
}
|
|
6
|
-
//# sourceMappingURL=assert.js.map
|
|
@@ -1,16 +1,24 @@
|
|
|
1
|
+
// Purpose: include this in your module to avoid
|
|
2
|
+
// dependencies on micro modules like 'global' and 'is-browser';
|
|
3
|
+
/* eslint-disable no-restricted-globals */
|
|
1
4
|
const globals = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
self: typeof self !== 'undefined' && self,
|
|
6
|
+
window: typeof window !== 'undefined' && window,
|
|
7
|
+
global: typeof global !== 'undefined' && global,
|
|
8
|
+
document: typeof document !== 'undefined' && document
|
|
6
9
|
};
|
|
7
10
|
const self_ = globals.self || globals.window || globals.global || {};
|
|
8
11
|
const window_ = globals.window || globals.self || globals.global || {};
|
|
9
12
|
const global_ = globals.global || globals.self || globals.window || {};
|
|
10
13
|
const document_ = globals.document || {};
|
|
11
14
|
export { self_ as self, window_ as window, global_ as global, document_ as document };
|
|
12
|
-
|
|
15
|
+
/** true if running in a browser */
|
|
16
|
+
export const isBrowser =
|
|
17
|
+
// @ts-ignore process does not exist on browser
|
|
18
|
+
Boolean(typeof process !== 'object' || String(process) !== '[object process]' || process.browser);
|
|
19
|
+
/** true if running in a worker thread */
|
|
13
20
|
export const isWorker = typeof importScripts === 'function';
|
|
21
|
+
// Extract node major version
|
|
14
22
|
const matches = typeof process !== 'undefined' && process.version && /v([0-9]*)/.exec(process.version);
|
|
15
|
-
|
|
16
|
-
|
|
23
|
+
/** Major Node version (as a number) */
|
|
24
|
+
export const nodeVersion = (matches && parseFloat(matches[1])) || 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-view-file.d.ts","sourceRoot":"","sources":["../../../src/lib/file-provider/data-view-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,
|
|
1
|
+
{"version":3,"file":"data-view-file.d.ts","sourceRoot":"","sources":["../../../src/lib/file-provider/data-view-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,2BAAwB;AAc7C;;;GAGG;AACH,qBAAa,YAAa,YAAW,YAAY;IAC/C,+CAA+C;IAC/C,OAAO,CAAC,IAAI,CAAW;gBAEX,IAAI,EAAE,QAAQ;IAIpB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAE9B;;;OAGG;IACG,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAI/C;;;OAGG;IACG,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIhD;;;OAGG;IACG,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIhD;;;OAGG;IACG,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAInD;;;;OAIG;IACG,KAAK,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAIzE,yCAAyC;IACzC,IAAI,MAAM,WAET;CACF"}
|
|
@@ -1,32 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Checks if bigint can be converted to number and convert it if possible
|
|
3
|
+
* @param bigint bigint to be converted
|
|
4
|
+
* @returns number
|
|
5
|
+
*/
|
|
6
|
+
const toNumber = (bigint) => {
|
|
7
|
+
if (bigint > Number.MAX_SAFE_INTEGER) {
|
|
8
|
+
throw new Error('Offset is out of bounds');
|
|
9
|
+
}
|
|
10
|
+
return Number(bigint);
|
|
6
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* Provides file data using DataView
|
|
14
|
+
* @deprecated - will be replaced with ReadableFile
|
|
15
|
+
*/
|
|
7
16
|
export class DataViewFile {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
17
|
+
/** The DataView from which data is provided */
|
|
18
|
+
file;
|
|
19
|
+
constructor(file) {
|
|
20
|
+
this.file = file;
|
|
21
|
+
}
|
|
22
|
+
async destroy() { }
|
|
23
|
+
/**
|
|
24
|
+
* Gets an unsigned 8-bit integer at the specified byte offset from the start of the file.
|
|
25
|
+
* @param offset The offset, in bytes, from the start of the file where to read the data.
|
|
26
|
+
*/
|
|
27
|
+
async getUint8(offset) {
|
|
28
|
+
return this.file.getUint8(toNumber(offset));
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Gets an unsigned 16-bit intege at the specified byte offset from the start of the file.
|
|
32
|
+
* @param offset The offset, in bytes, from the start of the file where to read the data.
|
|
33
|
+
*/
|
|
34
|
+
async getUint16(offset) {
|
|
35
|
+
return this.file.getUint16(toNumber(offset), true);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.
|
|
39
|
+
* @param offset The offset, in bytes, from the start of the file where to read the data.
|
|
40
|
+
*/
|
|
41
|
+
async getUint32(offset) {
|
|
42
|
+
return this.file.getUint32(toNumber(offset), true);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Gets an unsigned 64-bit integer at the specified byte offset from the start of the file.
|
|
46
|
+
* @param offset The offset, in bytes, from the start of the file where to read the data.
|
|
47
|
+
*/
|
|
48
|
+
async getBigUint64(offset) {
|
|
49
|
+
return this.file.getBigUint64(toNumber(offset), true);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* returns an ArrayBuffer whose contents are a copy of this file bytes from startOffset, inclusive, up to endOffset, exclusive.
|
|
53
|
+
* @param startOffset The offset, in bytes, from the start of the file where to start reading the data.
|
|
54
|
+
* @param endOffset The offset, in bytes, from the start of the file where to end reading the data.
|
|
55
|
+
*/
|
|
56
|
+
async slice(startOffset, endOffset) {
|
|
57
|
+
return this.file.buffer.slice(toNumber(startOffset), toNumber(endOffset));
|
|
58
|
+
}
|
|
59
|
+
/** the length (in bytes) of the data. */
|
|
60
|
+
get length() {
|
|
61
|
+
return BigInt(this.file.byteLength);
|
|
62
|
+
}
|
|
31
63
|
}
|
|
32
|
-
//# sourceMappingURL=data-view-file.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-handle-file.d.ts","sourceRoot":"","sources":["../../../src/lib/file-provider/file-handle-file.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,YAAY,EAAC,
|
|
1
|
+
{"version":3,"file":"file-handle-file.d.ts","sourceRoot":"","sources":["../../../src/lib/file-provider/file-handle-file.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,YAAY,EAAC,2BAAwB;AAG7C;;;GAGG;AACH,qBAAa,cAAe,YAAW,YAAY;IACjD,iDAAiD;IACjD,OAAO,CAAC,IAAI,CAAW;IAEvB,kCAAkC;gBACtB,IAAI,EAAE,MAAM,EAAE,MAAM,GAAE,OAAe;IAIjD;;;OAGG;IACG,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI7C;;;OAGG;IACG,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/C,iBAAiB;IACX,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAI9B;;;OAGG;IACG,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IASxD;;;OAGG;IACG,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IASzD;;;OAGG;IACG,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IASzD;;;OAGG;IACG,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAS5D;;;;OAIG;IACG,KAAK,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IASzE;;OAEG;IACH,IAAI,MAAM,IAAI,MAAM,CAEnB;CACF"}
|