@loaders.gl/loader-utils 3.1.0-alpha.2 → 3.1.0-beta.1
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/es5/index.js +323 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/json-loader.js +29 -0
- package/dist/es5/json-loader.js.map +1 -0
- package/dist/es5/lib/binary-utils/array-buffer-utils.js +102 -0
- package/dist/es5/lib/binary-utils/array-buffer-utils.js.map +1 -0
- package/dist/es5/lib/binary-utils/binary-copy-utils.js +35 -0
- package/dist/es5/lib/binary-utils/binary-copy-utils.js.map +1 -0
- package/dist/es5/lib/binary-utils/buffer-utils.js +32 -0
- package/dist/es5/lib/binary-utils/buffer-utils.js.map +1 -0
- package/dist/es5/lib/binary-utils/encode-utils.js +42 -0
- package/dist/es5/lib/binary-utils/encode-utils.js.map +1 -0
- package/dist/es5/lib/binary-utils/get-first-characters.js +36 -0
- package/dist/es5/lib/binary-utils/get-first-characters.js.map +1 -0
- package/dist/es5/lib/binary-utils/memory-copy-utils.js +39 -0
- package/dist/es5/lib/binary-utils/memory-copy-utils.js.map +1 -0
- package/dist/es5/lib/env-utils/assert.js +13 -0
- package/dist/es5/lib/env-utils/assert.js.map +1 -0
- package/dist/es5/lib/env-utils/globals.js +28 -0
- package/dist/es5/lib/env-utils/globals.js.map +1 -0
- package/dist/es5/lib/filesystems/node-filesystem.js +74 -0
- package/dist/es5/lib/filesystems/node-filesystem.js.map +1 -0
- package/dist/es5/lib/iterators/async-iteration.js +51 -0
- package/dist/es5/lib/iterators/async-iteration.js.map +1 -0
- package/dist/es5/lib/iterators/text-iterators.js +59 -0
- package/dist/es5/lib/iterators/text-iterators.js.map +1 -0
- package/dist/es5/lib/node/buffer.js +38 -0
- package/dist/es5/lib/node/buffer.js.map +1 -0
- package/dist/es5/lib/node/fs.js +52 -0
- package/dist/es5/lib/node/fs.js.map +1 -0
- package/dist/es5/lib/node/util.js +16 -0
- package/dist/es5/lib/node/util.js.map +1 -0
- package/dist/es5/lib/parser-utils/parse-json.js +17 -0
- package/dist/es5/lib/parser-utils/parse-json.js.map +1 -0
- package/dist/es5/lib/path-utils/file-aliases.js +39 -0
- package/dist/es5/lib/path-utils/file-aliases.js.map +1 -0
- package/dist/es5/lib/path-utils/path.js +35 -0
- package/dist/es5/lib/path-utils/path.js.map +1 -0
- package/dist/es5/lib/request-utils/request-scheduler.js +154 -0
- package/dist/es5/lib/request-utils/request-scheduler.js.map +1 -0
- package/dist/es5/lib/worker-loader-utils/create-loader-worker.js +117 -0
- package/dist/es5/lib/worker-loader-utils/create-loader-worker.js.map +1 -0
- package/dist/es5/lib/worker-loader-utils/parse-with-worker.js +76 -0
- package/dist/es5/lib/worker-loader-utils/parse-with-worker.js.map +1 -0
- package/dist/es5/types.js +2 -0
- package/dist/{types.js.map → es5/types.js.map} +0 -0
- package/dist/es5/workers/json-worker.js +8 -0
- package/dist/es5/workers/json-worker.js.map +1 -0
- package/dist/esm/index.js +26 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/json-loader.js +21 -0
- package/dist/esm/json-loader.js.map +1 -0
- package/dist/esm/lib/binary-utils/array-buffer-utils.js +86 -0
- package/dist/esm/lib/binary-utils/array-buffer-utils.js.map +1 -0
- package/dist/esm/lib/binary-utils/binary-copy-utils.js +25 -0
- package/dist/esm/lib/binary-utils/binary-copy-utils.js.map +1 -0
- package/dist/esm/lib/binary-utils/buffer-utils.js +16 -0
- package/dist/esm/lib/binary-utils/buffer-utils.js.map +1 -0
- package/dist/esm/lib/binary-utils/encode-utils.js +31 -0
- package/dist/esm/lib/binary-utils/encode-utils.js.map +1 -0
- package/dist/esm/lib/binary-utils/get-first-characters.js +27 -0
- package/dist/esm/lib/binary-utils/get-first-characters.js.map +1 -0
- package/dist/esm/lib/binary-utils/memory-copy-utils.js +27 -0
- package/dist/esm/lib/binary-utils/memory-copy-utils.js.map +1 -0
- package/dist/esm/lib/env-utils/assert.js +6 -0
- package/dist/esm/lib/env-utils/assert.js.map +1 -0
- package/dist/esm/lib/env-utils/globals.js +16 -0
- package/dist/esm/lib/env-utils/globals.js.map +1 -0
- package/dist/esm/lib/filesystems/node-filesystem.js +60 -0
- package/dist/esm/lib/filesystems/node-filesystem.js.map +1 -0
- package/dist/esm/lib/iterators/async-iteration.js +39 -0
- package/dist/esm/lib/iterators/async-iteration.js.map +1 -0
- package/dist/esm/lib/iterators/text-iterators.js +46 -0
- package/dist/esm/lib/iterators/text-iterators.js.map +1 -0
- package/dist/{lib/node/buffer-utils.node.js → esm/lib/node/buffer.js} +1 -1
- package/dist/esm/lib/node/buffer.js.map +1 -0
- package/dist/esm/lib/node/fs.js +27 -0
- package/dist/esm/lib/node/fs.js.map +1 -0
- package/dist/esm/lib/node/util.js +3 -0
- package/dist/esm/lib/node/util.js.map +1 -0
- package/dist/esm/lib/parser-utils/parse-json.js +9 -0
- package/dist/esm/lib/parser-utils/parse-json.js.map +1 -0
- package/dist/esm/lib/path-utils/file-aliases.js +26 -0
- package/dist/esm/lib/path-utils/file-aliases.js.map +1 -0
- package/dist/esm/lib/path-utils/path.js +24 -0
- package/dist/esm/lib/path-utils/path.js.map +1 -0
- package/dist/esm/lib/request-utils/request-scheduler.js +146 -0
- package/dist/esm/lib/request-utils/request-scheduler.js.map +1 -0
- package/dist/esm/lib/worker-loader-utils/create-loader-worker.js +102 -0
- package/dist/esm/lib/worker-loader-utils/create-loader-worker.js.map +1 -0
- package/dist/esm/lib/worker-loader-utils/parse-with-worker.js +64 -0
- package/dist/esm/lib/worker-loader-utils/parse-with-worker.js.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/workers/json-worker.js +4 -0
- package/dist/esm/workers/json-worker.js.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +111 -22
- package/dist/json-loader.d.ts +22 -0
- package/dist/json-loader.d.ts.map +1 -0
- package/dist/json-loader.js +25 -18
- package/dist/lib/binary-utils/array-buffer-utils.d.ts +31 -0
- package/dist/lib/binary-utils/array-buffer-utils.d.ts.map +1 -0
- package/dist/lib/binary-utils/array-buffer-utils.js +108 -79
- package/dist/lib/binary-utils/binary-copy-utils.d.ts +24 -0
- package/dist/lib/binary-utils/binary-copy-utils.d.ts.map +1 -0
- package/dist/lib/binary-utils/binary-copy-utils.js +48 -22
- package/dist/lib/binary-utils/buffer-utils.d.ts +16 -0
- package/dist/lib/binary-utils/buffer-utils.d.ts.map +1 -0
- package/dist/lib/binary-utils/buffer-utils.js +47 -13
- package/dist/lib/binary-utils/encode-utils.d.ts +4 -0
- package/dist/lib/binary-utils/encode-utils.d.ts.map +1 -0
- package/dist/lib/binary-utils/encode-utils.js +30 -26
- package/dist/lib/binary-utils/get-first-characters.d.ts +3 -0
- package/dist/lib/binary-utils/get-first-characters.d.ts.map +1 -0
- package/dist/lib/binary-utils/get-first-characters.js +28 -25
- package/dist/lib/binary-utils/memory-copy-utils.d.ts +25 -0
- package/dist/lib/binary-utils/memory-copy-utils.d.ts.map +1 -0
- package/dist/lib/binary-utils/memory-copy-utils.js +58 -24
- package/dist/lib/env-utils/assert.d.ts +6 -0
- package/dist/lib/env-utils/assert.d.ts.map +1 -0
- package/dist/lib/env-utils/assert.js +12 -5
- package/dist/lib/env-utils/globals.d.ts +15 -0
- package/dist/lib/env-utils/globals.d.ts.map +1 -0
- package/dist/lib/env-utils/globals.js +23 -9
- package/dist/lib/filesystems/node-filesystem.d.ts +38 -0
- package/dist/lib/filesystems/node-filesystem.d.ts.map +1 -0
- package/dist/lib/filesystems/node-filesystem.js +69 -0
- package/dist/lib/iterators/async-iteration.d.ts +20 -0
- package/dist/lib/iterators/async-iteration.d.ts.map +1 -0
- package/dist/lib/iterators/async-iteration.js +49 -35
- package/dist/lib/iterators/text-iterators.d.ts +19 -0
- package/dist/lib/iterators/text-iterators.d.ts.map +1 -0
- package/dist/lib/iterators/text-iterators.js +56 -41
- package/dist/lib/node/buffer.d.ts +10 -0
- package/dist/lib/node/buffer.d.ts.map +1 -0
- package/dist/lib/node/buffer.js +36 -0
- package/dist/lib/node/fs.d.ts +26 -0
- package/dist/lib/node/fs.d.ts.map +1 -0
- package/dist/lib/node/fs.js +40 -27
- package/dist/lib/node/util.d.ts +5 -0
- package/dist/lib/node/util.d.ts.map +1 -0
- package/dist/lib/node/util.js +25 -0
- package/dist/lib/parser-utils/parse-json.d.ts +5 -0
- package/dist/lib/parser-utils/parse-json.d.ts.map +1 -0
- package/dist/lib/parser-utils/parse-json.js +15 -8
- package/dist/lib/path-utils/file-aliases.d.ts +17 -0
- package/dist/lib/path-utils/file-aliases.d.ts.map +1 -0
- package/dist/lib/path-utils/file-aliases.js +40 -19
- package/dist/lib/path-utils/path.d.ts +16 -0
- package/dist/lib/path-utils/path.d.ts.map +1 -0
- package/dist/lib/path-utils/path.js +38 -18
- package/dist/lib/request-utils/request-scheduler.d.ts +62 -0
- package/dist/lib/request-utils/request-scheduler.d.ts.map +1 -0
- package/dist/lib/request-utils/request-scheduler.js +127 -131
- package/dist/lib/worker-loader-utils/create-loader-worker.d.ts +7 -0
- package/dist/lib/worker-loader-utils/create-loader-worker.d.ts.map +1 -0
- package/dist/lib/worker-loader-utils/create-loader-worker.js +91 -96
- package/dist/lib/worker-loader-utils/parse-with-worker.d.ts +15 -0
- package/dist/lib/worker-loader-utils/parse-with-worker.d.ts.map +1 -0
- package/dist/lib/worker-loader-utils/parse-with-worker.js +69 -60
- package/dist/types.d.ts +207 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -2
- package/dist/workers/json-worker.d.ts +2 -0
- package/dist/workers/json-worker.d.ts.map +1 -0
- package/dist/workers/json-worker.js +5 -4
- package/package.json +15 -14
- package/src/index.ts +26 -8
- package/src/lib/binary-utils/buffer-utils.ts +1 -1
- package/src/lib/env-utils/globals.ts +1 -1
- package/src/lib/filesystems/node-filesystem.ts +79 -0
- package/src/lib/node/{buffer-utils.node.ts → buffer.ts} +0 -0
- package/src/lib/node/fs.ts +29 -13
- package/src/lib/node/util.ts +4 -0
- package/src/lib/path-utils/path.ts +9 -0
- package/src/lib/worker-loader-utils/parse-with-worker.ts +6 -5
- 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/binary-copy-utils.js.map +0 -1
- package/dist/lib/binary-utils/buffer-utils.js.map +0 -1
- package/dist/lib/binary-utils/encode-utils.js.map +0 -1
- package/dist/lib/binary-utils/get-first-characters.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/iterators/async-iteration.js.map +0 -1
- package/dist/lib/iterators/text-iterators.js.map +0 -1
- package/dist/lib/node/buffer-utils.node.js.map +0 -1
- package/dist/lib/node/fs.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/path.js.map +0 -1
- package/dist/lib/request-utils/request-scheduler.js.map +0 -1
- package/dist/lib/worker-loader-utils/create-loader-worker.js.map +0 -1
- package/dist/lib/worker-loader-utils/parse-with-worker.js.map +0 -1
- package/dist/workers/json-worker.js.map +0 -1
|
@@ -1,86 +1,115 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) {
|
|
13
|
-
return data.buffer;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sliceArrayBuffer = exports.concatenateTypedArrays = exports.concatenateArrayBuffers = exports.compareArrayBuffers = exports.toArrayBuffer = void 0;
|
|
4
|
+
const buffer_utils_1 = require("./buffer-utils");
|
|
5
|
+
/**
|
|
6
|
+
* Convert an object to an array buffer
|
|
7
|
+
*/
|
|
8
|
+
function toArrayBuffer(data) {
|
|
9
|
+
// Note: Should be called first, Buffers can trigger other detections below
|
|
10
|
+
if ((0, buffer_utils_1.isBuffer)(data)) {
|
|
11
|
+
return (0, buffer_utils_1.bufferToArrayBuffer)(data);
|
|
14
12
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
13
|
+
if (data instanceof ArrayBuffer) {
|
|
14
|
+
return data;
|
|
15
|
+
}
|
|
16
|
+
// Careful - Node Buffers look like Uint8Arrays (keep after isBuffer)
|
|
17
|
+
if (ArrayBuffer.isView(data)) {
|
|
18
|
+
if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) {
|
|
19
|
+
return data.buffer;
|
|
20
|
+
}
|
|
21
|
+
return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
|
|
22
|
+
}
|
|
23
|
+
if (typeof data === 'string') {
|
|
24
|
+
const text = data;
|
|
25
|
+
const uint8Array = new TextEncoder().encode(text);
|
|
26
|
+
return uint8Array.buffer;
|
|
27
|
+
}
|
|
28
|
+
// HACK to support Blob polyfill
|
|
29
|
+
if (data && typeof data === 'object' && data._toArrayBuffer) {
|
|
30
|
+
return data._toArrayBuffer();
|
|
31
|
+
}
|
|
32
|
+
throw new Error('toArrayBuffer');
|
|
30
33
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (array1[i] !== array2[i]) {
|
|
43
|
-
return false;
|
|
34
|
+
exports.toArrayBuffer = toArrayBuffer;
|
|
35
|
+
/**
|
|
36
|
+
* compare two binary arrays for equality
|
|
37
|
+
* @param {ArrayBuffer} a
|
|
38
|
+
* @param {ArrayBuffer} b
|
|
39
|
+
* @param {number} byteLength
|
|
40
|
+
*/
|
|
41
|
+
function compareArrayBuffers(arrayBuffer1, arrayBuffer2, byteLength) {
|
|
42
|
+
byteLength = byteLength || arrayBuffer1.byteLength;
|
|
43
|
+
if (arrayBuffer1.byteLength < byteLength || arrayBuffer2.byteLength < byteLength) {
|
|
44
|
+
return false;
|
|
44
45
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
const array1 = new Uint8Array(arrayBuffer1);
|
|
47
|
+
const array2 = new Uint8Array(arrayBuffer2);
|
|
48
|
+
for (let i = 0; i < array1.length; ++i) {
|
|
49
|
+
if (array1[i] !== array2[i]) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return true;
|
|
48
54
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
55
|
+
exports.compareArrayBuffers = compareArrayBuffers;
|
|
56
|
+
/**
|
|
57
|
+
* Concatenate a sequence of ArrayBuffers
|
|
58
|
+
* @return A concatenated ArrayBuffer
|
|
59
|
+
*/
|
|
60
|
+
function concatenateArrayBuffers(...sources) {
|
|
61
|
+
// Make sure all inputs are wrapped in typed arrays
|
|
62
|
+
const sourceArrays = sources.map((source2) => source2 instanceof ArrayBuffer ? new Uint8Array(source2) : source2);
|
|
63
|
+
// Get length of all inputs
|
|
64
|
+
const byteLength = sourceArrays.reduce((length, typedArray) => length + typedArray.byteLength, 0);
|
|
65
|
+
// Allocate array with space for all inputs
|
|
66
|
+
const result = new Uint8Array(byteLength);
|
|
67
|
+
// Copy the subarrays
|
|
68
|
+
let offset = 0;
|
|
69
|
+
for (const sourceArray of sourceArrays) {
|
|
70
|
+
result.set(sourceArray, offset);
|
|
71
|
+
offset += sourceArray.byteLength;
|
|
72
|
+
}
|
|
73
|
+
// We work with ArrayBuffers, discard the typed array wrapper
|
|
74
|
+
return result.buffer;
|
|
61
75
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
exports.concatenateArrayBuffers = concatenateArrayBuffers;
|
|
77
|
+
/**
|
|
78
|
+
* Concatenate arbitrary count of typed arrays
|
|
79
|
+
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays
|
|
80
|
+
* @param {...*} arrays - list of arrays. All arrays should be the same type
|
|
81
|
+
* @return A concatenated TypedArray
|
|
82
|
+
*/
|
|
83
|
+
function concatenateTypedArrays(...typedArrays) {
|
|
84
|
+
// @ts-ignore
|
|
85
|
+
const arrays = typedArrays;
|
|
86
|
+
// @ts-ignore
|
|
87
|
+
const TypedArrayConstructor = (arrays && arrays.length > 1 && arrays[0].constructor) || null;
|
|
88
|
+
if (!TypedArrayConstructor) {
|
|
89
|
+
throw new Error('"concatenateTypedArrays" - incorrect quantity of arguments or arguments have incompatible data types');
|
|
90
|
+
}
|
|
91
|
+
const sumLength = arrays.reduce((acc, value) => acc + value.length, 0);
|
|
92
|
+
// @ts-ignore typescript does not like dynamic constructors
|
|
93
|
+
const result = new TypedArrayConstructor(sumLength);
|
|
94
|
+
let offset = 0;
|
|
95
|
+
for (const array of arrays) {
|
|
96
|
+
result.set(array, offset);
|
|
97
|
+
offset += array.length;
|
|
98
|
+
}
|
|
99
|
+
return result;
|
|
80
100
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
101
|
+
exports.concatenateTypedArrays = concatenateTypedArrays;
|
|
102
|
+
/**
|
|
103
|
+
* Copy a view of an ArrayBuffer into new ArrayBuffer with byteOffset = 0
|
|
104
|
+
* @param arrayBuffer
|
|
105
|
+
* @param byteOffset
|
|
106
|
+
* @param byteLength
|
|
107
|
+
*/
|
|
108
|
+
function sliceArrayBuffer(arrayBuffer, byteOffset, byteLength) {
|
|
109
|
+
const subArray = byteLength !== undefined
|
|
110
|
+
? new Uint8Array(arrayBuffer).subarray(byteOffset, byteOffset + byteLength)
|
|
111
|
+
: new Uint8Array(arrayBuffer).subarray(byteOffset);
|
|
112
|
+
const arrayCopy = new Uint8Array(subArray);
|
|
113
|
+
return arrayCopy.buffer;
|
|
85
114
|
}
|
|
86
|
-
|
|
115
|
+
exports.sliceArrayBuffer = sliceArrayBuffer;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { TypedArray } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Copy sourceBuffer to dataView with some padding
|
|
4
|
+
*
|
|
5
|
+
* @param {DataView | null} dataView - destination data container. If null - only new offset is calculated
|
|
6
|
+
* @param {number} byteOffset - destination byte offset to copy to
|
|
7
|
+
* @param {Array | TypedArray} sourceBuffer - source data buffer
|
|
8
|
+
* @param {number} padding - pad the resulting array to multiple of "padding" bytes. Additional bytes are filled with 0x20 (ASCII space)
|
|
9
|
+
*
|
|
10
|
+
* @return new byteOffset of resulting dataView
|
|
11
|
+
*/
|
|
12
|
+
export declare function copyPaddedArrayBufferToDataView(dataView: DataView | null, byteOffset: number, sourceBuffer: TypedArray, padding: number): number;
|
|
13
|
+
/**
|
|
14
|
+
* Copy string to dataView with some padding
|
|
15
|
+
*
|
|
16
|
+
* @param {DataView | null} dataView - destination data container. If null - only new offset is calculated
|
|
17
|
+
* @param {number} byteOffset - destination byte offset to copy to
|
|
18
|
+
* @param {string} string - source string
|
|
19
|
+
* @param {number} padding - pad the resulting array to multiple of "padding" bytes. Additional bytes are filled with 0x20 (ASCII space)
|
|
20
|
+
*
|
|
21
|
+
* @return new byteOffset of resulting dataView
|
|
22
|
+
*/
|
|
23
|
+
export declare function copyPaddedStringToDataView(dataView: DataView | null, byteOffset: number, string: string, padding: number): number;
|
|
24
|
+
//# sourceMappingURL=binary-copy-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binary-copy-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/binary-utils/binary-copy-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,aAAa,CAAC;AAGvC;;;;;;;;;GASG;AACH,wBAAgB,+BAA+B,CAC7C,QAAQ,EAAE,QAAQ,GAAG,IAAI,EACzB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,UAAU,EACxB,OAAO,EAAE,MAAM,UAuBhB;AAED;;;;;;;;;GASG;AACH,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,QAAQ,GAAG,IAAI,EACzB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GACd,MAAM,CASR"}
|
|
@@ -1,25 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.copyPaddedStringToDataView = exports.copyPaddedArrayBufferToDataView = void 0;
|
|
4
|
+
const memory_copy_utils_1 = require("./memory-copy-utils");
|
|
5
|
+
/**
|
|
6
|
+
* Copy sourceBuffer to dataView with some padding
|
|
7
|
+
*
|
|
8
|
+
* @param {DataView | null} dataView - destination data container. If null - only new offset is calculated
|
|
9
|
+
* @param {number} byteOffset - destination byte offset to copy to
|
|
10
|
+
* @param {Array | TypedArray} sourceBuffer - source data buffer
|
|
11
|
+
* @param {number} padding - pad the resulting array to multiple of "padding" bytes. Additional bytes are filled with 0x20 (ASCII space)
|
|
12
|
+
*
|
|
13
|
+
* @return new byteOffset of resulting dataView
|
|
14
|
+
*/
|
|
15
|
+
function copyPaddedArrayBufferToDataView(dataView, byteOffset, sourceBuffer, padding) {
|
|
16
|
+
const paddedLength = (0, memory_copy_utils_1.padToNBytes)(sourceBuffer.byteLength, padding);
|
|
17
|
+
const padLength = paddedLength - sourceBuffer.byteLength;
|
|
18
|
+
if (dataView) {
|
|
19
|
+
// Copy array
|
|
20
|
+
const targetArray = new Uint8Array(dataView.buffer, dataView.byteOffset + byteOffset, sourceBuffer.byteLength);
|
|
21
|
+
const sourceArray = new Uint8Array(sourceBuffer);
|
|
22
|
+
targetArray.set(sourceArray);
|
|
23
|
+
// Add PADDING
|
|
24
|
+
for (let i = 0; i < padLength; ++i) {
|
|
25
|
+
// json chunk is padded with spaces (ASCII 0x20)
|
|
26
|
+
dataView.setUint8(byteOffset + sourceBuffer.byteLength + i, 0x20);
|
|
27
|
+
}
|
|
13
28
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
byteOffset += paddedLength;
|
|
17
|
-
return byteOffset;
|
|
29
|
+
byteOffset += paddedLength;
|
|
30
|
+
return byteOffset;
|
|
18
31
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
32
|
+
exports.copyPaddedArrayBufferToDataView = copyPaddedArrayBufferToDataView;
|
|
33
|
+
/**
|
|
34
|
+
* Copy string to dataView with some padding
|
|
35
|
+
*
|
|
36
|
+
* @param {DataView | null} dataView - destination data container. If null - only new offset is calculated
|
|
37
|
+
* @param {number} byteOffset - destination byte offset to copy to
|
|
38
|
+
* @param {string} string - source string
|
|
39
|
+
* @param {number} padding - pad the resulting array to multiple of "padding" bytes. Additional bytes are filled with 0x20 (ASCII space)
|
|
40
|
+
*
|
|
41
|
+
* @return new byteOffset of resulting dataView
|
|
42
|
+
*/
|
|
43
|
+
function copyPaddedStringToDataView(dataView, byteOffset, string, padding) {
|
|
44
|
+
const textEncoder = new TextEncoder();
|
|
45
|
+
// PERFORMANCE IDEA: We encode twice, once to get size and once to store
|
|
46
|
+
// PERFORMANCE IDEA: Use TextEncoder.encodeInto() to avoid temporary copy
|
|
47
|
+
const stringBuffer = textEncoder.encode(string);
|
|
48
|
+
byteOffset = copyPaddedArrayBufferToDataView(dataView, byteOffset, stringBuffer, padding);
|
|
49
|
+
return byteOffset;
|
|
24
50
|
}
|
|
25
|
-
|
|
51
|
+
exports.copyPaddedStringToDataView = copyPaddedStringToDataView;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
* Check for Node.js `Buffer` (without triggering bundler to include Buffer polyfill on browser)
|
|
4
|
+
*/
|
|
5
|
+
export declare function isBuffer(value: any): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Converts to Node.js `Buffer` (without triggering bundler to include Buffer polyfill on browser)
|
|
8
|
+
* @todo better data type
|
|
9
|
+
*/
|
|
10
|
+
export declare function toBuffer(data: any): Buffer;
|
|
11
|
+
/**
|
|
12
|
+
* Converts Node.js `Buffer` to `ArrayBuffer` (without triggering bundler to include Buffer polyfill on browser)
|
|
13
|
+
* @todo better data type
|
|
14
|
+
*/
|
|
15
|
+
export declare function bufferToArrayBuffer(buffer: any): ArrayBuffer;
|
|
16
|
+
//# sourceMappingURL=buffer-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buffer-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/binary-utils/buffer-utils.ts"],"names":[],"mappings":";AAEA;;GAEG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAE5C;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,CAE1C;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,GAAG,GAAG,WAAW,CAM5D"}
|
|
@@ -1,16 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.bufferToArrayBuffer = exports.toBuffer = exports.isBuffer = void 0;
|
|
23
|
+
const node = __importStar(require("../node/buffer"));
|
|
24
|
+
/**
|
|
25
|
+
* Check for Node.js `Buffer` (without triggering bundler to include Buffer polyfill on browser)
|
|
26
|
+
*/
|
|
27
|
+
function isBuffer(value) {
|
|
28
|
+
return value && typeof value === 'object' && value.isBuffer;
|
|
4
29
|
}
|
|
5
|
-
|
|
6
|
-
|
|
30
|
+
exports.isBuffer = isBuffer;
|
|
31
|
+
/**
|
|
32
|
+
* Converts to Node.js `Buffer` (without triggering bundler to include Buffer polyfill on browser)
|
|
33
|
+
* @todo better data type
|
|
34
|
+
*/
|
|
35
|
+
function toBuffer(data) {
|
|
36
|
+
return node.toBuffer ? node.toBuffer(data) : data;
|
|
7
37
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
38
|
+
exports.toBuffer = toBuffer;
|
|
39
|
+
/**
|
|
40
|
+
* Converts Node.js `Buffer` to `ArrayBuffer` (without triggering bundler to include Buffer polyfill on browser)
|
|
41
|
+
* @todo better data type
|
|
42
|
+
*/
|
|
43
|
+
function bufferToArrayBuffer(buffer) {
|
|
44
|
+
if (isBuffer(buffer)) {
|
|
45
|
+
const typedArray = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.length);
|
|
46
|
+
return typedArray.slice().buffer;
|
|
47
|
+
}
|
|
48
|
+
return buffer;
|
|
15
49
|
}
|
|
16
|
-
|
|
50
|
+
exports.bufferToArrayBuffer = bufferToArrayBuffer;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function padStringToByteAlignment(string: any, byteAlignment: any): string;
|
|
2
|
+
export declare function copyStringToDataView(dataView: any, byteOffset: any, string: any, byteLength: any): any;
|
|
3
|
+
export declare function copyBinaryToDataView(dataView: any, byteOffset: any, binary: any, byteLength: any): any;
|
|
4
|
+
//# sourceMappingURL=encode-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encode-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/binary-utils/encode-utils.ts"],"names":[],"mappings":"AAIA,wBAAgB,wBAAwB,CAAC,MAAM,KAAA,EAAE,aAAa,KAAA,UAS7D;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,KAAA,EAAE,UAAU,KAAA,EAAE,MAAM,KAAA,EAAE,UAAU,KAAA,OAO5E;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,KAAA,EAAE,UAAU,KAAA,EAAE,MAAM,KAAA,EAAE,UAAU,KAAA,OAO5E"}
|
|
@@ -1,31 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
// Note: These were broken out from gltf loader...
|
|
3
|
+
// eslint-disable-next-line complexity
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.copyBinaryToDataView = exports.copyStringToDataView = exports.padStringToByteAlignment = void 0;
|
|
6
|
+
// PERFORMANCE IDEA: No need to copy string twice...
|
|
7
|
+
function padStringToByteAlignment(string, byteAlignment) {
|
|
8
|
+
const length = string.length;
|
|
9
|
+
const paddedLength = Math.ceil(length / byteAlignment) * byteAlignment; // Round up to the required alignment
|
|
10
|
+
const padding = paddedLength - length;
|
|
11
|
+
let whitespace = '';
|
|
12
|
+
for (let i = 0; i < padding; ++i) {
|
|
13
|
+
whitespace += ' ';
|
|
14
|
+
}
|
|
15
|
+
return string + whitespace;
|
|
12
16
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
exports.padStringToByteAlignment = padStringToByteAlignment;
|
|
18
|
+
function copyStringToDataView(dataView, byteOffset, string, byteLength) {
|
|
19
|
+
if (dataView) {
|
|
20
|
+
for (let i = 0; i < byteLength; i++) {
|
|
21
|
+
dataView.setUint8(byteOffset + i, string.charCodeAt(i));
|
|
22
|
+
}
|
|
17
23
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return byteOffset + byteLength;
|
|
24
|
+
return byteOffset + byteLength;
|
|
21
25
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
exports.copyStringToDataView = copyStringToDataView;
|
|
27
|
+
function copyBinaryToDataView(dataView, byteOffset, binary, byteLength) {
|
|
28
|
+
if (dataView) {
|
|
29
|
+
for (let i = 0; i < byteLength; i++) {
|
|
30
|
+
dataView.setUint8(byteOffset + i, binary[i]);
|
|
31
|
+
}
|
|
26
32
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return byteOffset + byteLength;
|
|
33
|
+
return byteOffset + byteLength;
|
|
30
34
|
}
|
|
31
|
-
|
|
35
|
+
exports.copyBinaryToDataView = copyBinaryToDataView;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-first-characters.d.ts","sourceRoot":"","sources":["../../../src/lib/binary-utils/get-first-characters.ts"],"names":[],"mappings":"AAAA,wBAAgB,kBAAkB,CAAC,IAAI,KAAA,EAAE,MAAM,SAAI,GAAG,MAAM,CAW3D;AAED,wBAAgB,cAAc,CAC5B,WAAW,EAAE,WAAW,EACxB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,GACb,MAAM,CAUR"}
|
|
@@ -1,27 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMagicString = exports.getFirstCharacters = void 0;
|
|
4
|
+
function getFirstCharacters(data, length = 5) {
|
|
5
|
+
if (typeof data === 'string') {
|
|
6
|
+
return data.slice(0, length);
|
|
7
|
+
}
|
|
8
|
+
else if (ArrayBuffer.isView(data)) {
|
|
9
|
+
// Typed Arrays can have offsets into underlying buffer
|
|
10
|
+
return getMagicString(data.buffer, data.byteOffset, length);
|
|
11
|
+
}
|
|
12
|
+
else if (data instanceof ArrayBuffer) {
|
|
13
|
+
const byteOffset = 0;
|
|
14
|
+
return getMagicString(data, byteOffset, length);
|
|
15
|
+
}
|
|
15
16
|
return '';
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const dataView = new DataView(arrayBuffer);
|
|
19
|
-
let magic = '';
|
|
20
|
-
|
|
21
|
-
for (let i = 0; i < length; i++) {
|
|
22
|
-
magic += String.fromCharCode(dataView.getUint8(byteOffset + i));
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return magic;
|
|
26
17
|
}
|
|
27
|
-
|
|
18
|
+
exports.getFirstCharacters = getFirstCharacters;
|
|
19
|
+
function getMagicString(arrayBuffer, byteOffset, length) {
|
|
20
|
+
if (arrayBuffer.byteLength <= byteOffset + length) {
|
|
21
|
+
return '';
|
|
22
|
+
}
|
|
23
|
+
const dataView = new DataView(arrayBuffer);
|
|
24
|
+
let magic = '';
|
|
25
|
+
for (let i = 0; i < length; i++) {
|
|
26
|
+
magic += String.fromCharCode(dataView.getUint8(byteOffset + i));
|
|
27
|
+
}
|
|
28
|
+
return magic;
|
|
29
|
+
}
|
|
30
|
+
exports.getMagicString = getMagicString;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculate new size of an arrayBuffer to be aligned to an n-byte boundary
|
|
3
|
+
* This function increases `byteLength` by the minimum delta,
|
|
4
|
+
* allowing the total length to be divided by `padding`
|
|
5
|
+
* @param byteLength
|
|
6
|
+
* @param padding
|
|
7
|
+
*/
|
|
8
|
+
export declare function padToNBytes(byteLength: number, padding: number): number;
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new Uint8Array based on two different ArrayBuffers
|
|
11
|
+
* @param targetBuffer The first buffer.
|
|
12
|
+
* @param sourceBuffer The second buffer.
|
|
13
|
+
* @return The new ArrayBuffer created out of the two.
|
|
14
|
+
*/
|
|
15
|
+
export declare function copyArrayBuffer(targetBuffer: ArrayBuffer, sourceBuffer: ArrayBuffer, byteOffset: number, byteLength?: number): ArrayBuffer;
|
|
16
|
+
/**
|
|
17
|
+
* Copy from source to target at the targetOffset
|
|
18
|
+
*
|
|
19
|
+
* @param source - The data to copy
|
|
20
|
+
* @param target - The destination to copy data into
|
|
21
|
+
* @param targetOffset - The start offset into target to place the copied data
|
|
22
|
+
* @returns the new offset taking into account proper padding
|
|
23
|
+
*/
|
|
24
|
+
export declare function copyToArray(source: ArrayBuffer | any, target: any, targetOffset: number): number;
|
|
25
|
+
//# sourceMappingURL=memory-copy-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-copy-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/binary-utils/memory-copy-utils.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAIvE;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,YAAY,EAAE,WAAW,EACzB,YAAY,EAAE,WAAW,EACzB,UAAU,EAAE,MAAM,EAClB,UAAU,GAAE,MAAgC,GAC3C,WAAW,CAKb;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,WAAW,GAAG,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAuBhG"}
|