@loaders.gl/loader-utils 4.0.0-alpha.5 → 4.0.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/es5/index.js +328 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/json-loader.js +44 -0
- package/dist/es5/json-loader.js.map +1 -0
- package/dist/es5/lib/binary-utils/array-buffer-utils.js +80 -0
- package/dist/es5/lib/binary-utils/array-buffer-utils.js.map +1 -0
- package/dist/es5/lib/binary-utils/dataview-copy-utils.js +58 -0
- package/dist/es5/lib/binary-utils/dataview-copy-utils.js.map +1 -0
- package/dist/es5/lib/binary-utils/get-first-characters.js +31 -0
- package/dist/es5/lib/binary-utils/get-first-characters.js.map +1 -0
- package/dist/es5/lib/binary-utils/memory-conversion-utils.js +44 -0
- package/dist/es5/lib/binary-utils/memory-conversion-utils.js.map +1 -0
- package/dist/es5/lib/binary-utils/memory-copy-utils.js +34 -0
- package/dist/es5/lib/binary-utils/memory-copy-utils.js.map +1 -0
- package/dist/es5/lib/env-utils/assert.js +12 -0
- package/dist/es5/lib/env-utils/assert.js.map +1 -0
- package/dist/es5/lib/env-utils/globals.js +30 -0
- package/dist/es5/lib/env-utils/globals.js.map +1 -0
- package/dist/es5/lib/filesystems/node-filesystem.js +210 -0
- package/dist/es5/lib/filesystems/node-filesystem.js.map +1 -0
- package/dist/es5/lib/filesystems/readable-file.js +91 -0
- package/dist/es5/lib/filesystems/readable-file.js.map +1 -0
- package/dist/es5/lib/filesystems/writable-file.js +82 -0
- package/dist/es5/lib/filesystems/writable-file.js.map +1 -0
- package/dist/es5/lib/iterators/async-iteration.js +190 -0
- package/dist/es5/lib/iterators/async-iteration.js.map +1 -0
- package/dist/es5/lib/iterators/text-iterators.js +305 -0
- package/dist/es5/lib/iterators/text-iterators.js.map +1 -0
- package/dist/es5/lib/node/buffer.browser.js +14 -0
- package/dist/es5/lib/node/buffer.browser.js.map +1 -0
- package/dist/es5/lib/node/buffer.js +27 -0
- package/dist/es5/lib/node/buffer.js.map +1 -0
- package/dist/es5/lib/node/fs.js +88 -0
- package/dist/es5/lib/node/fs.js.map +1 -0
- package/dist/es5/lib/node/promisify.js +36 -0
- package/dist/es5/lib/node/promisify.js.map +1 -0
- package/dist/es5/lib/node/stream.js +16 -0
- package/dist/es5/lib/node/stream.js.map +1 -0
- package/dist/es5/lib/option-utils/merge-loader-options.js +30 -0
- package/dist/es5/lib/option-utils/merge-loader-options.js.map +1 -0
- package/dist/es5/lib/parser-utils/parse-json.js +15 -0
- package/dist/es5/lib/parser-utils/parse-json.js.map +1 -0
- package/dist/es5/lib/path-utils/file-aliases.js +33 -0
- package/dist/es5/lib/path-utils/file-aliases.js.map +1 -0
- package/dist/es5/lib/path-utils/get-cwd.js +15 -0
- package/dist/es5/lib/path-utils/get-cwd.js.map +1 -0
- package/dist/es5/lib/path-utils/path.js +136 -0
- package/dist/es5/lib/path-utils/path.js.map +1 -0
- package/dist/es5/lib/request-utils/request-scheduler.js +150 -0
- package/dist/es5/lib/request-utils/request-scheduler.js.map +1 -0
- package/dist/es5/lib/worker-loader-utils/create-loader-worker.js +142 -0
- package/dist/es5/lib/worker-loader-utils/create-loader-worker.js.map +1 -0
- package/dist/es5/lib/worker-loader-utils/encode-with-worker.js +18 -0
- package/dist/es5/lib/worker-loader-utils/encode-with-worker.js.map +1 -0
- package/dist/es5/lib/worker-loader-utils/parse-with-worker.js +115 -0
- package/dist/es5/lib/worker-loader-utils/parse-with-worker.js.map +1 -0
- package/dist/es5/types.js +2 -0
- package/dist/es5/types.js.map +1 -0
- package/dist/es5/workers/json-worker.js +6 -0
- package/dist/es5/workers/json-worker.js.map +1 -0
- package/dist/esm/index.js +29 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/json-loader.js +18 -0
- package/dist/esm/json-loader.js.map +1 -0
- package/dist/esm/lib/binary-utils/array-buffer-utils.js +52 -0
- package/dist/esm/lib/binary-utils/array-buffer-utils.js.map +1 -0
- package/dist/{lib/binary-utils/binary-copy-utils.js → esm/lib/binary-utils/dataview-copy-utils.js} +27 -4
- package/dist/esm/lib/binary-utils/dataview-copy-utils.js.map +1 -0
- package/dist/esm/lib/binary-utils/get-first-characters.js +24 -0
- package/dist/esm/lib/binary-utils/get-first-characters.js.map +1 -0
- package/dist/esm/lib/binary-utils/memory-conversion-utils.js +31 -0
- package/dist/esm/lib/binary-utils/memory-conversion-utils.js.map +1 -0
- package/dist/esm/lib/binary-utils/memory-copy-utils.js +26 -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 +53 -0
- package/dist/esm/lib/filesystems/node-filesystem.js.map +1 -0
- package/dist/esm/lib/filesystems/readable-file.js +20 -0
- package/dist/esm/lib/filesystems/readable-file.js.map +1 -0
- package/dist/esm/lib/filesystems/writable-file.js +20 -0
- package/dist/esm/lib/filesystems/writable-file.js.map +1 -0
- package/dist/esm/lib/iterators/async-iteration.js +32 -0
- package/dist/esm/lib/iterators/async-iteration.js.map +1 -0
- package/dist/esm/lib/iterators/text-iterators.js +47 -0
- package/dist/esm/lib/iterators/text-iterators.js.map +1 -0
- package/dist/esm/lib/node/buffer.browser.js +7 -0
- package/dist/esm/lib/node/buffer.browser.js.map +1 -0
- package/dist/esm/lib/node/buffer.js +20 -0
- package/dist/esm/lib/node/buffer.js.map +1 -0
- package/dist/esm/lib/node/fs.js +40 -0
- package/dist/esm/lib/node/fs.js.map +1 -0
- package/dist/esm/lib/node/promisify.js +10 -0
- package/dist/esm/lib/node/promisify.js.map +1 -0
- package/dist/esm/lib/node/stream.js +7 -0
- package/dist/esm/lib/node/stream.js.map +1 -0
- package/dist/esm/lib/option-utils/merge-loader-options.js +17 -0
- package/dist/esm/lib/option-utils/merge-loader-options.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 +24 -0
- package/dist/esm/lib/path-utils/file-aliases.js.map +1 -0
- package/dist/esm/lib/path-utils/get-cwd.js +9 -0
- package/dist/esm/lib/path-utils/get-cwd.js.map +1 -0
- package/dist/esm/lib/path-utils/path.js +127 -0
- package/dist/esm/lib/path-utils/path.js.map +1 -0
- package/dist/esm/lib/request-utils/request-scheduler.js +120 -0
- package/dist/esm/lib/request-utils/request-scheduler.js.map +1 -0
- package/dist/esm/lib/worker-loader-utils/create-loader-worker.js +95 -0
- package/dist/esm/lib/worker-loader-utils/create-loader-worker.js.map +1 -0
- package/dist/esm/lib/worker-loader-utils/encode-with-worker.js +12 -0
- package/dist/esm/lib/worker-loader-utils/encode-with-worker.js.map +1 -0
- package/dist/esm/lib/worker-loader-utils/parse-with-worker.js +63 -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 +13 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +122 -26
- package/dist/json-loader.d.ts +4 -17
- package/dist/json-loader.d.ts.map +1 -1
- package/dist/json-loader.js +24 -18
- 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 +78 -80
- 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/dataview-copy-utils.js +97 -0
- 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 +43 -25
- 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/memory-conversion-utils.js +73 -0
- package/dist/lib/binary-utils/memory-copy-utils.js +58 -24
- package/dist/lib/env-utils/assert.js +12 -5
- package/dist/lib/env-utils/globals.d.ts +1 -1
- package/dist/lib/env-utils/globals.d.ts.map +1 -1
- package/dist/lib/env-utils/globals.js +23 -9
- package/dist/lib/filesystems/node-filesystem.d.ts +3 -2
- package/dist/lib/filesystems/node-filesystem.d.ts.map +1 -1
- package/dist/lib/filesystems/node-filesystem.js +72 -59
- 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/iterators/async-iteration.js +49 -35
- package/dist/lib/iterators/text-iterators.js +56 -41
- package/dist/lib/node/buffer.browser.d.ts +12 -0
- package/dist/lib/node/buffer.browser.d.ts.map +1 -0
- package/dist/lib/node/buffer.browser.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 +33 -25
- 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 +47 -40
- package/dist/lib/node/promisify.d.ts +13 -0
- package/dist/lib/node/promisify.d.ts.map +1 -0
- package/dist/lib/node/promisify.js +22 -0
- 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/option-utils/merge-loader-options.d.ts +9 -0
- package/dist/lib/option-utils/merge-loader-options.d.ts.map +1 -0
- package/dist/lib/option-utils/merge-loader-options.js +27 -0
- package/dist/lib/parser-utils/parse-json.js +15 -8
- package/dist/lib/path-utils/file-aliases.js +40 -19
- package/dist/lib/path-utils/get-cwd.d.ts +2 -0
- package/dist/lib/path-utils/get-cwd.d.ts.map +1 -0
- package/dist/lib/path-utils/get-cwd.js +12 -0
- package/dist/lib/path-utils/path.d.ts +8 -0
- package/dist/lib/path-utils/path.d.ts.map +1 -1
- package/dist/lib/path-utils/path.js +173 -19
- package/dist/lib/request-utils/request-scheduler.d.ts +6 -6
- package/dist/lib/request-utils/request-scheduler.d.ts.map +1 -1
- package/dist/lib/request-utils/request-scheduler.js +127 -131
- package/dist/lib/worker-loader-utils/create-loader-worker.d.ts.map +1 -1
- package/dist/lib/worker-loader-utils/create-loader-worker.js +92 -96
- package/dist/lib/worker-loader-utils/encode-with-worker.d.ts +8 -0
- package/dist/lib/worker-loader-utils/encode-with-worker.d.ts.map +1 -0
- package/dist/lib/worker-loader-utils/encode-with-worker.js +21 -0
- package/dist/lib/worker-loader-utils/parse-with-worker.d.ts.map +1 -1
- package/dist/lib/worker-loader-utils/parse-with-worker.js +77 -60
- package/dist/types.d.ts +85 -72
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +3 -2
- package/dist/workers/json-worker.js +5 -4
- package/package.json +12 -19
- package/src/index.ts +32 -18
- package/src/json-loader.ts +5 -4
- 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/node/buffer.browser.ts +20 -0
- package/src/lib/node/buffer.ts +12 -11
- package/src/lib/node/fs.ts +16 -11
- package/src/lib/node/promisify.ts +70 -0
- package/src/lib/node/stream.ts +18 -0
- package/src/lib/option-utils/merge-loader-options.ts +35 -0
- package/src/lib/path-utils/get-cwd.ts +9 -0
- package/src/lib/path-utils/path.ts +138 -4
- package/src/lib/worker-loader-utils/create-loader-worker.ts +3 -2
- package/src/lib/worker-loader-utils/encode-with-worker.ts +21 -0
- package/src/lib/worker-loader-utils/parse-with-worker.ts +15 -2
- package/src/types.ts +156 -93
- 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.d.ts +0 -24
- package/dist/lib/binary-utils/binary-copy-utils.d.ts.map +0 -1
- package/dist/lib/binary-utils/binary-copy-utils.js.map +0 -1
- package/dist/lib/binary-utils/buffer-utils.d.ts.map +0 -1
- package/dist/lib/binary-utils/buffer-utils.js +0 -16
- package/dist/lib/binary-utils/buffer-utils.js.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 -31
- 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/filesystems/node-filesystem.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.js.map +0 -1
- package/dist/lib/node/fs.js.map +0 -1
- package/dist/lib/node/util.d.ts +0 -5
- package/dist/lib/node/util.d.ts.map +0 -1
- package/dist/lib/node/util.js +0 -3
- package/dist/lib/node/util.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/types.js.map +0 -1
- package/dist/workers/json-worker.js.map +0 -1
- package/src/lib/binary-utils/buffer-utils.ts +0 -28
- package/src/lib/binary-utils/encode-utils.ts +0 -32
- package/src/lib/node/util.ts +0 -4
|
@@ -1,102 +1,98 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createLoaderWorker = void 0;
|
|
4
|
+
const worker_utils_1 = require("@loaders.gl/worker-utils");
|
|
5
|
+
// import {validateLoaderVersion} from './validate-loader-version.js';
|
|
2
6
|
let requestId = 0;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
try {
|
|
12
|
-
const {
|
|
13
|
-
input,
|
|
14
|
-
options = {}
|
|
15
|
-
} = payload;
|
|
16
|
-
const result = await parseData({
|
|
17
|
-
loader,
|
|
18
|
-
arrayBuffer: input,
|
|
19
|
-
options,
|
|
20
|
-
context: {
|
|
21
|
-
parse: parseOnMainThread
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
WorkerBody.postMessage('done', {
|
|
25
|
-
result
|
|
26
|
-
});
|
|
27
|
-
} catch (error) {
|
|
28
|
-
const message = error instanceof Error ? error.message : '';
|
|
29
|
-
WorkerBody.postMessage('error', {
|
|
30
|
-
error: message
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
break;
|
|
35
|
-
|
|
36
|
-
default:
|
|
7
|
+
/**
|
|
8
|
+
* Set up a WebWorkerGlobalScope to talk with the main thread
|
|
9
|
+
* @param loader
|
|
10
|
+
*/
|
|
11
|
+
function createLoaderWorker(loader) {
|
|
12
|
+
// Check that we are actually in a worker thread
|
|
13
|
+
if (!worker_utils_1.WorkerBody.inWorkerThread()) {
|
|
14
|
+
return;
|
|
37
15
|
}
|
|
38
|
-
|
|
16
|
+
worker_utils_1.WorkerBody.onmessage = async (type, payload) => {
|
|
17
|
+
switch (type) {
|
|
18
|
+
case 'process':
|
|
19
|
+
try {
|
|
20
|
+
// validateLoaderVersion(loader, data.source.split('@')[1]);
|
|
21
|
+
const { input, options = {}, context = {} } = payload;
|
|
22
|
+
const result = await parseData({
|
|
23
|
+
loader,
|
|
24
|
+
arrayBuffer: input,
|
|
25
|
+
options,
|
|
26
|
+
context: {
|
|
27
|
+
...context,
|
|
28
|
+
parse: parseOnMainThread
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
worker_utils_1.WorkerBody.postMessage('done', { result });
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
const message = error instanceof Error ? error.message : '';
|
|
35
|
+
worker_utils_1.WorkerBody.postMessage('error', { error: message });
|
|
36
|
+
}
|
|
37
|
+
break;
|
|
38
|
+
default:
|
|
39
|
+
}
|
|
40
|
+
};
|
|
39
41
|
}
|
|
40
|
-
|
|
42
|
+
exports.createLoaderWorker = createLoaderWorker;
|
|
41
43
|
function parseOnMainThread(arrayBuffer, options) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
options
|
|
70
|
-
};
|
|
71
|
-
WorkerBody.postMessage('process', payload);
|
|
72
|
-
});
|
|
44
|
+
return new Promise((resolve, reject) => {
|
|
45
|
+
const id = requestId++;
|
|
46
|
+
/**
|
|
47
|
+
*/
|
|
48
|
+
const onMessage = (type, payload) => {
|
|
49
|
+
if (payload.id !== id) {
|
|
50
|
+
// not ours
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
switch (type) {
|
|
54
|
+
case 'done':
|
|
55
|
+
worker_utils_1.WorkerBody.removeEventListener(onMessage);
|
|
56
|
+
resolve(payload.result);
|
|
57
|
+
break;
|
|
58
|
+
case 'error':
|
|
59
|
+
worker_utils_1.WorkerBody.removeEventListener(onMessage);
|
|
60
|
+
reject(payload.error);
|
|
61
|
+
break;
|
|
62
|
+
default:
|
|
63
|
+
// ignore
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
worker_utils_1.WorkerBody.addEventListener(onMessage);
|
|
67
|
+
// Ask the main thread to decode data
|
|
68
|
+
const payload = { id, input: arrayBuffer, options };
|
|
69
|
+
worker_utils_1.WorkerBody.postMessage('process', payload);
|
|
70
|
+
});
|
|
73
71
|
}
|
|
74
|
-
|
|
75
|
-
async
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}, context, loader);
|
|
72
|
+
// TODO - Support byteOffset and byteLength (enabling parsing of embedded binaries without copies)
|
|
73
|
+
// TODO - Why not support async loader.parse* funcs here?
|
|
74
|
+
// TODO - Why not reuse a common function instead of reimplementing loader.parse* selection logic? Keeping loader small?
|
|
75
|
+
// TODO - Lack of appropriate parser functions can be detected when we create worker, no need to wait until parse
|
|
76
|
+
async function parseData({ loader, arrayBuffer, options, context }) {
|
|
77
|
+
let data;
|
|
78
|
+
let parser;
|
|
79
|
+
if (loader.parseSync || loader.parse) {
|
|
80
|
+
data = arrayBuffer;
|
|
81
|
+
parser = loader.parseSync || loader.parse;
|
|
82
|
+
}
|
|
83
|
+
else if (loader.parseTextSync) {
|
|
84
|
+
const textDecoder = new TextDecoder();
|
|
85
|
+
data = textDecoder.decode(arrayBuffer);
|
|
86
|
+
parser = loader.parseTextSync;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
throw new Error(`Could not load data with ${loader.name} loader`);
|
|
90
|
+
}
|
|
91
|
+
// TODO - proper merge in of loader options...
|
|
92
|
+
options = {
|
|
93
|
+
...options,
|
|
94
|
+
modules: (loader && loader.options && loader.options.modules) || {},
|
|
95
|
+
worker: false
|
|
96
|
+
};
|
|
97
|
+
return await parser(data, { ...options }, context, loader);
|
|
101
98
|
}
|
|
102
|
-
//# sourceMappingURL=create-loader-worker.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Writer, WriterOptions } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Determines if a loader can parse with worker
|
|
4
|
+
* @param loader
|
|
5
|
+
* @param options
|
|
6
|
+
*/
|
|
7
|
+
export declare function canEncodeWithWorker(writer: Writer, options?: WriterOptions): any;
|
|
8
|
+
//# sourceMappingURL=encode-with-worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encode-with-worker.d.ts","sourceRoot":"","sources":["../../../src/lib/worker-loader-utils/encode-with-worker.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAE,aAAa,EAAC,MAAM,aAAa,CAAC;AAGlD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,OAW1E"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.canEncodeWithWorker = void 0;
|
|
4
|
+
const worker_utils_1 = require("@loaders.gl/worker-utils");
|
|
5
|
+
const globals_1 = require("../env-utils/globals");
|
|
6
|
+
/**
|
|
7
|
+
* Determines if a loader can parse with worker
|
|
8
|
+
* @param loader
|
|
9
|
+
* @param options
|
|
10
|
+
*/
|
|
11
|
+
function canEncodeWithWorker(writer, options) {
|
|
12
|
+
if (!worker_utils_1.WorkerFarm.isSupported()) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
// Node workers are still experimental
|
|
16
|
+
if (!globals_1.isBrowser && !options?._nodeWorkers) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
return writer.worker && options?.worker;
|
|
20
|
+
}
|
|
21
|
+
exports.canEncodeWithWorker = canEncodeWithWorker;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-with-worker.d.ts","sourceRoot":"","sources":["../../../src/lib/worker-loader-utils/parse-with-worker.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parse-with-worker.d.ts","sourceRoot":"","sources":["../../../src/lib/worker-loader-utils/parse-with-worker.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAC,MAAM,EAAE,aAAa,EAAE,aAAa,EAAC,MAAM,aAAa,CAAC;AAGtE;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,4BAWzE;AAED;;;GAGG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,GAAG,EACT,OAAO,CAAC,EAAE,aAAa,EACvB,OAAO,CAAC,EAAE,aAAa,EACvB,iBAAiB,CAAC,EAAE,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,gBA8B/F"}
|
|
@@ -1,64 +1,81 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseWithWorker = exports.canParseWithWorker = void 0;
|
|
4
|
+
const worker_utils_1 = require("@loaders.gl/worker-utils");
|
|
5
|
+
const worker_utils_2 = require("@loaders.gl/worker-utils");
|
|
6
|
+
/**
|
|
7
|
+
* Determines if a loader can parse with worker
|
|
8
|
+
* @param loader
|
|
9
|
+
* @param options
|
|
10
|
+
*/
|
|
11
|
+
function canParseWithWorker(loader, options) {
|
|
12
|
+
if (!worker_utils_2.WorkerFarm.isSupported()) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
// Node workers are still experimental
|
|
16
|
+
if (!worker_utils_1.isBrowser && !options?._nodeWorkers) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
return loader.worker && options?.worker;
|
|
8
20
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
exports.canParseWithWorker = canParseWithWorker;
|
|
22
|
+
/**
|
|
23
|
+
* this function expects that the worker function sends certain messages,
|
|
24
|
+
* this can be automated if the worker is wrapper by a call to createLoaderWorker in @loaders.gl/loader-utils.
|
|
25
|
+
*/
|
|
26
|
+
async function parseWithWorker(loader, data, options, context, parseOnMainThread) {
|
|
27
|
+
const name = loader.id; // TODO
|
|
28
|
+
const url = (0, worker_utils_2.getWorkerURL)(loader, options);
|
|
29
|
+
const workerFarm = worker_utils_2.WorkerFarm.getWorkerFarm(options);
|
|
30
|
+
const workerPool = workerFarm.getWorkerPool({ name, url });
|
|
31
|
+
// options.log object contains functions which cannot be transferred
|
|
32
|
+
// context.fetch & context.parse functions cannot be transferred
|
|
33
|
+
// TODO - decide how to handle logging on workers
|
|
34
|
+
options = JSON.parse(JSON.stringify(options));
|
|
35
|
+
context = JSON.parse(JSON.stringify(context || {}));
|
|
36
|
+
const job = await workerPool.startJob('process-on-worker',
|
|
37
|
+
// @ts-expect-error
|
|
38
|
+
onMessage.bind(null, parseOnMainThread) // eslint-disable-line @typescript-eslint/no-misused-promises
|
|
39
|
+
);
|
|
40
|
+
job.postMessage('process', {
|
|
41
|
+
// @ts-ignore
|
|
42
|
+
input: data,
|
|
43
|
+
options,
|
|
44
|
+
context
|
|
45
|
+
});
|
|
46
|
+
const result = await job.result;
|
|
47
|
+
// TODO - what is going on here?
|
|
48
|
+
return await result.result;
|
|
25
49
|
}
|
|
26
|
-
|
|
50
|
+
exports.parseWithWorker = parseWithWorker;
|
|
51
|
+
/**
|
|
52
|
+
* Handle worker's responses to the main thread
|
|
53
|
+
* @param job
|
|
54
|
+
* @param type
|
|
55
|
+
* @param payload
|
|
56
|
+
*/
|
|
27
57
|
async function onMessage(parseOnMainThread, job, type, payload) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const message = error instanceof Error ? error.message : 'unknown error';
|
|
52
|
-
job.postMessage('error', {
|
|
53
|
-
id,
|
|
54
|
-
error: message
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
break;
|
|
59
|
-
|
|
60
|
-
default:
|
|
61
|
-
console.warn("parse-with-worker unknown message ".concat(type));
|
|
62
|
-
}
|
|
58
|
+
switch (type) {
|
|
59
|
+
case 'done':
|
|
60
|
+
job.done(payload);
|
|
61
|
+
break;
|
|
62
|
+
case 'error':
|
|
63
|
+
job.error(new Error(payload.error));
|
|
64
|
+
break;
|
|
65
|
+
case 'process':
|
|
66
|
+
// Worker is asking for main thread to parseO
|
|
67
|
+
const { id, input, options } = payload;
|
|
68
|
+
try {
|
|
69
|
+
const result = await parseOnMainThread(input, options);
|
|
70
|
+
job.postMessage('done', { id, result });
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
const message = error instanceof Error ? error.message : 'unknown error';
|
|
74
|
+
job.postMessage('error', { id, error: message });
|
|
75
|
+
}
|
|
76
|
+
break;
|
|
77
|
+
default:
|
|
78
|
+
// eslint-disable-next-line
|
|
79
|
+
console.warn(`parse-with-worker unknown message ${type}`);
|
|
80
|
+
}
|
|
63
81
|
}
|
|
64
|
-
//# sourceMappingURL=parse-with-worker.js.map
|
package/dist/types.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
export type TypedIntArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Int32Array | Uint32Array;
|
|
3
|
+
export type TypedFloatArray = Uint16Array | Float32Array | Float64Array;
|
|
4
|
+
export type TypedArray = TypedIntArray | TypedFloatArray;
|
|
5
|
+
export type NumericArray = Array<number> | TypedIntArray | TypedFloatArray;
|
|
6
|
+
type FetchLike = (url: string, options?: RequestInit) => Promise<Response>;
|
|
7
|
+
/**
|
|
8
|
+
* Core Loader Options
|
|
9
|
+
*/
|
|
10
|
+
export type LoaderOptions = {
|
|
8
11
|
/** fetch options or a custom fetch function */
|
|
9
12
|
fetch?: typeof fetch | FetchLike | RequestInit | null;
|
|
10
13
|
/** Do not throw on errors */
|
|
@@ -30,7 +33,7 @@ export declare type LoaderOptions = {
|
|
|
30
33
|
/** Transforms to run on incoming batches */
|
|
31
34
|
transforms?: TransformBatches[];
|
|
32
35
|
/** CDN load workers from */
|
|
33
|
-
CDN?: string;
|
|
36
|
+
CDN?: string | null;
|
|
34
37
|
/** Set to `false` to disable workers */
|
|
35
38
|
worker?: boolean;
|
|
36
39
|
/** Number of concurrent workers (per loader) on desktop browser */
|
|
@@ -39,128 +42,138 @@ export declare type LoaderOptions = {
|
|
|
39
42
|
maxMobileConcurrency?: number;
|
|
40
43
|
/** Set to `false` to prevent reuse workers */
|
|
41
44
|
reuseWorkers?: boolean;
|
|
42
|
-
/**
|
|
45
|
+
/** Whether to use workers under Node.js (experimental) */
|
|
46
|
+
_nodeWorkers?: boolean;
|
|
47
|
+
/** set to 'test' to run local worker */
|
|
43
48
|
_workerType?: string;
|
|
44
49
|
/** @deprecated `options.batchType` removed, Use `options.<loader>.type` instead */
|
|
45
50
|
batchType?: 'row' | 'columnar' | 'arrow';
|
|
46
51
|
/** @deprecated `options.throw removed`, Use `options.nothrow` instead */
|
|
47
52
|
throws?: boolean;
|
|
48
53
|
/** @deprecated `options.dataType` no longer used */
|
|
49
|
-
dataType?:
|
|
54
|
+
dataType?: never;
|
|
50
55
|
/** @deprecated `options.uri` no longer used */
|
|
51
|
-
uri?:
|
|
56
|
+
uri?: never;
|
|
52
57
|
/** @deprecated `options.method` removed. Use `options.fetch.method` */
|
|
53
|
-
method?:
|
|
58
|
+
method?: never;
|
|
54
59
|
/** @deprecated `options.headers` removed. Use `options.fetch.headers` */
|
|
55
|
-
headers?:
|
|
60
|
+
headers?: never;
|
|
56
61
|
/** @deprecated `options.body` removed. Use `options.fetch.body` */
|
|
57
|
-
body?:
|
|
62
|
+
body?: never;
|
|
58
63
|
/** @deprecated `options.mode` removed. Use `options.fetch.mode` */
|
|
59
|
-
mode?:
|
|
64
|
+
mode?: never;
|
|
60
65
|
/** @deprecated `options.credentials` removed. Use `options.fetch.credentials` */
|
|
61
|
-
credentials?:
|
|
66
|
+
credentials?: never;
|
|
62
67
|
/** @deprecated `options.cache` removed. Use `options.fetch.cache` */
|
|
63
|
-
cache?:
|
|
68
|
+
cache?: never;
|
|
64
69
|
/** @deprecated `options.redirect` removed. Use `options.fetch.redirect` */
|
|
65
|
-
redirect?:
|
|
70
|
+
redirect?: never;
|
|
66
71
|
/** @deprecated `options.referrer` removed. Use `options.fetch.referrer` */
|
|
67
|
-
referrer?:
|
|
72
|
+
referrer?: never;
|
|
68
73
|
/** @deprecated `options.referrerPolicy` removed. Use `options.fetch.referrerPolicy` */
|
|
69
|
-
referrerPolicy?:
|
|
74
|
+
referrerPolicy?: never;
|
|
70
75
|
/** @deprecated `options.integrity` removed. Use `options.fetch.integrity` */
|
|
71
|
-
integrity?:
|
|
76
|
+
integrity?: never;
|
|
72
77
|
/** @deprecated `options.keepalive` removed. Use `options.fetch.keepalive` */
|
|
73
|
-
keepalive?:
|
|
78
|
+
keepalive?: never;
|
|
74
79
|
/** @deprecated `options.signal` removed. Use `options.fetch.signal` */
|
|
75
|
-
signal?:
|
|
76
|
-
[loaderId: string]:
|
|
80
|
+
signal?: never;
|
|
81
|
+
[loaderId: string]: unknown;
|
|
77
82
|
};
|
|
78
|
-
|
|
79
|
-
[key: string]:
|
|
83
|
+
type PreloadOptions = {
|
|
84
|
+
[key: string]: unknown;
|
|
80
85
|
};
|
|
81
86
|
/**
|
|
82
87
|
* A worker loader definition that can be used with `@loaders.gl/core` functions
|
|
83
88
|
*/
|
|
84
|
-
export
|
|
89
|
+
export type Loader<DataT = any, BatchT = any, LoaderOptionsT = LoaderOptions> = {
|
|
90
|
+
dataType?: DataT;
|
|
91
|
+
batchType?: BatchT;
|
|
92
|
+
options: LoaderOptionsT;
|
|
93
|
+
deprecatedOptions?: Record<string, string | Record<string, string>>;
|
|
85
94
|
name: string;
|
|
86
95
|
id: string;
|
|
87
96
|
module: string;
|
|
88
97
|
version: string;
|
|
89
98
|
worker?: string | boolean;
|
|
90
|
-
options: object;
|
|
91
|
-
deprecatedOptions?: object;
|
|
92
99
|
category?: string;
|
|
93
100
|
extensions: string[];
|
|
94
101
|
mimeTypes: string[];
|
|
95
102
|
binary?: boolean;
|
|
96
103
|
text?: boolean;
|
|
97
|
-
tests?: (((ArrayBuffer:
|
|
104
|
+
tests?: (((ArrayBuffer: ArrayBuffer) => boolean) | ArrayBuffer | string)[];
|
|
98
105
|
supported?: boolean;
|
|
99
|
-
testText?: (string:
|
|
106
|
+
testText?: (string: string) => boolean;
|
|
100
107
|
};
|
|
101
108
|
/**
|
|
102
109
|
* A "bundled" loader definition that can be used with `@loaders.gl/core` functions
|
|
103
110
|
* If a worker loader is supported it will also be supported.
|
|
104
111
|
*/
|
|
105
|
-
export
|
|
106
|
-
testText?: (string:
|
|
107
|
-
parse:
|
|
112
|
+
export type LoaderWithParser<DataT = any, BatchT = any, LoaderOptionsT = LoaderOptions> = Loader<DataT, BatchT, LoaderOptionsT> & {
|
|
113
|
+
testText?: (string: string) => boolean;
|
|
114
|
+
parse: (arrayBuffer: ArrayBuffer, options?: LoaderOptionsT, context?: LoaderContext) => Promise<DataT>;
|
|
108
115
|
preload?: Preload;
|
|
109
|
-
parseSync?:
|
|
110
|
-
parseText?:
|
|
111
|
-
parseTextSync?:
|
|
112
|
-
parseInBatches?:
|
|
113
|
-
parseFileInBatches?:
|
|
116
|
+
parseSync?: (arrayBuffer: ArrayBuffer, options?: LoaderOptionsT, context?: LoaderContext) => DataT;
|
|
117
|
+
parseText?: (text: string, options?: LoaderOptionsT) => Promise<DataT>;
|
|
118
|
+
parseTextSync?: (text: string, options?: LoaderOptionsT) => DataT;
|
|
119
|
+
parseInBatches?: (iterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>, options?: LoaderOptionsT, context?: LoaderContext) => AsyncIterable<BatchT>;
|
|
120
|
+
parseFileInBatches?: (file: Blob, options?: LoaderOptionsT, context?: LoaderContext) => AsyncIterable<BatchT>;
|
|
121
|
+
};
|
|
122
|
+
export type LoaderContext = {
|
|
123
|
+
loaders?: Loader[] | null;
|
|
124
|
+
url?: string;
|
|
125
|
+
fetch: typeof fetch | FetchLike;
|
|
126
|
+
response?: Response;
|
|
127
|
+
parse: (arrayBuffer: ArrayBuffer, loaders?: Loader | Loader[] | LoaderOptions, options?: LoaderOptions, context?: LoaderContext) => Promise<any>;
|
|
128
|
+
parseSync?: (arrayBuffer: ArrayBuffer, loaders?: Loader | Loader[] | LoaderOptions, options?: LoaderOptions, context?: LoaderContext) => any;
|
|
129
|
+
parseInBatches?: (iterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>, loaders?: Loader | Loader[] | LoaderOptions, options?: LoaderOptions, context?: LoaderContext) => AsyncIterable<any> | Promise<AsyncIterable<any>>;
|
|
114
130
|
};
|
|
131
|
+
type Preload = (url: string, options?: PreloadOptions) => any;
|
|
132
|
+
/** Typescript helper to extract options type from a generic loader type */
|
|
133
|
+
export type LoaderOptionsType<T = Loader> = T extends Loader<any, any, infer Options> ? Options : never;
|
|
134
|
+
/** Typescript helper to extract data type from a generic loader type */
|
|
135
|
+
export type LoaderReturnType<T = Loader> = T extends Loader<infer Return, any, any> ? Return : never;
|
|
136
|
+
/** Typescript helper to extract batch type from a generic loader type */
|
|
137
|
+
export type LoaderBatchType<T = Loader> = T extends Loader<any, infer Batch, any> ? Batch : never;
|
|
115
138
|
/** Options for writers */
|
|
116
|
-
export
|
|
139
|
+
export type WriterOptions = {
|
|
140
|
+
/** worker source. If is set will be used instead of loading worker from the Internet */
|
|
141
|
+
souce?: string | null;
|
|
142
|
+
/** writer-specific options */
|
|
143
|
+
[writerId: string]: any;
|
|
144
|
+
};
|
|
117
145
|
/**
|
|
118
146
|
* A writer definition that can be used with `@loaders.gl/core` functions
|
|
119
147
|
*/
|
|
120
|
-
export
|
|
148
|
+
export type Writer<DataT = unknown, BatchT = unknown, WriterOptionsT = WriterOptions> = {
|
|
121
149
|
name: string;
|
|
122
150
|
id: string;
|
|
123
151
|
module: string;
|
|
124
152
|
version: string;
|
|
125
|
-
|
|
126
|
-
deprecatedOptions?: object;
|
|
127
|
-
binary?: boolean;
|
|
153
|
+
worker?: string | boolean;
|
|
128
154
|
extensions?: string[];
|
|
129
155
|
mimeTypes?: string[];
|
|
156
|
+
binary?: boolean;
|
|
130
157
|
text?: boolean;
|
|
131
|
-
|
|
158
|
+
options: WriterOptionsT;
|
|
159
|
+
deprecatedOptions?: Record<string, string>;
|
|
132
160
|
encodeSync?: EncodeSync;
|
|
133
|
-
encodeInBatches?: EncodeInBatches;
|
|
134
161
|
encodeURLtoURL?: EncodeURLtoURL;
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
loaders?: Loader[] | null;
|
|
139
|
-
url?: string;
|
|
140
|
-
fetch: typeof fetch;
|
|
141
|
-
parse: (arrayBuffer: ArrayBuffer, loaders?: any, options?: LoaderOptions, context?: LoaderContext) => Promise<any>;
|
|
142
|
-
parseSync?: (arrayBuffer: ArrayBuffer, loaders?: any, options?: LoaderOptions, context?: LoaderContext) => any;
|
|
143
|
-
parseInBatches?: (iterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>, loaders?: any, options?: LoaderOptions, context?: LoaderContext) => AsyncIterable<any> | Promise<AsyncIterable<any>>;
|
|
162
|
+
encode?(data: DataT, options?: WriterOptionsT): Promise<ArrayBuffer>;
|
|
163
|
+
encodeText?(table: DataT, options?: WriterOptionsT): Promise<string> | string;
|
|
164
|
+
encodeInBatches?(data: AsyncIterable<any>, options?: WriterOptionsT): AsyncIterable<ArrayBuffer>;
|
|
144
165
|
};
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
declare type ParseFileInBatches = (file: Blob, options?: LoaderOptions, context?: LoaderContext) => AsyncIterable<any>;
|
|
151
|
-
declare type Encode = (data: any, options?: WriterOptions) => Promise<ArrayBuffer>;
|
|
152
|
-
declare type EncodeSync = (data: any, options?: WriterOptions) => ArrayBuffer;
|
|
153
|
-
declare type EncodeText = Function;
|
|
154
|
-
declare type EncodeInBatches = Function;
|
|
155
|
-
declare type EncodeURLtoURL = (inputUrl: string, outputUrl: string, options?: WriterOptions) => Promise<string>;
|
|
156
|
-
declare type Preload = (url: string, options?: PreloadOptions) => any;
|
|
157
|
-
export declare type TransformBatches = (asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>) => AsyncIterable<ArrayBuffer>;
|
|
166
|
+
type EncodeSync = (data: any, options?: WriterOptions) => ArrayBuffer;
|
|
167
|
+
type EncodeURLtoURL = (inputUrl: string, outputUrl: string, options?: WriterOptions) => Promise<string>;
|
|
168
|
+
/** Typescript helper to extract the writer options type from a generic writer type */
|
|
169
|
+
export type WriterOptionsType<T = Writer> = T extends Writer<unknown, unknown, infer Options> ? Options : never;
|
|
170
|
+
export type TransformBatches = (asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>) => AsyncIterable<ArrayBuffer>;
|
|
158
171
|
/** Types that can be synchronously parsed */
|
|
159
|
-
export
|
|
172
|
+
export type SyncDataType = string | ArrayBuffer;
|
|
160
173
|
/** Types that can be parsed async */
|
|
161
|
-
export
|
|
174
|
+
export type DataType = string | ArrayBuffer | File | Blob | Response | ReadableStream | Iterable<ArrayBuffer> | AsyncIterable<ArrayBuffer>;
|
|
162
175
|
/** Types that can be parsed in batches */
|
|
163
|
-
export
|
|
176
|
+
export type BatchableDataType = DataType | Iterable<ArrayBuffer> | AsyncIterable<ArrayBuffer> | Promise<AsyncIterable<ArrayBuffer>>;
|
|
164
177
|
/**
|
|
165
178
|
* A FileSystem interface can encapsulate a FileList, a ZipFile, a GoogleDrive etc.
|
|
166
179
|
*/
|
|
@@ -188,14 +201,14 @@ export interface IFileSystem {
|
|
|
188
201
|
*/
|
|
189
202
|
fetch(filename: string, options?: object): Promise<Response>;
|
|
190
203
|
}
|
|
191
|
-
|
|
204
|
+
type ReadOptions = {
|
|
192
205
|
buffer?: ArrayBuffer;
|
|
193
206
|
offset?: number;
|
|
194
207
|
length?: number;
|
|
195
208
|
position?: number;
|
|
196
209
|
};
|
|
197
210
|
export interface IRandomAccessReadFileSystem extends IFileSystem {
|
|
198
|
-
open(path: string, flags:
|
|
211
|
+
open(path: string, flags: string | number, mode?: any): Promise<any>;
|
|
199
212
|
close(fd: any): Promise<void>;
|
|
200
213
|
fstat(fd: any): Promise<object>;
|
|
201
214
|
read(fd: any, options?: ReadOptions): Promise<{
|