@loaders.gl/loader-utils 3.3.0-alpha.12 → 3.3.0-alpha.14
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 +28 -18
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/json-loader.js +1 -1
- package/dist/es5/lib/binary-utils/array-buffer-utils.js +0 -30
- package/dist/es5/lib/binary-utils/array-buffer-utils.js.map +1 -1
- package/dist/es5/lib/binary-utils/{binary-copy-utils.js → dataview-copy-utils.js} +33 -1
- package/dist/es5/lib/binary-utils/dataview-copy-utils.js.map +1 -0
- package/dist/es5/lib/binary-utils/get-first-characters.js +2 -0
- package/dist/es5/lib/binary-utils/get-first-characters.js.map +1 -1
- package/dist/es5/lib/binary-utils/{buffer-utils.js → memory-conversion-utils.js} +26 -7
- package/dist/es5/lib/binary-utils/memory-conversion-utils.js.map +1 -0
- package/dist/es5/lib/filesystems/readable-file.js +100 -0
- package/dist/es5/lib/filesystems/readable-file.js.map +1 -0
- package/dist/es5/lib/filesystems/writable-file.js +89 -0
- package/dist/es5/lib/filesystems/writable-file.js.map +1 -0
- package/dist/es5/lib/loader-utils/buffer-utils.js +19 -0
- package/dist/es5/lib/loader-utils/buffer-utils.js.map +1 -0
- package/dist/es5/lib/node/buffer.js +5 -8
- package/dist/es5/lib/node/buffer.js.map +1 -1
- package/dist/es5/lib/node/fs.js +18 -9
- package/dist/es5/lib/node/fs.js.map +1 -1
- package/dist/es5/lib/node/stream.js +20 -0
- package/dist/es5/lib/node/stream.js.map +1 -0
- package/dist/es5/lib/node/util.js +16 -6
- package/dist/es5/lib/node/util.js.map +1 -1
- package/dist/esm/index.js +11 -7
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/json-loader.js +1 -1
- package/dist/esm/lib/binary-utils/array-buffer-utils.js +0 -27
- package/dist/esm/lib/binary-utils/array-buffer-utils.js.map +1 -1
- package/dist/esm/lib/binary-utils/{binary-copy-utils.js → dataview-copy-utils.js} +31 -1
- package/dist/esm/lib/binary-utils/dataview-copy-utils.js.map +1 -0
- package/dist/esm/lib/binary-utils/get-first-characters.js +3 -0
- package/dist/esm/lib/binary-utils/get-first-characters.js.map +1 -1
- package/dist/esm/lib/binary-utils/memory-conversion-utils.js +38 -0
- package/dist/esm/lib/binary-utils/memory-conversion-utils.js.map +1 -0
- package/dist/esm/lib/filesystems/readable-file.js +22 -0
- package/dist/esm/lib/filesystems/readable-file.js.map +1 -0
- package/dist/esm/lib/filesystems/writable-file.js +21 -0
- package/dist/esm/lib/filesystems/writable-file.js.map +1 -0
- package/dist/esm/lib/loader-utils/buffer-utils.js +13 -0
- package/dist/esm/lib/loader-utils/buffer-utils.js.map +1 -0
- package/dist/esm/lib/node/buffer.js +5 -9
- package/dist/esm/lib/node/buffer.js.map +1 -1
- package/dist/esm/lib/node/fs.js +11 -9
- package/dist/esm/lib/node/fs.js.map +1 -1
- package/dist/esm/lib/node/stream.js +11 -0
- package/dist/esm/lib/node/stream.js.map +1 -0
- package/dist/esm/lib/node/util.js +5 -10
- package/dist/esm/lib/node/util.js.map +1 -1
- package/dist/index.d.ts +10 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -17
- package/dist/lib/binary-utils/array-buffer-utils.d.ts +4 -8
- package/dist/lib/binary-utils/array-buffer-utils.d.ts.map +1 -1
- package/dist/lib/binary-utils/array-buffer-utils.js +5 -36
- package/dist/lib/binary-utils/dataview-copy-utils.d.ts +43 -0
- package/dist/lib/binary-utils/dataview-copy-utils.d.ts.map +1 -0
- package/dist/lib/binary-utils/{binary-copy-utils.js → dataview-copy-utils.js} +51 -5
- package/dist/lib/binary-utils/get-first-characters.d.ts +15 -1
- package/dist/lib/binary-utils/get-first-characters.d.ts.map +1 -1
- package/dist/lib/binary-utils/get-first-characters.js +15 -0
- package/dist/lib/binary-utils/{buffer-utils.d.ts → memory-conversion-utils.d.ts} +3 -4
- package/dist/lib/binary-utils/memory-conversion-utils.d.ts.map +1 -0
- package/dist/lib/binary-utils/{buffer-utils.js → memory-conversion-utils.js} +28 -9
- package/dist/lib/filesystems/readable-file.d.ts +10 -0
- package/dist/lib/filesystems/readable-file.d.ts.map +1 -0
- package/dist/lib/filesystems/readable-file.js +25 -0
- package/dist/lib/filesystems/writable-file.d.ts +18 -0
- package/dist/lib/filesystems/writable-file.d.ts.map +1 -0
- package/dist/lib/filesystems/writable-file.js +48 -0
- package/dist/lib/loader-utils/buffer-utils.d.ts +10 -0
- package/dist/lib/loader-utils/buffer-utils.d.ts.map +1 -0
- package/dist/lib/loader-utils/buffer-utils.js +22 -0
- package/dist/lib/node/buffer.d.ts +3 -1
- package/dist/lib/node/buffer.d.ts.map +1 -1
- package/dist/lib/node/buffer.js +7 -8
- package/dist/lib/node/fs.d.ts +4 -2
- package/dist/lib/node/fs.d.ts.map +1 -1
- package/dist/lib/node/fs.js +10 -9
- package/dist/lib/node/stream.d.ts +4 -0
- package/dist/lib/node/stream.d.ts.map +1 -0
- package/dist/lib/node/stream.js +17 -0
- package/dist/lib/node/util.d.ts +2 -1
- package/dist/lib/node/util.d.ts.map +1 -1
- package/dist/lib/node/util.js +7 -11
- package/dist/lib/worker-loader-utils/create-loader-worker.js +1 -1
- package/package.json +5 -4
- package/src/index.ts +19 -12
- package/src/lib/binary-utils/array-buffer-utils.ts +4 -40
- package/src/lib/binary-utils/{binary-copy-utils.ts → dataview-copy-utils.ts} +57 -5
- package/src/lib/binary-utils/get-first-characters.ts +17 -1
- package/src/lib/binary-utils/memory-conversion-utils.ts +53 -0
- package/src/lib/filesystems/readable-file.ts +30 -0
- package/src/lib/filesystems/writable-file.ts +44 -0
- package/src/lib/loader-utils/buffer-utils.ts +18 -0
- package/src/lib/node/buffer.ts +9 -10
- package/src/lib/node/fs.ts +16 -11
- package/src/lib/node/stream.ts +18 -0
- package/src/lib/node/util.ts +51 -11
- package/dist/es5/lib/binary-utils/binary-copy-utils.js.map +0 -1
- package/dist/es5/lib/binary-utils/buffer-utils.js.map +0 -1
- package/dist/es5/lib/binary-utils/encode-utils.js +0 -36
- package/dist/es5/lib/binary-utils/encode-utils.js.map +0 -1
- package/dist/esm/lib/binary-utils/binary-copy-utils.js.map +0 -1
- package/dist/esm/lib/binary-utils/buffer-utils.js +0 -18
- package/dist/esm/lib/binary-utils/buffer-utils.js.map +0 -1
- package/dist/esm/lib/binary-utils/encode-utils.js +0 -29
- package/dist/esm/lib/binary-utils/encode-utils.js.map +0 -1
- package/dist/lib/binary-utils/binary-copy-utils.d.ts +0 -24
- package/dist/lib/binary-utils/binary-copy-utils.d.ts.map +0 -1
- package/dist/lib/binary-utils/buffer-utils.d.ts.map +0 -1
- package/dist/lib/binary-utils/encode-utils.d.ts +0 -4
- package/dist/lib/binary-utils/encode-utils.d.ts.map +0 -1
- package/dist/lib/binary-utils/encode-utils.js +0 -35
- package/src/lib/binary-utils/buffer-utils.ts +0 -28
- package/src/lib/binary-utils/encode-utils.ts +0 -32
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// loaders.gl, MIT license
|
|
2
|
+
|
|
3
|
+
import * as node from '../node/buffer';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Check for Node.js `Buffer` (without triggering bundler to include Buffer polyfill on browser)
|
|
7
|
+
*/
|
|
8
|
+
export function isBuffer(value: any): boolean {
|
|
9
|
+
return value && typeof value === 'object' && value.isBuffer;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Converts to Node.js `Buffer` (without triggering bundler to include Buffer polyfill on browser)
|
|
14
|
+
* @todo better data type
|
|
15
|
+
*/
|
|
16
|
+
export function toBuffer(data: any): Buffer {
|
|
17
|
+
return node.toBuffer ? node.toBuffer(data) : data;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Convert an object to an array buffer
|
|
22
|
+
*/
|
|
23
|
+
export function toArrayBuffer(data: unknown): ArrayBuffer {
|
|
24
|
+
// Note: Should be called first, Buffers can trigger other detections below
|
|
25
|
+
if (isBuffer(data)) {
|
|
26
|
+
return node.toArrayBuffer(data);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (data instanceof ArrayBuffer) {
|
|
30
|
+
return data;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Careful - Node Buffers look like Uint8Arrays (keep after isBuffer)
|
|
34
|
+
if (ArrayBuffer.isView(data)) {
|
|
35
|
+
if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) {
|
|
36
|
+
return data.buffer;
|
|
37
|
+
}
|
|
38
|
+
return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (typeof data === 'string') {
|
|
42
|
+
const text = data;
|
|
43
|
+
const uint8Array = new TextEncoder().encode(text);
|
|
44
|
+
return uint8Array.buffer;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// HACK to support Blob polyfill
|
|
48
|
+
if (data && typeof data === 'object' && (data as any)._toArrayBuffer) {
|
|
49
|
+
return (data as any)._toArrayBuffer();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
throw new Error('toArrayBuffer');
|
|
53
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// loaders.gl, MIT license
|
|
2
|
+
|
|
3
|
+
export type ReadableFile = {
|
|
4
|
+
read: (position: number, length: number) => Promise<Buffer>;
|
|
5
|
+
close: () => Promise<void>;
|
|
6
|
+
/** Length of file in bytes */
|
|
7
|
+
size: number;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
/** Helper function to create an envelope reader for a binary memory input */
|
|
11
|
+
export function makeReadableFile(data: Blob | ArrayBuffer): ReadableFile {
|
|
12
|
+
if (data instanceof ArrayBuffer) {
|
|
13
|
+
const arrayBuffer: ArrayBuffer = data;
|
|
14
|
+
return {
|
|
15
|
+
read: async (start: number, length: number) => Buffer.from(data, start, length),
|
|
16
|
+
close: async () => {},
|
|
17
|
+
size: arrayBuffer.byteLength
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const blob: Blob = data;
|
|
22
|
+
return {
|
|
23
|
+
read: async (start: number, length: number) => {
|
|
24
|
+
const arrayBuffer = await blob.slice(start, start + length).arrayBuffer();
|
|
25
|
+
return Buffer.from(arrayBuffer);
|
|
26
|
+
},
|
|
27
|
+
close: async () => {},
|
|
28
|
+
size: blob.size
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Forked from https://github.com/kbajalc/parquets under MIT license (Copyright (c) 2017 ironSource Ltd.)
|
|
2
|
+
import {isBrowser} from '@loaders.gl/loader-utils';
|
|
3
|
+
import * as fs from '../node/fs';
|
|
4
|
+
import type {Writable} from 'stream';
|
|
5
|
+
|
|
6
|
+
export type WritableFile = {
|
|
7
|
+
write: (buf: Buffer) => Promise<void>;
|
|
8
|
+
close: () => Promise<void>;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export interface WriteStreamOptions {
|
|
12
|
+
flags?: string;
|
|
13
|
+
encoding?: 'utf8';
|
|
14
|
+
fd?: number;
|
|
15
|
+
mode?: number;
|
|
16
|
+
autoClose?: boolean;
|
|
17
|
+
start?: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Helper function to create an envelope reader for a binary memory input */
|
|
21
|
+
export function makeWritableFile(
|
|
22
|
+
pathOrStream: string | Writable,
|
|
23
|
+
options?: WriteStreamOptions
|
|
24
|
+
): WritableFile {
|
|
25
|
+
if (isBrowser) {
|
|
26
|
+
return {
|
|
27
|
+
write: async () => {},
|
|
28
|
+
close: async () => {}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const outputStream: Writable =
|
|
33
|
+
typeof pathOrStream === 'string' ? fs.createWriteStream(pathOrStream, options) : pathOrStream;
|
|
34
|
+
return {
|
|
35
|
+
write: async (buffer: Buffer) =>
|
|
36
|
+
new Promise((resolve, reject) => {
|
|
37
|
+
outputStream.write(buffer, (err) => (err ? reject(err) : resolve()));
|
|
38
|
+
}),
|
|
39
|
+
close: () =>
|
|
40
|
+
new Promise((resolve, reject) => {
|
|
41
|
+
(outputStream as any).close((err) => (err ? reject(err) : resolve()));
|
|
42
|
+
})
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert Buffer to ArrayBuffer
|
|
3
|
+
*/
|
|
4
|
+
export function toArrayBuffer(buffer: Buffer): ArrayBuffer {
|
|
5
|
+
// TODO - per docs we should just be able to call buffer.buffer, but there are issues
|
|
6
|
+
if (Buffer.isBuffer(buffer)) {
|
|
7
|
+
const typedArray = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.length);
|
|
8
|
+
return typedArray.slice().buffer;
|
|
9
|
+
}
|
|
10
|
+
return buffer;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Convert (copy) ArrayBuffer to Buffer
|
|
15
|
+
*/
|
|
16
|
+
export function toBuffer(arrayBuffer: ArrayBuffer): Buffer {
|
|
17
|
+
return Buffer.from(arrayBuffer);
|
|
18
|
+
}
|
package/src/lib/node/buffer.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// Isolates Buffer references to ensure they are only bundled under Node.js (avoids big webpack polyfill)
|
|
2
2
|
// this file is not visible to webpack (it is excluded in the package.json "browser" field).
|
|
3
3
|
|
|
4
|
-
import {assert} from '../env-utils/assert';
|
|
5
|
-
|
|
6
4
|
/**
|
|
7
5
|
* Convert Buffer to ArrayBuffer
|
|
6
|
+
* Converts Node.js `Buffer` to `ArrayBuffer` (without triggering bundler to include Buffer polyfill on browser)
|
|
7
|
+
* @todo better data type
|
|
8
8
|
*/
|
|
9
9
|
export function toArrayBuffer(buffer) {
|
|
10
10
|
// TODO - per docs we should just be able to call buffer.buffer, but there are issues
|
|
@@ -18,19 +18,18 @@ export function toArrayBuffer(buffer) {
|
|
|
18
18
|
/**
|
|
19
19
|
* Convert (copy) ArrayBuffer to Buffer
|
|
20
20
|
*/
|
|
21
|
-
export function toBuffer(binaryData) {
|
|
21
|
+
export function toBuffer(binaryData: ArrayBuffer | ArrayBuffer | Buffer): Buffer {
|
|
22
|
+
if (Buffer.isBuffer(binaryData)) {
|
|
23
|
+
return binaryData;
|
|
24
|
+
}
|
|
25
|
+
|
|
22
26
|
if (ArrayBuffer.isView(binaryData)) {
|
|
23
27
|
binaryData = binaryData.buffer;
|
|
24
28
|
}
|
|
25
29
|
|
|
26
30
|
if (typeof Buffer !== 'undefined' && binaryData instanceof ArrayBuffer) {
|
|
27
|
-
|
|
28
|
-
const view = new Uint8Array(binaryData);
|
|
29
|
-
for (let i = 0; i < buffer.length; ++i) {
|
|
30
|
-
buffer[i] = view[i];
|
|
31
|
-
}
|
|
32
|
-
return buffer;
|
|
31
|
+
return Buffer.from(binaryData);
|
|
33
32
|
}
|
|
34
33
|
|
|
35
|
-
|
|
34
|
+
throw new Error('toBuffer');
|
|
36
35
|
}
|
package/src/lib/node/fs.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// fs wrapper (promisified fs + avoids bundling fs in browsers)
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import {toArrayBuffer} from './buffer';
|
|
4
|
-
import {
|
|
4
|
+
import {promisify2, promisify3} from './util';
|
|
5
5
|
|
|
6
|
-
export type {Stats} from 'fs';
|
|
6
|
+
export type {Stats, WriteStream} from 'fs';
|
|
7
7
|
|
|
8
8
|
export let readdir;
|
|
9
9
|
/** Wrapper for Node.js fs method */
|
|
@@ -23,41 +23,46 @@ export let writeFileSync;
|
|
|
23
23
|
/** Wrapper for Node.js fs method */
|
|
24
24
|
export let open;
|
|
25
25
|
/** Wrapper for Node.js fs method */
|
|
26
|
-
export let close
|
|
26
|
+
export let close: (fd: number) => Promise<void>;
|
|
27
27
|
/** Wrapper for Node.js fs method */
|
|
28
28
|
export let read;
|
|
29
29
|
/** Wrapper for Node.js fs method */
|
|
30
30
|
export let fstat;
|
|
31
31
|
|
|
32
|
+
export let createWriteStream: typeof fs.createWriteStream;
|
|
33
|
+
|
|
32
34
|
export let isSupported = Boolean(fs);
|
|
33
35
|
|
|
34
36
|
// paths
|
|
35
37
|
|
|
36
38
|
try {
|
|
37
39
|
/** Wrapper for Node.js fs method */
|
|
38
|
-
readdir =
|
|
40
|
+
readdir = promisify2(fs.readdir);
|
|
39
41
|
/** Wrapper for Node.js fs method */
|
|
40
|
-
stat =
|
|
42
|
+
stat = promisify2(fs.stat);
|
|
41
43
|
|
|
42
44
|
/** Wrapper for Node.js fs method */
|
|
43
|
-
readFile =
|
|
45
|
+
readFile = fs.readFile;
|
|
44
46
|
/** Wrapper for Node.js fs method */
|
|
45
47
|
readFileSync = fs.readFileSync;
|
|
46
48
|
/** Wrapper for Node.js fs method */
|
|
47
|
-
writeFile =
|
|
49
|
+
writeFile = promisify3(fs.writeFile);
|
|
48
50
|
/** Wrapper for Node.js fs method */
|
|
49
51
|
writeFileSync = fs.writeFileSync;
|
|
50
52
|
|
|
51
53
|
// file descriptors
|
|
52
54
|
|
|
53
55
|
/** Wrapper for Node.js fs method */
|
|
54
|
-
open =
|
|
56
|
+
open = fs.open;
|
|
55
57
|
/** Wrapper for Node.js fs method */
|
|
56
|
-
close =
|
|
58
|
+
close = (fd: number) =>
|
|
59
|
+
new Promise((resolve, reject) => fs.close(fd, (err) => (err ? reject(err) : resolve())));
|
|
57
60
|
/** Wrapper for Node.js fs method */
|
|
58
|
-
read =
|
|
61
|
+
read = fs.read;
|
|
59
62
|
/** Wrapper for Node.js fs method */
|
|
60
|
-
fstat =
|
|
63
|
+
fstat = fs.fstat;
|
|
64
|
+
|
|
65
|
+
createWriteStream = fs.createWriteStream;
|
|
61
66
|
|
|
62
67
|
isSupported = Boolean(fs);
|
|
63
68
|
} catch {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// loaders.gl, MIT license
|
|
2
|
+
|
|
3
|
+
import stream from 'stream';
|
|
4
|
+
|
|
5
|
+
export type {Writable} from 'stream';
|
|
6
|
+
|
|
7
|
+
export let Transform;
|
|
8
|
+
|
|
9
|
+
export const isSupported = Boolean(stream);
|
|
10
|
+
|
|
11
|
+
// paths
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
/** Wrapper for Node.js fs method */
|
|
15
|
+
Transform = stream.Transform;
|
|
16
|
+
} catch {
|
|
17
|
+
// ignore
|
|
18
|
+
}
|
package/src/lib/node/util.ts
CHANGED
|
@@ -1,7 +1,42 @@
|
|
|
1
1
|
// @loaders.gl, MIT license
|
|
2
2
|
|
|
3
|
+
// type Parameter1<T extends (arg1: any, ...args: unknown[]) => unknown> = T extends (
|
|
4
|
+
// arg1: infer P,
|
|
5
|
+
// ...args: unknown[]
|
|
6
|
+
// ) => unknown
|
|
7
|
+
// ? P
|
|
8
|
+
// : never;
|
|
9
|
+
|
|
10
|
+
// type Parameter2<T extends (arg1: unknown, arg2: any, ...args: unknown[]) => unknown> = T extends (
|
|
11
|
+
// arg1: unknown,
|
|
12
|
+
// arg2: infer P,
|
|
13
|
+
// ...args: unknown[]
|
|
14
|
+
// ) => unknown
|
|
15
|
+
// ? P
|
|
16
|
+
// : never;
|
|
17
|
+
|
|
18
|
+
// type CallbackParameter2<
|
|
19
|
+
// T extends (arg: unknown, cb: (error: any, value: any) => void) => unknown
|
|
20
|
+
// > = T extends (arg: unknown, cb: (error: any, value: infer P) => void) => unknown ? P : never;
|
|
21
|
+
|
|
22
|
+
// type CallbackParameter3<
|
|
23
|
+
// T extends (arg: unknown, arg2: unknown, cb: (error: any, value: any) => void) => unknown
|
|
24
|
+
// > = T extends (arg: unknown, arg2: unknown, cb: (error: any, value: infer P) => void) => unknown
|
|
25
|
+
// ? P
|
|
26
|
+
// : never;
|
|
27
|
+
|
|
28
|
+
// /** Extract the parameters of a function type in a tuple */
|
|
29
|
+
// export type Promisified<F extends (arg1, cb: (error: unknown, value: any) => void) => any> = (
|
|
30
|
+
// arg1: Parameter1<F>
|
|
31
|
+
// ) => Promise<CallbackParameter2<F>>;
|
|
32
|
+
// /** Extract the parameters of a function type in a tuple */
|
|
33
|
+
// export type Promisified2<F extends (arg1, arg2, cb: (error: unknown, value: any) => void) => any> = (
|
|
34
|
+
// arg1: Parameter1<F>,
|
|
35
|
+
// arg2: Parameter2<F>
|
|
36
|
+
// ) => Promise<CallbackParameter3<F>>;
|
|
37
|
+
|
|
3
38
|
/** Wrapper for Node.js promisify */
|
|
4
|
-
type Callback<A> = (args: A) => void;
|
|
39
|
+
type Callback<A> = (error: unknown, args: A) => void;
|
|
5
40
|
|
|
6
41
|
/**
|
|
7
42
|
* Typesafe promisify implementation
|
|
@@ -11,20 +46,25 @@ type Callback<A> = (args: A) => void;
|
|
|
11
46
|
*/
|
|
12
47
|
export function promisify1<T, A>(fn: (args: T, cb: Callback<A>) => void): (args: T) => Promise<A> {
|
|
13
48
|
return (args: T) =>
|
|
14
|
-
new Promise((resolve) =>
|
|
15
|
-
fn(args, (callbackArgs) =>
|
|
16
|
-
|
|
17
|
-
});
|
|
18
|
-
});
|
|
49
|
+
new Promise((resolve, reject) =>
|
|
50
|
+
fn(args, (error, callbackArgs) => (error ? reject(error) : resolve(callbackArgs)))
|
|
51
|
+
);
|
|
19
52
|
}
|
|
20
53
|
|
|
21
54
|
export function promisify2<T1, T2, A>(
|
|
22
55
|
fn: (arg1: T1, arg2: T2, cb: Callback<A>) => void
|
|
23
56
|
): (arg1: T1, arg2: T2) => Promise<A> {
|
|
24
57
|
return (arg1: T1, arg2: T2) =>
|
|
25
|
-
new Promise((resolve) =>
|
|
26
|
-
fn(arg1, arg2, (callbackArgs) =>
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
58
|
+
new Promise((resolve, reject) =>
|
|
59
|
+
fn(arg1, arg2, (error, callbackArgs) => (error ? reject(error) : resolve(callbackArgs)))
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function promisify3<T1, T2, T3, A>(
|
|
64
|
+
fn: (arg1: T1, arg2: T2, arg3: T3, cb: Callback<A>) => void
|
|
65
|
+
): (arg1: T1, arg2: T2, arg3: T3) => Promise<A> {
|
|
66
|
+
return (arg1: T1, arg2: T2, arg3: T3) =>
|
|
67
|
+
new Promise((resolve, reject) =>
|
|
68
|
+
fn(arg1, arg2, arg3, (error, callbackArgs) => (error ? reject(error) : resolve(callbackArgs)))
|
|
69
|
+
);
|
|
30
70
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"binary-copy-utils.js","names":["copyPaddedArrayBufferToDataView","dataView","byteOffset","sourceBuffer","padding","paddedLength","padToNBytes","byteLength","padLength","targetArray","Uint8Array","buffer","sourceArray","set","i","setUint8","copyPaddedStringToDataView","string","textEncoder","TextEncoder","stringBuffer","encode"],"sources":["../../../../src/lib/binary-utils/binary-copy-utils.ts"],"sourcesContent":["import {TypedArray} from '../../types';\nimport {padToNBytes} from './memory-copy-utils';\n\n/**\n * Copy sourceBuffer to dataView with some padding\n *\n * @param {DataView | null} dataView - destination data container. If null - only new offset is calculated\n * @param {number} byteOffset - destination byte offset to copy to\n * @param {Array | TypedArray} sourceBuffer - source data buffer\n * @param {number} padding - pad the resulting array to multiple of \"padding\" bytes. Additional bytes are filled with 0x20 (ASCII space)\n *\n * @return new byteOffset of resulting dataView\n */\nexport function copyPaddedArrayBufferToDataView(\n dataView: DataView | null,\n byteOffset: number,\n sourceBuffer: TypedArray,\n padding: number\n) {\n const paddedLength = padToNBytes(sourceBuffer.byteLength, padding);\n const padLength = paddedLength - sourceBuffer.byteLength;\n\n if (dataView) {\n // Copy array\n const targetArray = new Uint8Array(\n dataView.buffer,\n dataView.byteOffset + byteOffset,\n sourceBuffer.byteLength\n );\n const sourceArray = new Uint8Array(sourceBuffer);\n targetArray.set(sourceArray);\n\n // Add PADDING\n for (let i = 0; i < padLength; ++i) {\n // json chunk is padded with spaces (ASCII 0x20)\n dataView.setUint8(byteOffset + sourceBuffer.byteLength + i, 0x20);\n }\n }\n byteOffset += paddedLength;\n return byteOffset;\n}\n\n/**\n * Copy string to dataView with some padding\n *\n * @param {DataView | null} dataView - destination data container. If null - only new offset is calculated\n * @param {number} byteOffset - destination byte offset to copy to\n * @param {string} string - source string\n * @param {number} padding - pad the resulting array to multiple of \"padding\" bytes. Additional bytes are filled with 0x20 (ASCII space)\n *\n * @return new byteOffset of resulting dataView\n */\nexport function copyPaddedStringToDataView(\n dataView: DataView | null,\n byteOffset: number,\n string: string,\n padding: number\n): number {\n const textEncoder = new TextEncoder();\n // PERFORMANCE IDEA: We encode twice, once to get size and once to store\n // PERFORMANCE IDEA: Use TextEncoder.encodeInto() to avoid temporary copy\n const stringBuffer = textEncoder.encode(string);\n\n byteOffset = copyPaddedArrayBufferToDataView(dataView, byteOffset, stringBuffer, padding);\n\n return byteOffset;\n}\n"],"mappings":";;;;;;;AACA;AAYO,SAASA,+BAA+B,CAC7CC,QAAyB,EACzBC,UAAkB,EAClBC,YAAwB,EACxBC,OAAe,EACf;EACA,IAAMC,YAAY,GAAG,IAAAC,4BAAW,EAACH,YAAY,CAACI,UAAU,EAAEH,OAAO,CAAC;EAClE,IAAMI,SAAS,GAAGH,YAAY,GAAGF,YAAY,CAACI,UAAU;EAExD,IAAIN,QAAQ,EAAE;IAEZ,IAAMQ,WAAW,GAAG,IAAIC,UAAU,CAChCT,QAAQ,CAACU,MAAM,EACfV,QAAQ,CAACC,UAAU,GAAGA,UAAU,EAChCC,YAAY,CAACI,UAAU,CACxB;IACD,IAAMK,WAAW,GAAG,IAAIF,UAAU,CAACP,YAAY,CAAC;IAChDM,WAAW,CAACI,GAAG,CAACD,WAAW,CAAC;;IAG5B,KAAK,IAAIE,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGN,SAAS,EAAE,EAAEM,CAAC,EAAE;MAElCb,QAAQ,CAACc,QAAQ,CAACb,UAAU,GAAGC,YAAY,CAACI,UAAU,GAAGO,CAAC,EAAE,IAAI,CAAC;IACnE;EACF;EACAZ,UAAU,IAAIG,YAAY;EAC1B,OAAOH,UAAU;AACnB;;AAYO,SAASc,0BAA0B,CACxCf,QAAyB,EACzBC,UAAkB,EAClBe,MAAc,EACdb,OAAe,EACP;EACR,IAAMc,WAAW,GAAG,IAAIC,WAAW,EAAE;EAGrC,IAAMC,YAAY,GAAGF,WAAW,CAACG,MAAM,CAACJ,MAAM,CAAC;EAE/Cf,UAAU,GAAGF,+BAA+B,CAACC,QAAQ,EAAEC,UAAU,EAAEkB,YAAY,EAAEhB,OAAO,CAAC;EAEzF,OAAOF,UAAU;AACnB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"buffer-utils.js","names":["isBuffer","value","toBuffer","data","node","bufferToArrayBuffer","buffer","typedArray","Uint8Array","byteOffset","length","slice"],"sources":["../../../../src/lib/binary-utils/buffer-utils.ts"],"sourcesContent":["import * as node from '../node/buffer';\n\n/**\n * Check for Node.js `Buffer` (without triggering bundler to include Buffer polyfill on browser)\n */\nexport function isBuffer(value: any): boolean {\n return value && typeof value === 'object' && value.isBuffer;\n}\n\n/**\n * Converts to Node.js `Buffer` (without triggering bundler to include Buffer polyfill on browser)\n * @todo better data type\n */\nexport function toBuffer(data: any): Buffer {\n return node.toBuffer ? node.toBuffer(data) : data;\n}\n\n/**\n * Converts Node.js `Buffer` to `ArrayBuffer` (without triggering bundler to include Buffer polyfill on browser)\n * @todo better data type\n */\nexport function bufferToArrayBuffer(buffer: any): ArrayBuffer {\n if (isBuffer(buffer)) {\n const typedArray = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.length);\n return typedArray.slice().buffer;\n }\n return buffer;\n}\n"],"mappings":";;;;;;;;;;;AAAA;AAAuC;AAAA;AAKhC,SAASA,QAAQ,CAACC,KAAU,EAAW;EAC5C,OAAOA,KAAK,IAAI,sBAAOA,KAAK,MAAK,QAAQ,IAAIA,KAAK,CAACD,QAAQ;AAC7D;;AAMO,SAASE,QAAQ,CAACC,IAAS,EAAU;EAC1C,OAAOC,IAAI,CAACF,QAAQ,GAAGE,IAAI,CAACF,QAAQ,CAACC,IAAI,CAAC,GAAGA,IAAI;AACnD;;AAMO,SAASE,mBAAmB,CAACC,MAAW,EAAe;EAC5D,IAAIN,QAAQ,CAACM,MAAM,CAAC,EAAE;IACpB,IAAMC,UAAU,GAAG,IAAIC,UAAU,CAACF,MAAM,CAACA,MAAM,EAAEA,MAAM,CAACG,UAAU,EAAEH,MAAM,CAACI,MAAM,CAAC;IAClF,OAAOH,UAAU,CAACI,KAAK,EAAE,CAACL,MAAM;EAClC;EACA,OAAOA,MAAM;AACf"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.copyBinaryToDataView = copyBinaryToDataView;
|
|
7
|
-
exports.copyStringToDataView = copyStringToDataView;
|
|
8
|
-
exports.padStringToByteAlignment = padStringToByteAlignment;
|
|
9
|
-
|
|
10
|
-
function padStringToByteAlignment(string, byteAlignment) {
|
|
11
|
-
var length = string.length;
|
|
12
|
-
var paddedLength = Math.ceil(length / byteAlignment) * byteAlignment;
|
|
13
|
-
var padding = paddedLength - length;
|
|
14
|
-
var whitespace = '';
|
|
15
|
-
for (var i = 0; i < padding; ++i) {
|
|
16
|
-
whitespace += ' ';
|
|
17
|
-
}
|
|
18
|
-
return string + whitespace;
|
|
19
|
-
}
|
|
20
|
-
function copyStringToDataView(dataView, byteOffset, string, byteLength) {
|
|
21
|
-
if (dataView) {
|
|
22
|
-
for (var i = 0; i < byteLength; i++) {
|
|
23
|
-
dataView.setUint8(byteOffset + i, string.charCodeAt(i));
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return byteOffset + byteLength;
|
|
27
|
-
}
|
|
28
|
-
function copyBinaryToDataView(dataView, byteOffset, binary, byteLength) {
|
|
29
|
-
if (dataView) {
|
|
30
|
-
for (var i = 0; i < byteLength; i++) {
|
|
31
|
-
dataView.setUint8(byteOffset + i, binary[i]);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return byteOffset + byteLength;
|
|
35
|
-
}
|
|
36
|
-
//# sourceMappingURL=encode-utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"encode-utils.js","names":["padStringToByteAlignment","string","byteAlignment","length","paddedLength","Math","ceil","padding","whitespace","i","copyStringToDataView","dataView","byteOffset","byteLength","setUint8","charCodeAt","copyBinaryToDataView","binary"],"sources":["../../../../src/lib/binary-utils/encode-utils.ts"],"sourcesContent":["// Note: These were broken out from gltf loader...\n// eslint-disable-next-line complexity\n\n// PERFORMANCE IDEA: No need to copy string twice...\nexport function padStringToByteAlignment(string, byteAlignment) {\n const length = string.length;\n const paddedLength = Math.ceil(length / byteAlignment) * byteAlignment; // Round up to the required alignment\n const padding = paddedLength - length;\n let whitespace = '';\n for (let i = 0; i < padding; ++i) {\n whitespace += ' ';\n }\n return string + whitespace;\n}\n\nexport function copyStringToDataView(dataView, byteOffset, string, byteLength) {\n if (dataView) {\n for (let i = 0; i < byteLength; i++) {\n dataView.setUint8(byteOffset + i, string.charCodeAt(i));\n }\n }\n return byteOffset + byteLength;\n}\n\nexport function copyBinaryToDataView(dataView, byteOffset, binary, byteLength) {\n if (dataView) {\n for (let i = 0; i < byteLength; i++) {\n dataView.setUint8(byteOffset + i, binary[i]);\n }\n }\n return byteOffset + byteLength;\n}\n"],"mappings":";;;;;;;;;AAIO,SAASA,wBAAwB,CAACC,MAAM,EAAEC,aAAa,EAAE;EAC9D,IAAMC,MAAM,GAAGF,MAAM,CAACE,MAAM;EAC5B,IAAMC,YAAY,GAAGC,IAAI,CAACC,IAAI,CAACH,MAAM,GAAGD,aAAa,CAAC,GAAGA,aAAa;EACtE,IAAMK,OAAO,GAAGH,YAAY,GAAGD,MAAM;EACrC,IAAIK,UAAU,GAAG,EAAE;EACnB,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGF,OAAO,EAAE,EAAEE,CAAC,EAAE;IAChCD,UAAU,IAAI,GAAG;EACnB;EACA,OAAOP,MAAM,GAAGO,UAAU;AAC5B;AAEO,SAASE,oBAAoB,CAACC,QAAQ,EAAEC,UAAU,EAAEX,MAAM,EAAEY,UAAU,EAAE;EAC7E,IAAIF,QAAQ,EAAE;IACZ,KAAK,IAAIF,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGI,UAAU,EAAEJ,CAAC,EAAE,EAAE;MACnCE,QAAQ,CAACG,QAAQ,CAACF,UAAU,GAAGH,CAAC,EAAER,MAAM,CAACc,UAAU,CAACN,CAAC,CAAC,CAAC;IACzD;EACF;EACA,OAAOG,UAAU,GAAGC,UAAU;AAChC;AAEO,SAASG,oBAAoB,CAACL,QAAQ,EAAEC,UAAU,EAAEK,MAAM,EAAEJ,UAAU,EAAE;EAC7E,IAAIF,QAAQ,EAAE;IACZ,KAAK,IAAIF,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGI,UAAU,EAAEJ,CAAC,EAAE,EAAE;MACnCE,QAAQ,CAACG,QAAQ,CAACF,UAAU,GAAGH,CAAC,EAAEQ,MAAM,CAACR,CAAC,CAAC,CAAC;IAC9C;EACF;EACA,OAAOG,UAAU,GAAGC,UAAU;AAChC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"binary-copy-utils.js","names":["padToNBytes","copyPaddedArrayBufferToDataView","dataView","byteOffset","sourceBuffer","padding","paddedLength","byteLength","padLength","targetArray","Uint8Array","buffer","sourceArray","set","i","setUint8","copyPaddedStringToDataView","string","textEncoder","TextEncoder","stringBuffer","encode"],"sources":["../../../../src/lib/binary-utils/binary-copy-utils.ts"],"sourcesContent":["import {TypedArray} from '../../types';\nimport {padToNBytes} from './memory-copy-utils';\n\n/**\n * Copy sourceBuffer to dataView with some padding\n *\n * @param {DataView | null} dataView - destination data container. If null - only new offset is calculated\n * @param {number} byteOffset - destination byte offset to copy to\n * @param {Array | TypedArray} sourceBuffer - source data buffer\n * @param {number} padding - pad the resulting array to multiple of \"padding\" bytes. Additional bytes are filled with 0x20 (ASCII space)\n *\n * @return new byteOffset of resulting dataView\n */\nexport function copyPaddedArrayBufferToDataView(\n dataView: DataView | null,\n byteOffset: number,\n sourceBuffer: TypedArray,\n padding: number\n) {\n const paddedLength = padToNBytes(sourceBuffer.byteLength, padding);\n const padLength = paddedLength - sourceBuffer.byteLength;\n\n if (dataView) {\n // Copy array\n const targetArray = new Uint8Array(\n dataView.buffer,\n dataView.byteOffset + byteOffset,\n sourceBuffer.byteLength\n );\n const sourceArray = new Uint8Array(sourceBuffer);\n targetArray.set(sourceArray);\n\n // Add PADDING\n for (let i = 0; i < padLength; ++i) {\n // json chunk is padded with spaces (ASCII 0x20)\n dataView.setUint8(byteOffset + sourceBuffer.byteLength + i, 0x20);\n }\n }\n byteOffset += paddedLength;\n return byteOffset;\n}\n\n/**\n * Copy string to dataView with some padding\n *\n * @param {DataView | null} dataView - destination data container. If null - only new offset is calculated\n * @param {number} byteOffset - destination byte offset to copy to\n * @param {string} string - source string\n * @param {number} padding - pad the resulting array to multiple of \"padding\" bytes. Additional bytes are filled with 0x20 (ASCII space)\n *\n * @return new byteOffset of resulting dataView\n */\nexport function copyPaddedStringToDataView(\n dataView: DataView | null,\n byteOffset: number,\n string: string,\n padding: number\n): number {\n const textEncoder = new TextEncoder();\n // PERFORMANCE IDEA: We encode twice, once to get size and once to store\n // PERFORMANCE IDEA: Use TextEncoder.encodeInto() to avoid temporary copy\n const stringBuffer = textEncoder.encode(string);\n\n byteOffset = copyPaddedArrayBufferToDataView(dataView, byteOffset, stringBuffer, padding);\n\n return byteOffset;\n}\n"],"mappings":"AACA,SAAQA,WAAW,QAAO,qBAAqB;;AAY/C,OAAO,SAASC,+BAA+B,CAC7CC,QAAyB,EACzBC,UAAkB,EAClBC,YAAwB,EACxBC,OAAe,EACf;EACA,MAAMC,YAAY,GAAGN,WAAW,CAACI,YAAY,CAACG,UAAU,EAAEF,OAAO,CAAC;EAClE,MAAMG,SAAS,GAAGF,YAAY,GAAGF,YAAY,CAACG,UAAU;EAExD,IAAIL,QAAQ,EAAE;IAEZ,MAAMO,WAAW,GAAG,IAAIC,UAAU,CAChCR,QAAQ,CAACS,MAAM,EACfT,QAAQ,CAACC,UAAU,GAAGA,UAAU,EAChCC,YAAY,CAACG,UAAU,CACxB;IACD,MAAMK,WAAW,GAAG,IAAIF,UAAU,CAACN,YAAY,CAAC;IAChDK,WAAW,CAACI,GAAG,CAACD,WAAW,CAAC;;IAG5B,KAAK,IAAIE,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGN,SAAS,EAAE,EAAEM,CAAC,EAAE;MAElCZ,QAAQ,CAACa,QAAQ,CAACZ,UAAU,GAAGC,YAAY,CAACG,UAAU,GAAGO,CAAC,EAAE,IAAI,CAAC;IACnE;EACF;EACAX,UAAU,IAAIG,YAAY;EAC1B,OAAOH,UAAU;AACnB;;AAYA,OAAO,SAASa,0BAA0B,CACxCd,QAAyB,EACzBC,UAAkB,EAClBc,MAAc,EACdZ,OAAe,EACP;EACR,MAAMa,WAAW,GAAG,IAAIC,WAAW,EAAE;EAGrC,MAAMC,YAAY,GAAGF,WAAW,CAACG,MAAM,CAACJ,MAAM,CAAC;EAE/Cd,UAAU,GAAGF,+BAA+B,CAACC,QAAQ,EAAEC,UAAU,EAAEiB,YAAY,EAAEf,OAAO,CAAC;EAEzF,OAAOF,UAAU;AACnB"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import * as node from '../node/buffer';
|
|
2
|
-
|
|
3
|
-
export function isBuffer(value) {
|
|
4
|
-
return value && typeof value === 'object' && value.isBuffer;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export function toBuffer(data) {
|
|
8
|
-
return node.toBuffer ? node.toBuffer(data) : data;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function bufferToArrayBuffer(buffer) {
|
|
12
|
-
if (isBuffer(buffer)) {
|
|
13
|
-
const typedArray = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.length);
|
|
14
|
-
return typedArray.slice().buffer;
|
|
15
|
-
}
|
|
16
|
-
return buffer;
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=buffer-utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"buffer-utils.js","names":["node","isBuffer","value","toBuffer","data","bufferToArrayBuffer","buffer","typedArray","Uint8Array","byteOffset","length","slice"],"sources":["../../../../src/lib/binary-utils/buffer-utils.ts"],"sourcesContent":["import * as node from '../node/buffer';\n\n/**\n * Check for Node.js `Buffer` (without triggering bundler to include Buffer polyfill on browser)\n */\nexport function isBuffer(value: any): boolean {\n return value && typeof value === 'object' && value.isBuffer;\n}\n\n/**\n * Converts to Node.js `Buffer` (without triggering bundler to include Buffer polyfill on browser)\n * @todo better data type\n */\nexport function toBuffer(data: any): Buffer {\n return node.toBuffer ? node.toBuffer(data) : data;\n}\n\n/**\n * Converts Node.js `Buffer` to `ArrayBuffer` (without triggering bundler to include Buffer polyfill on browser)\n * @todo better data type\n */\nexport function bufferToArrayBuffer(buffer: any): ArrayBuffer {\n if (isBuffer(buffer)) {\n const typedArray = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.length);\n return typedArray.slice().buffer;\n }\n return buffer;\n}\n"],"mappings":"AAAA,OAAO,KAAKA,IAAI,MAAM,gBAAgB;;AAKtC,OAAO,SAASC,QAAQ,CAACC,KAAU,EAAW;EAC5C,OAAOA,KAAK,IAAI,OAAOA,KAAK,KAAK,QAAQ,IAAIA,KAAK,CAACD,QAAQ;AAC7D;;AAMA,OAAO,SAASE,QAAQ,CAACC,IAAS,EAAU;EAC1C,OAAOJ,IAAI,CAACG,QAAQ,GAAGH,IAAI,CAACG,QAAQ,CAACC,IAAI,CAAC,GAAGA,IAAI;AACnD;;AAMA,OAAO,SAASC,mBAAmB,CAACC,MAAW,EAAe;EAC5D,IAAIL,QAAQ,CAACK,MAAM,CAAC,EAAE;IACpB,MAAMC,UAAU,GAAG,IAAIC,UAAU,CAACF,MAAM,CAACA,MAAM,EAAEA,MAAM,CAACG,UAAU,EAAEH,MAAM,CAACI,MAAM,CAAC;IAClF,OAAOH,UAAU,CAACI,KAAK,EAAE,CAACL,MAAM;EAClC;EACA,OAAOA,MAAM;AACf"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export function padStringToByteAlignment(string, byteAlignment) {
|
|
4
|
-
const length = string.length;
|
|
5
|
-
const paddedLength = Math.ceil(length / byteAlignment) * byteAlignment;
|
|
6
|
-
const padding = paddedLength - length;
|
|
7
|
-
let whitespace = '';
|
|
8
|
-
for (let i = 0; i < padding; ++i) {
|
|
9
|
-
whitespace += ' ';
|
|
10
|
-
}
|
|
11
|
-
return string + whitespace;
|
|
12
|
-
}
|
|
13
|
-
export function copyStringToDataView(dataView, byteOffset, string, byteLength) {
|
|
14
|
-
if (dataView) {
|
|
15
|
-
for (let i = 0; i < byteLength; i++) {
|
|
16
|
-
dataView.setUint8(byteOffset + i, string.charCodeAt(i));
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return byteOffset + byteLength;
|
|
20
|
-
}
|
|
21
|
-
export function copyBinaryToDataView(dataView, byteOffset, binary, byteLength) {
|
|
22
|
-
if (dataView) {
|
|
23
|
-
for (let i = 0; i < byteLength; i++) {
|
|
24
|
-
dataView.setUint8(byteOffset + i, binary[i]);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return byteOffset + byteLength;
|
|
28
|
-
}
|
|
29
|
-
//# sourceMappingURL=encode-utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"encode-utils.js","names":["padStringToByteAlignment","string","byteAlignment","length","paddedLength","Math","ceil","padding","whitespace","i","copyStringToDataView","dataView","byteOffset","byteLength","setUint8","charCodeAt","copyBinaryToDataView","binary"],"sources":["../../../../src/lib/binary-utils/encode-utils.ts"],"sourcesContent":["// Note: These were broken out from gltf loader...\n// eslint-disable-next-line complexity\n\n// PERFORMANCE IDEA: No need to copy string twice...\nexport function padStringToByteAlignment(string, byteAlignment) {\n const length = string.length;\n const paddedLength = Math.ceil(length / byteAlignment) * byteAlignment; // Round up to the required alignment\n const padding = paddedLength - length;\n let whitespace = '';\n for (let i = 0; i < padding; ++i) {\n whitespace += ' ';\n }\n return string + whitespace;\n}\n\nexport function copyStringToDataView(dataView, byteOffset, string, byteLength) {\n if (dataView) {\n for (let i = 0; i < byteLength; i++) {\n dataView.setUint8(byteOffset + i, string.charCodeAt(i));\n }\n }\n return byteOffset + byteLength;\n}\n\nexport function copyBinaryToDataView(dataView, byteOffset, binary, byteLength) {\n if (dataView) {\n for (let i = 0; i < byteLength; i++) {\n dataView.setUint8(byteOffset + i, binary[i]);\n }\n }\n return byteOffset + byteLength;\n}\n"],"mappings":";;AAIA,OAAO,SAASA,wBAAwB,CAACC,MAAM,EAAEC,aAAa,EAAE;EAC9D,MAAMC,MAAM,GAAGF,MAAM,CAACE,MAAM;EAC5B,MAAMC,YAAY,GAAGC,IAAI,CAACC,IAAI,CAACH,MAAM,GAAGD,aAAa,CAAC,GAAGA,aAAa;EACtE,MAAMK,OAAO,GAAGH,YAAY,GAAGD,MAAM;EACrC,IAAIK,UAAU,GAAG,EAAE;EACnB,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGF,OAAO,EAAE,EAAEE,CAAC,EAAE;IAChCD,UAAU,IAAI,GAAG;EACnB;EACA,OAAOP,MAAM,GAAGO,UAAU;AAC5B;AAEA,OAAO,SAASE,oBAAoB,CAACC,QAAQ,EAAEC,UAAU,EAAEX,MAAM,EAAEY,UAAU,EAAE;EAC7E,IAAIF,QAAQ,EAAE;IACZ,KAAK,IAAIF,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGI,UAAU,EAAEJ,CAAC,EAAE,EAAE;MACnCE,QAAQ,CAACG,QAAQ,CAACF,UAAU,GAAGH,CAAC,EAAER,MAAM,CAACc,UAAU,CAACN,CAAC,CAAC,CAAC;IACzD;EACF;EACA,OAAOG,UAAU,GAAGC,UAAU;AAChC;AAEA,OAAO,SAASG,oBAAoB,CAACL,QAAQ,EAAEC,UAAU,EAAEK,MAAM,EAAEJ,UAAU,EAAE;EAC7E,IAAIF,QAAQ,EAAE;IACZ,KAAK,IAAIF,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGI,UAAU,EAAEJ,CAAC,EAAE,EAAE;MACnCE,QAAQ,CAACG,QAAQ,CAACF,UAAU,GAAGH,CAAC,EAAEQ,MAAM,CAACR,CAAC,CAAC,CAAC;IAC9C;EACF;EACA,OAAOG,UAAU,GAAGC,UAAU;AAChC"}
|
|
@@ -1,24 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
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,4 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,35 +0,0 @@
|
|
|
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;
|
|
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
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return byteOffset + byteLength;
|
|
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
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return byteOffset + byteLength;
|
|
34
|
-
}
|
|
35
|
-
exports.copyBinaryToDataView = copyBinaryToDataView;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import * as node from '../node/buffer';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Check for Node.js `Buffer` (without triggering bundler to include Buffer polyfill on browser)
|
|
5
|
-
*/
|
|
6
|
-
export function isBuffer(value: any): boolean {
|
|
7
|
-
return value && typeof value === 'object' && value.isBuffer;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Converts to Node.js `Buffer` (without triggering bundler to include Buffer polyfill on browser)
|
|
12
|
-
* @todo better data type
|
|
13
|
-
*/
|
|
14
|
-
export function toBuffer(data: any): Buffer {
|
|
15
|
-
return node.toBuffer ? node.toBuffer(data) : data;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Converts Node.js `Buffer` to `ArrayBuffer` (without triggering bundler to include Buffer polyfill on browser)
|
|
20
|
-
* @todo better data type
|
|
21
|
-
*/
|
|
22
|
-
export function bufferToArrayBuffer(buffer: any): ArrayBuffer {
|
|
23
|
-
if (isBuffer(buffer)) {
|
|
24
|
-
const typedArray = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.length);
|
|
25
|
-
return typedArray.slice().buffer;
|
|
26
|
-
}
|
|
27
|
-
return buffer;
|
|
28
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
// Note: These were broken out from gltf loader...
|
|
2
|
-
// eslint-disable-next-line complexity
|
|
3
|
-
|
|
4
|
-
// PERFORMANCE IDEA: No need to copy string twice...
|
|
5
|
-
export function padStringToByteAlignment(string, byteAlignment) {
|
|
6
|
-
const length = string.length;
|
|
7
|
-
const paddedLength = Math.ceil(length / byteAlignment) * byteAlignment; // Round up to the required alignment
|
|
8
|
-
const padding = paddedLength - length;
|
|
9
|
-
let whitespace = '';
|
|
10
|
-
for (let i = 0; i < padding; ++i) {
|
|
11
|
-
whitespace += ' ';
|
|
12
|
-
}
|
|
13
|
-
return string + whitespace;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function copyStringToDataView(dataView, byteOffset, string, byteLength) {
|
|
17
|
-
if (dataView) {
|
|
18
|
-
for (let i = 0; i < byteLength; i++) {
|
|
19
|
-
dataView.setUint8(byteOffset + i, string.charCodeAt(i));
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return byteOffset + byteLength;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function copyBinaryToDataView(dataView, byteOffset, binary, byteLength) {
|
|
26
|
-
if (dataView) {
|
|
27
|
-
for (let i = 0; i < byteLength; i++) {
|
|
28
|
-
dataView.setUint8(byteOffset + i, binary[i]);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return byteOffset + byteLength;
|
|
32
|
-
}
|