@loaders.gl/core 4.2.0-alpha.4 → 4.2.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core-addons/write-file-browser.js +62 -1
- package/dist/dist.dev.js +366 -332
- package/dist/dist.min.js +15 -0
- package/dist/index.cjs +55 -68
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +20 -20
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -1
- package/dist/iterators/batch-iterators/timed-batch-iterator.js +18 -13
- package/dist/iterators/make-iterator/make-array-buffer-iterator.d.ts +1 -1
- package/dist/iterators/make-iterator/make-array-buffer-iterator.d.ts.map +1 -1
- package/dist/iterators/make-iterator/make-array-buffer-iterator.js +21 -15
- package/dist/iterators/make-iterator/make-blob-iterator.d.ts +1 -1
- package/dist/iterators/make-iterator/make-blob-iterator.d.ts.map +1 -1
- package/dist/iterators/make-iterator/make-blob-iterator.js +18 -10
- package/dist/iterators/make-iterator/make-iterator.d.ts +1 -1
- package/dist/iterators/make-iterator/make-iterator.d.ts.map +1 -1
- package/dist/iterators/make-iterator/make-iterator.js +29 -18
- package/dist/iterators/make-iterator/make-stream-iterator.js +86 -23
- package/dist/iterators/make-iterator/make-string-iterator.d.ts +1 -1
- package/dist/iterators/make-iterator/make-string-iterator.d.ts.map +1 -1
- package/dist/iterators/make-iterator/make-string-iterator.js +20 -10
- package/dist/iterators/make-stream/make-stream.js +47 -29
- package/dist/javascript-utils/is-type.js +25 -19
- package/dist/lib/api/encode-table.js +40 -35
- package/dist/lib/api/encode.js +112 -73
- package/dist/lib/api/load-in-batches.js +35 -21
- package/dist/lib/api/load.js +35 -20
- package/dist/lib/api/loader-options.d.ts +2 -2
- package/dist/lib/api/loader-options.d.ts.map +1 -1
- package/dist/lib/api/loader-options.js +3 -1
- package/dist/lib/api/parse-in-batches.js +105 -69
- package/dist/lib/api/parse-sync.js +42 -33
- package/dist/lib/api/parse.js +73 -61
- package/dist/lib/api/register-loaders.js +23 -14
- package/dist/lib/api/select-loader.js +216 -163
- package/dist/lib/common.js +3 -1
- package/dist/lib/fetch/fetch-error-message.js +17 -12
- package/dist/lib/fetch/fetch-file.js +26 -15
- package/dist/lib/fetch/read-array-buffer.js +30 -15
- package/dist/lib/filesystems/browser-filesystem.js +126 -69
- package/dist/lib/filesystems/read-array-buffer.js +14 -6
- package/dist/lib/init.js +12 -6
- package/dist/lib/loader-utils/check-errors.js +37 -16
- package/dist/lib/loader-utils/get-data.js +110 -88
- package/dist/lib/loader-utils/get-fetch-function.js +24 -13
- package/dist/lib/loader-utils/loader-context.js +50 -31
- package/dist/lib/loader-utils/loggers.js +34 -44
- package/dist/lib/loader-utils/normalize-loader.js +45 -32
- package/dist/lib/loader-utils/option-defaults.js +38 -34
- package/dist/lib/loader-utils/option-utils.d.ts.map +1 -1
- package/dist/lib/loader-utils/option-utils.js +133 -80
- package/dist/lib/progress/fetch-progress.js +54 -47
- package/dist/lib/utils/log.js +4 -4
- package/dist/lib/utils/mime-type-utils.js +34 -11
- package/dist/lib/utils/resource-utils.js +77 -45
- package/dist/lib/utils/response-utils.js +97 -74
- package/dist/lib/utils/url-utils.js +6 -4
- package/dist/null-loader.js +43 -29
- package/dist/workers/null-worker-node.js +3 -1
- package/dist/workers/null-worker.js +3 -1
- package/package.json +7 -7
- package/src/lib/loader-utils/option-utils.ts +3 -1
- package/dist/core-addons/README.md +0 -1
- package/dist/core-addons/write-file-browser.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/iterators/batch-iterators/timed-batch-iterator.js.map +0 -1
- package/dist/iterators/make-iterator/make-array-buffer-iterator.js.map +0 -1
- package/dist/iterators/make-iterator/make-blob-iterator.js.map +0 -1
- package/dist/iterators/make-iterator/make-iterator.js.map +0 -1
- package/dist/iterators/make-iterator/make-stream-iterator.js.map +0 -1
- package/dist/iterators/make-iterator/make-string-iterator.js.map +0 -1
- package/dist/iterators/make-stream/make-stream.js.map +0 -1
- package/dist/javascript-utils/is-type.js.map +0 -1
- package/dist/lib/api/encode-table.js.map +0 -1
- package/dist/lib/api/encode.js.map +0 -1
- package/dist/lib/api/load-in-batches.js.map +0 -1
- package/dist/lib/api/load.js.map +0 -1
- package/dist/lib/api/loader-options.js.map +0 -1
- package/dist/lib/api/parse-in-batches.js.map +0 -1
- package/dist/lib/api/parse-sync.js.map +0 -1
- package/dist/lib/api/parse.js.map +0 -1
- package/dist/lib/api/register-loaders.js.map +0 -1
- package/dist/lib/api/select-loader.js.map +0 -1
- package/dist/lib/common.js.map +0 -1
- package/dist/lib/fetch/fetch-error-message.js.map +0 -1
- package/dist/lib/fetch/fetch-file.js.map +0 -1
- package/dist/lib/fetch/read-array-buffer.js.map +0 -1
- package/dist/lib/filesystems/browser-filesystem.js.map +0 -1
- package/dist/lib/filesystems/read-array-buffer.js.map +0 -1
- package/dist/lib/init.js.map +0 -1
- package/dist/lib/loader-utils/check-errors.js.map +0 -1
- package/dist/lib/loader-utils/get-data.js.map +0 -1
- package/dist/lib/loader-utils/get-fetch-function.js.map +0 -1
- package/dist/lib/loader-utils/loader-context.js.map +0 -1
- package/dist/lib/loader-utils/loggers.js.map +0 -1
- package/dist/lib/loader-utils/normalize-loader.js.map +0 -1
- package/dist/lib/loader-utils/option-defaults.js.map +0 -1
- package/dist/lib/loader-utils/option-utils.js.map +0 -1
- package/dist/lib/progress/fetch-progress.js.map +0 -1
- package/dist/lib/utils/log.js.map +0 -1
- package/dist/lib/utils/mime-type-utils.js.map +0 -1
- package/dist/lib/utils/resource-utils.js.map +0 -1
- package/dist/lib/utils/response-utils.js.map +0 -1
- package/dist/lib/utils/url-utils.js.map +0 -1
- package/dist/null-loader.js.map +0 -1
- package/dist/workers/null-worker-node.js.map +0 -1
- package/dist/workers/null-worker.js.map +0 -1
package/dist/dist.dev.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
if (typeof exports === 'object' && typeof module === 'object')
|
|
3
3
|
module.exports = factory();
|
|
4
4
|
else if (typeof define === 'function' && define.amd) define([], factory);
|
|
5
|
-
else if (typeof exports === 'object') exports['
|
|
6
|
-
else root['
|
|
5
|
+
else if (typeof exports === 'object') exports['loaders'] = factory();
|
|
6
|
+
else root['loaders'] = factory();})(globalThis, function () {
|
|
7
7
|
"use strict";
|
|
8
8
|
var __exports__ = (() => {
|
|
9
9
|
var __defProp = Object.defineProperty;
|
|
@@ -24,9 +24,9 @@ var __exports__ = (() => {
|
|
|
24
24
|
};
|
|
25
25
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
26
26
|
|
|
27
|
-
//
|
|
28
|
-
var
|
|
29
|
-
__export(
|
|
27
|
+
// bundle.ts
|
|
28
|
+
var bundle_exports = {};
|
|
29
|
+
__export(bundle_exports, {
|
|
30
30
|
JSONLoader: () => JSONLoader,
|
|
31
31
|
NullLoader: () => NullLoader,
|
|
32
32
|
NullWorkerLoader: () => NullWorkerLoader,
|
|
@@ -101,7 +101,10 @@ var __exports__ = (() => {
|
|
|
101
101
|
var window_ = globals.window || globals.self || globals.global || {};
|
|
102
102
|
var global_ = globals.global || globals.self || globals.window || {};
|
|
103
103
|
var document_ = globals.document || {};
|
|
104
|
-
var isBrowser =
|
|
104
|
+
var isBrowser = (
|
|
105
|
+
// @ts-ignore process does not exist on browser
|
|
106
|
+
Boolean(typeof process !== "object" || String(process) !== "[object process]" || process.browser)
|
|
107
|
+
);
|
|
105
108
|
var isWorker = typeof importScripts === "function";
|
|
106
109
|
var matches = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
|
|
107
110
|
var nodeVersion = matches && parseFloat(matches[1]) || 0;
|
|
@@ -114,12 +117,14 @@ var __exports__ = (() => {
|
|
|
114
117
|
if (level > 3) {
|
|
115
118
|
return newOptions;
|
|
116
119
|
}
|
|
117
|
-
const options = {
|
|
118
|
-
...baseOptions
|
|
119
|
-
};
|
|
120
|
+
const options = { ...baseOptions };
|
|
120
121
|
for (const [key, newValue] of Object.entries(newOptions)) {
|
|
121
122
|
if (newValue && typeof newValue === "object" && !Array.isArray(newValue)) {
|
|
122
|
-
options[key] = mergeOptionsRecursively(
|
|
123
|
+
options[key] = mergeOptionsRecursively(
|
|
124
|
+
options[key] || {},
|
|
125
|
+
newOptions[key],
|
|
126
|
+
level + 1
|
|
127
|
+
);
|
|
123
128
|
} else {
|
|
124
129
|
options[key] = newOptions[key];
|
|
125
130
|
}
|
|
@@ -132,11 +137,13 @@ var __exports__ = (() => {
|
|
|
132
137
|
function getVersion() {
|
|
133
138
|
if (!globalThis._loadersgl_?.version) {
|
|
134
139
|
globalThis._loadersgl_ = globalThis._loadersgl_ || {};
|
|
135
|
-
if (
|
|
136
|
-
console.warn(
|
|
140
|
+
if (typeof __VERSION__ === "undefined") {
|
|
141
|
+
console.warn(
|
|
142
|
+
"loaders.gl: The __VERSION__ variable is not injected using babel plugin. Latest unstable workers would be fetched from the CDN."
|
|
143
|
+
);
|
|
137
144
|
globalThis._loadersgl_.version = NPM_TAG;
|
|
138
145
|
} else {
|
|
139
|
-
globalThis._loadersgl_.version =
|
|
146
|
+
globalThis._loadersgl_.version = __VERSION__;
|
|
140
147
|
}
|
|
141
148
|
}
|
|
142
149
|
return globalThis._loadersgl_.version;
|
|
@@ -161,19 +168,22 @@ var __exports__ = (() => {
|
|
|
161
168
|
var window_2 = globals2.window || globals2.self || globals2.global || {};
|
|
162
169
|
var global_2 = globals2.global || globals2.self || globals2.window || {};
|
|
163
170
|
var document_2 = globals2.document || {};
|
|
164
|
-
var isBrowser2 =
|
|
171
|
+
var isBrowser2 = (
|
|
172
|
+
// @ts-ignore process.browser
|
|
173
|
+
typeof process !== "object" || String(process) !== "[object process]" || process.browser
|
|
174
|
+
);
|
|
165
175
|
var isMobile = typeof window !== "undefined" && typeof window.orientation !== "undefined";
|
|
166
176
|
var matches2 = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
|
|
167
177
|
var nodeVersion2 = matches2 && parseFloat(matches2[1]) || 0;
|
|
168
178
|
|
|
169
179
|
// ../worker-utils/src/lib/worker-farm/worker-job.ts
|
|
170
180
|
var WorkerJob = class {
|
|
171
|
-
isRunning = true;
|
|
172
|
-
_resolve = () => {
|
|
173
|
-
};
|
|
174
|
-
_reject = () => {
|
|
175
|
-
};
|
|
176
181
|
constructor(jobName, workerThread) {
|
|
182
|
+
this.isRunning = true;
|
|
183
|
+
this._resolve = () => {
|
|
184
|
+
};
|
|
185
|
+
this._reject = () => {
|
|
186
|
+
};
|
|
177
187
|
this.name = jobName;
|
|
178
188
|
this.workerThread = workerThread;
|
|
179
189
|
this.result = new Promise((resolve2, reject) => {
|
|
@@ -181,18 +191,29 @@ var __exports__ = (() => {
|
|
|
181
191
|
this._reject = reject;
|
|
182
192
|
});
|
|
183
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* Send a message to the job's worker thread
|
|
196
|
+
* @param data any data structure, ideally consisting mostly of transferrable objects
|
|
197
|
+
*/
|
|
184
198
|
postMessage(type, payload) {
|
|
185
199
|
this.workerThread.postMessage({
|
|
186
200
|
source: "loaders.gl",
|
|
201
|
+
// Lets worker ignore unrelated messages
|
|
187
202
|
type,
|
|
188
203
|
payload
|
|
189
204
|
});
|
|
190
205
|
}
|
|
206
|
+
/**
|
|
207
|
+
* Call to resolve the `result` Promise with the supplied value
|
|
208
|
+
*/
|
|
191
209
|
done(value) {
|
|
192
210
|
assert2(this.isRunning);
|
|
193
211
|
this.isRunning = false;
|
|
194
212
|
this._resolve(value);
|
|
195
213
|
}
|
|
214
|
+
/**
|
|
215
|
+
* Call to reject the `result` Promise with the supplied error
|
|
216
|
+
*/
|
|
196
217
|
error(error) {
|
|
197
218
|
assert2(this.isRunning);
|
|
198
219
|
this.isRunning = false;
|
|
@@ -232,9 +253,7 @@ var __exports__ = (() => {
|
|
|
232
253
|
return getLoadableWorkerURLFromSource(workerSource);
|
|
233
254
|
}
|
|
234
255
|
function getLoadableWorkerURLFromSource(workerSource) {
|
|
235
|
-
const blob = new Blob([workerSource], {
|
|
236
|
-
type: "application/javascript"
|
|
237
|
-
});
|
|
256
|
+
const blob = new Blob([workerSource], { type: "application/javascript" });
|
|
238
257
|
return URL.createObjectURL(blob);
|
|
239
258
|
}
|
|
240
259
|
function buildScriptSource(workerUrl) {
|
|
@@ -301,17 +320,10 @@ var __exports__ = (() => {
|
|
|
301
320
|
var NOOP = () => {
|
|
302
321
|
};
|
|
303
322
|
var WorkerThread = class {
|
|
304
|
-
terminated = false;
|
|
305
|
-
_loadableURL = "";
|
|
306
|
-
static isSupported() {
|
|
307
|
-
return typeof Worker !== "undefined" && isBrowser2 || typeof NodeWorker !== "undefined" && !isBrowser2;
|
|
308
|
-
}
|
|
309
323
|
constructor(props) {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
url
|
|
314
|
-
} = props;
|
|
324
|
+
this.terminated = false;
|
|
325
|
+
this._loadableURL = "";
|
|
326
|
+
const { name, source, url } = props;
|
|
315
327
|
assert2(source || url);
|
|
316
328
|
this.name = name;
|
|
317
329
|
this.source = source;
|
|
@@ -320,6 +332,14 @@ var __exports__ = (() => {
|
|
|
320
332
|
this.onError = (error) => console.log(error);
|
|
321
333
|
this.worker = isBrowser2 ? this._createBrowserWorker() : this._createNodeWorker();
|
|
322
334
|
}
|
|
335
|
+
/** Checks if workers are supported on this platform */
|
|
336
|
+
static isSupported() {
|
|
337
|
+
return typeof Worker !== "undefined" && isBrowser2 || typeof NodeWorker !== "undefined" && !isBrowser2;
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Terminate this worker thread
|
|
341
|
+
* @note Can free up significant memory
|
|
342
|
+
*/
|
|
323
343
|
destroy() {
|
|
324
344
|
this.onMessage = NOOP;
|
|
325
345
|
this.onError = NOOP;
|
|
@@ -329,10 +349,20 @@ var __exports__ = (() => {
|
|
|
329
349
|
get isRunning() {
|
|
330
350
|
return Boolean(this.onMessage);
|
|
331
351
|
}
|
|
352
|
+
/**
|
|
353
|
+
* Send a message to this worker thread
|
|
354
|
+
* @param data any data structure, ideally consisting mostly of transferrable objects
|
|
355
|
+
* @param transferList If not supplied, calculated automatically by traversing data
|
|
356
|
+
*/
|
|
332
357
|
postMessage(data, transferList) {
|
|
333
358
|
transferList = transferList || getTransferList(data);
|
|
334
359
|
this.worker.postMessage(data, transferList);
|
|
335
360
|
}
|
|
361
|
+
// PRIVATE
|
|
362
|
+
/**
|
|
363
|
+
* Generate a standard Error from an ErrorEvent
|
|
364
|
+
* @param event
|
|
365
|
+
*/
|
|
336
366
|
_getErrorFromErrorEvent(event) {
|
|
337
367
|
let message = "Failed to load ";
|
|
338
368
|
message += `worker ${this.name} from ${this.url}. `;
|
|
@@ -344,14 +374,12 @@ var __exports__ = (() => {
|
|
|
344
374
|
}
|
|
345
375
|
return new Error(message);
|
|
346
376
|
}
|
|
377
|
+
/**
|
|
378
|
+
* Creates a worker thread on the browser
|
|
379
|
+
*/
|
|
347
380
|
_createBrowserWorker() {
|
|
348
|
-
this._loadableURL = getLoadableWorkerURL({
|
|
349
|
-
|
|
350
|
-
url: this.url
|
|
351
|
-
});
|
|
352
|
-
const worker = new Worker(this._loadableURL, {
|
|
353
|
-
name: this.name
|
|
354
|
-
});
|
|
381
|
+
this._loadableURL = getLoadableWorkerURL({ source: this.source, url: this.url });
|
|
382
|
+
const worker = new Worker(this._loadableURL, { name: this.name });
|
|
355
383
|
worker.onmessage = (event) => {
|
|
356
384
|
if (!event.data) {
|
|
357
385
|
this.onError(new Error("No data received"));
|
|
@@ -366,18 +394,18 @@ var __exports__ = (() => {
|
|
|
366
394
|
worker.onmessageerror = (event) => console.error(event);
|
|
367
395
|
return worker;
|
|
368
396
|
}
|
|
397
|
+
/**
|
|
398
|
+
* Creates a worker thread in node.js
|
|
399
|
+
* @todo https://nodejs.org/api/async_hooks.html#async-resource-worker-pool
|
|
400
|
+
*/
|
|
369
401
|
_createNodeWorker() {
|
|
370
402
|
let worker;
|
|
371
403
|
if (this.url) {
|
|
372
404
|
const absolute = this.url.includes(":/") || this.url.startsWith("/");
|
|
373
405
|
const url = absolute ? this.url : `./${this.url}`;
|
|
374
|
-
worker = new NodeWorker(url, {
|
|
375
|
-
eval: false
|
|
376
|
-
});
|
|
406
|
+
worker = new NodeWorker(url, { eval: false });
|
|
377
407
|
} else if (this.source) {
|
|
378
|
-
worker = new NodeWorker(this.source, {
|
|
379
|
-
eval: true
|
|
380
|
-
});
|
|
408
|
+
worker = new NodeWorker(this.source, { eval: true });
|
|
381
409
|
} else {
|
|
382
410
|
throw new Error("no worker");
|
|
383
411
|
}
|
|
@@ -395,34 +423,40 @@ var __exports__ = (() => {
|
|
|
395
423
|
|
|
396
424
|
// ../worker-utils/src/lib/worker-farm/worker-pool.ts
|
|
397
425
|
var WorkerPool = class {
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
};
|
|
403
|
-
reuseWorkers = true;
|
|
404
|
-
props = {};
|
|
405
|
-
jobQueue = [];
|
|
406
|
-
idleQueue = [];
|
|
407
|
-
count = 0;
|
|
408
|
-
isDestroyed = false;
|
|
409
|
-
static isSupported() {
|
|
410
|
-
return WorkerThread.isSupported();
|
|
411
|
-
}
|
|
426
|
+
/**
|
|
427
|
+
* @param processor - worker function
|
|
428
|
+
* @param maxConcurrency - max count of workers
|
|
429
|
+
*/
|
|
412
430
|
constructor(props) {
|
|
431
|
+
this.name = "unnamed";
|
|
432
|
+
this.maxConcurrency = 1;
|
|
433
|
+
this.maxMobileConcurrency = 1;
|
|
434
|
+
this.onDebug = () => {
|
|
435
|
+
};
|
|
436
|
+
this.reuseWorkers = true;
|
|
437
|
+
this.props = {};
|
|
438
|
+
this.jobQueue = [];
|
|
439
|
+
this.idleQueue = [];
|
|
440
|
+
this.count = 0;
|
|
441
|
+
this.isDestroyed = false;
|
|
413
442
|
this.source = props.source;
|
|
414
443
|
this.url = props.url;
|
|
415
444
|
this.setProps(props);
|
|
416
445
|
}
|
|
446
|
+
/** Checks if workers are supported on this platform */
|
|
447
|
+
static isSupported() {
|
|
448
|
+
return WorkerThread.isSupported();
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Terminates all workers in the pool
|
|
452
|
+
* @note Can free up significant memory
|
|
453
|
+
*/
|
|
417
454
|
destroy() {
|
|
418
455
|
this.idleQueue.forEach((worker) => worker.destroy());
|
|
419
456
|
this.isDestroyed = true;
|
|
420
457
|
}
|
|
421
458
|
setProps(props) {
|
|
422
|
-
this.props = {
|
|
423
|
-
...this.props,
|
|
424
|
-
...props
|
|
425
|
-
};
|
|
459
|
+
this.props = { ...this.props, ...props };
|
|
426
460
|
if (props.name !== void 0) {
|
|
427
461
|
this.name = props.name;
|
|
428
462
|
}
|
|
@@ -441,17 +475,17 @@ var __exports__ = (() => {
|
|
|
441
475
|
}
|
|
442
476
|
async startJob(name, onMessage3 = (job, type, data) => job.done(data), onError = (job, error) => job.error(error)) {
|
|
443
477
|
const startPromise = new Promise((onStart) => {
|
|
444
|
-
this.jobQueue.push({
|
|
445
|
-
name,
|
|
446
|
-
onMessage: onMessage3,
|
|
447
|
-
onError,
|
|
448
|
-
onStart
|
|
449
|
-
});
|
|
478
|
+
this.jobQueue.push({ name, onMessage: onMessage3, onError, onStart });
|
|
450
479
|
return this;
|
|
451
480
|
});
|
|
452
481
|
this._startQueuedJob();
|
|
453
482
|
return await startPromise;
|
|
454
483
|
}
|
|
484
|
+
// PRIVATE
|
|
485
|
+
/**
|
|
486
|
+
* Starts first queued job if worker is available or can be created
|
|
487
|
+
* Called when job is started and whenever a worker returns to the idleQueue
|
|
488
|
+
*/
|
|
455
489
|
async _startQueuedJob() {
|
|
456
490
|
if (!this.jobQueue.length) {
|
|
457
491
|
return;
|
|
@@ -481,8 +515,23 @@ var __exports__ = (() => {
|
|
|
481
515
|
}
|
|
482
516
|
}
|
|
483
517
|
}
|
|
518
|
+
/**
|
|
519
|
+
* Returns a worker to the idle queue
|
|
520
|
+
* Destroys the worker if
|
|
521
|
+
* - pool is destroyed
|
|
522
|
+
* - if this pool doesn't reuse workers
|
|
523
|
+
* - if maxConcurrency has been lowered
|
|
524
|
+
* @param worker
|
|
525
|
+
*/
|
|
484
526
|
returnWorkerToQueue(worker) {
|
|
485
|
-
const shouldDestroyWorker =
|
|
527
|
+
const shouldDestroyWorker = (
|
|
528
|
+
// Workers on Node.js prevent the process from exiting.
|
|
529
|
+
// Until we figure out how to close them before exit, we always destroy them
|
|
530
|
+
!isBrowser2 || // If the pool is destroyed, there is no reason to keep the worker around
|
|
531
|
+
this.isDestroyed || // If the app has disabled worker reuse, any completed workers should be destroyed
|
|
532
|
+
!this.reuseWorkers || // If concurrency has been lowered, this worker might be surplus to requirements
|
|
533
|
+
this.count > this._getMaxConcurrency()
|
|
534
|
+
);
|
|
486
535
|
if (shouldDestroyWorker) {
|
|
487
536
|
worker.destroy();
|
|
488
537
|
this.count--;
|
|
@@ -493,6 +542,9 @@ var __exports__ = (() => {
|
|
|
493
542
|
this._startQueuedJob();
|
|
494
543
|
}
|
|
495
544
|
}
|
|
545
|
+
/**
|
|
546
|
+
* Returns idle worker or creates new worker if maxConcurrency has not been reached
|
|
547
|
+
*/
|
|
496
548
|
_getAvailableWorker() {
|
|
497
549
|
if (this.idleQueue.length > 0) {
|
|
498
550
|
return this.idleQueue.shift() || null;
|
|
@@ -500,11 +552,7 @@ var __exports__ = (() => {
|
|
|
500
552
|
if (this.count < this._getMaxConcurrency()) {
|
|
501
553
|
this.count++;
|
|
502
554
|
const name = `${this.name.toLowerCase()} (#${this.count} of ${this.maxConcurrency})`;
|
|
503
|
-
return new WorkerThread({
|
|
504
|
-
name,
|
|
505
|
-
source: this.source,
|
|
506
|
-
url: this.url
|
|
507
|
-
});
|
|
555
|
+
return new WorkerThread({ name, source: this.source, url: this.url });
|
|
508
556
|
}
|
|
509
557
|
return null;
|
|
510
558
|
}
|
|
@@ -522,43 +570,54 @@ var __exports__ = (() => {
|
|
|
522
570
|
}
|
|
523
571
|
};
|
|
524
572
|
var WorkerFarm = class {
|
|
525
|
-
|
|
573
|
+
/** get global instance with WorkerFarm.getWorkerFarm() */
|
|
574
|
+
constructor(props) {
|
|
575
|
+
this.workerPools = /* @__PURE__ */ new Map();
|
|
576
|
+
this.props = { ...DEFAULT_PROPS };
|
|
577
|
+
this.setProps(props);
|
|
578
|
+
this.workerPools = /* @__PURE__ */ new Map();
|
|
579
|
+
}
|
|
580
|
+
/** Checks if workers are supported on this platform */
|
|
526
581
|
static isSupported() {
|
|
527
582
|
return WorkerThread.isSupported();
|
|
528
583
|
}
|
|
584
|
+
/** Get the singleton instance of the global worker farm */
|
|
529
585
|
static getWorkerFarm(props = {}) {
|
|
530
586
|
WorkerFarm._workerFarm = WorkerFarm._workerFarm || new WorkerFarm({});
|
|
531
587
|
WorkerFarm._workerFarm.setProps(props);
|
|
532
588
|
return WorkerFarm._workerFarm;
|
|
533
589
|
}
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
this.setProps(props);
|
|
539
|
-
this.workerPools = /* @__PURE__ */ new Map();
|
|
540
|
-
}
|
|
590
|
+
/**
|
|
591
|
+
* Terminate all workers in the farm
|
|
592
|
+
* @note Can free up significant memory
|
|
593
|
+
*/
|
|
541
594
|
destroy() {
|
|
542
595
|
for (const workerPool of this.workerPools.values()) {
|
|
543
596
|
workerPool.destroy();
|
|
544
597
|
}
|
|
545
598
|
this.workerPools = /* @__PURE__ */ new Map();
|
|
546
599
|
}
|
|
600
|
+
/**
|
|
601
|
+
* Set props used when initializing worker pools
|
|
602
|
+
* @param props
|
|
603
|
+
*/
|
|
547
604
|
setProps(props) {
|
|
548
|
-
this.props = {
|
|
549
|
-
...this.props,
|
|
550
|
-
...props
|
|
551
|
-
};
|
|
605
|
+
this.props = { ...this.props, ...props };
|
|
552
606
|
for (const workerPool of this.workerPools.values()) {
|
|
553
607
|
workerPool.setProps(this._getWorkerPoolProps());
|
|
554
608
|
}
|
|
555
609
|
}
|
|
610
|
+
/**
|
|
611
|
+
* Returns a worker pool for the specified worker
|
|
612
|
+
* @param options - only used first time for a specific worker name
|
|
613
|
+
* @param options.name - the name of the worker - used to identify worker pool
|
|
614
|
+
* @param options.url -
|
|
615
|
+
* @param options.source -
|
|
616
|
+
* @example
|
|
617
|
+
* const job = WorkerFarm.getWorkerFarm().getWorkerPool({name, url}).startJob(...);
|
|
618
|
+
*/
|
|
556
619
|
getWorkerPool(options) {
|
|
557
|
-
const {
|
|
558
|
-
name,
|
|
559
|
-
source,
|
|
560
|
-
url
|
|
561
|
-
} = options;
|
|
620
|
+
const { name, source, url } = options;
|
|
562
621
|
let workerPool = this.workerPools.get(name);
|
|
563
622
|
if (!workerPool) {
|
|
564
623
|
workerPool = new WorkerPool({
|
|
@@ -616,24 +675,20 @@ var __exports__ = (() => {
|
|
|
616
675
|
async function processOnWorker(worker, data, options = {}, context = {}) {
|
|
617
676
|
const name = getWorkerName(worker);
|
|
618
677
|
const workerFarm = WorkerFarm.getWorkerFarm(options);
|
|
619
|
-
const {
|
|
620
|
-
|
|
621
|
-
} = options;
|
|
622
|
-
const workerPoolProps = {
|
|
623
|
-
name,
|
|
624
|
-
source
|
|
625
|
-
};
|
|
678
|
+
const { source } = options;
|
|
679
|
+
const workerPoolProps = { name, source };
|
|
626
680
|
if (!source) {
|
|
627
681
|
workerPoolProps.url = getWorkerURL(worker, options);
|
|
628
682
|
}
|
|
629
683
|
const workerPool = workerFarm.getWorkerPool(workerPoolProps);
|
|
630
684
|
const jobName = options.jobName || worker.name;
|
|
631
|
-
const job = await workerPool.startJob(
|
|
685
|
+
const job = await workerPool.startJob(
|
|
686
|
+
jobName,
|
|
687
|
+
// eslint-disable-next-line
|
|
688
|
+
onMessage.bind(null, context)
|
|
689
|
+
);
|
|
632
690
|
const transferableOptions = getTransferListForWriter(options);
|
|
633
|
-
job.postMessage("process", {
|
|
634
|
-
input: data,
|
|
635
|
-
options: transferableOptions
|
|
636
|
-
});
|
|
691
|
+
job.postMessage("process", { input: data, options: transferableOptions });
|
|
637
692
|
const result = await job.result;
|
|
638
693
|
return result.result;
|
|
639
694
|
}
|
|
@@ -646,30 +701,17 @@ var __exports__ = (() => {
|
|
|
646
701
|
job.error(new Error(payload.error));
|
|
647
702
|
break;
|
|
648
703
|
case "process":
|
|
649
|
-
const {
|
|
650
|
-
id,
|
|
651
|
-
input,
|
|
652
|
-
options
|
|
653
|
-
} = payload;
|
|
704
|
+
const { id, input, options } = payload;
|
|
654
705
|
try {
|
|
655
706
|
if (!context.process) {
|
|
656
|
-
job.postMessage("error", {
|
|
657
|
-
id,
|
|
658
|
-
error: "Worker not set up to process on main thread"
|
|
659
|
-
});
|
|
707
|
+
job.postMessage("error", { id, error: "Worker not set up to process on main thread" });
|
|
660
708
|
return;
|
|
661
709
|
}
|
|
662
710
|
const result = await context.process(input, options);
|
|
663
|
-
job.postMessage("done", {
|
|
664
|
-
id,
|
|
665
|
-
result
|
|
666
|
-
});
|
|
711
|
+
job.postMessage("done", { id, result });
|
|
667
712
|
} catch (error) {
|
|
668
713
|
const message = error instanceof Error ? error.message : "unknown error";
|
|
669
|
-
job.postMessage("error", {
|
|
670
|
-
id,
|
|
671
|
-
error: message
|
|
672
|
-
});
|
|
714
|
+
job.postMessage("error", { id, error: message });
|
|
673
715
|
}
|
|
674
716
|
break;
|
|
675
717
|
default:
|
|
@@ -701,14 +743,17 @@ var __exports__ = (() => {
|
|
|
701
743
|
const name = loader.id;
|
|
702
744
|
const url = getWorkerURL(loader, options);
|
|
703
745
|
const workerFarm = WorkerFarm.getWorkerFarm(options);
|
|
704
|
-
const workerPool = workerFarm.getWorkerPool({
|
|
705
|
-
name,
|
|
706
|
-
url
|
|
707
|
-
});
|
|
746
|
+
const workerPool = workerFarm.getWorkerPool({ name, url });
|
|
708
747
|
options = JSON.parse(JSON.stringify(options));
|
|
709
748
|
context = JSON.parse(JSON.stringify(context || {}));
|
|
710
|
-
const job = await workerPool.startJob(
|
|
749
|
+
const job = await workerPool.startJob(
|
|
750
|
+
"process-on-worker",
|
|
751
|
+
// @ts-expect-error
|
|
752
|
+
onMessage2.bind(null, parseOnMainThread)
|
|
753
|
+
// eslint-disable-line @typescript-eslint/no-misused-promises
|
|
754
|
+
);
|
|
711
755
|
job.postMessage("process", {
|
|
756
|
+
// @ts-ignore
|
|
712
757
|
input: data,
|
|
713
758
|
options,
|
|
714
759
|
context
|
|
@@ -725,23 +770,13 @@ var __exports__ = (() => {
|
|
|
725
770
|
job.error(new Error(payload.error));
|
|
726
771
|
break;
|
|
727
772
|
case "process":
|
|
728
|
-
const {
|
|
729
|
-
id,
|
|
730
|
-
input,
|
|
731
|
-
options
|
|
732
|
-
} = payload;
|
|
773
|
+
const { id, input, options } = payload;
|
|
733
774
|
try {
|
|
734
775
|
const result = await parseOnMainThread(input, options);
|
|
735
|
-
job.postMessage("done", {
|
|
736
|
-
id,
|
|
737
|
-
result
|
|
738
|
-
});
|
|
776
|
+
job.postMessage("done", { id, result });
|
|
739
777
|
} catch (error) {
|
|
740
778
|
const message = error instanceof Error ? error.message : "unknown error";
|
|
741
|
-
job.postMessage("error", {
|
|
742
|
-
id,
|
|
743
|
-
error: message
|
|
744
|
-
});
|
|
779
|
+
job.postMessage("error", { id, error: message });
|
|
745
780
|
}
|
|
746
781
|
break;
|
|
747
782
|
default:
|
|
@@ -779,7 +814,9 @@ var __exports__ = (() => {
|
|
|
779
814
|
return concatenateArrayBuffersFromArray(sources);
|
|
780
815
|
}
|
|
781
816
|
function concatenateArrayBuffersFromArray(sources) {
|
|
782
|
-
const sourceArrays = sources.map(
|
|
817
|
+
const sourceArrays = sources.map(
|
|
818
|
+
(source2) => source2 instanceof ArrayBuffer ? new Uint8Array(source2) : source2
|
|
819
|
+
);
|
|
783
820
|
const byteLength = sourceArrays.reduce((length, typedArray) => length + typedArray.byteLength, 0);
|
|
784
821
|
const result = new Uint8Array(byteLength);
|
|
785
822
|
let offset = 0;
|
|
@@ -794,9 +831,7 @@ var __exports__ = (() => {
|
|
|
794
831
|
async function* makeTextDecoderIterator(arrayBufferIterator, options = {}) {
|
|
795
832
|
const textDecoder = new TextDecoder(void 0, options);
|
|
796
833
|
for await (const arrayBuffer of arrayBufferIterator) {
|
|
797
|
-
yield typeof arrayBuffer === "string" ? arrayBuffer : textDecoder.decode(arrayBuffer, {
|
|
798
|
-
stream: true
|
|
799
|
-
});
|
|
834
|
+
yield typeof arrayBuffer === "string" ? arrayBuffer : textDecoder.decode(arrayBuffer, { stream: true });
|
|
800
835
|
}
|
|
801
836
|
}
|
|
802
837
|
async function* makeTextEncoderIterator(textIterator) {
|
|
@@ -823,10 +858,7 @@ var __exports__ = (() => {
|
|
|
823
858
|
async function* makeNumberedLineIterator(lineIterator) {
|
|
824
859
|
let counter = 1;
|
|
825
860
|
for await (const line of lineIterator) {
|
|
826
|
-
yield {
|
|
827
|
-
counter,
|
|
828
|
-
line
|
|
829
|
-
};
|
|
861
|
+
yield { counter, line };
|
|
830
862
|
counter++;
|
|
831
863
|
}
|
|
832
864
|
}
|
|
@@ -834,10 +866,7 @@ var __exports__ = (() => {
|
|
|
834
866
|
// ../loader-utils/src/lib/iterators/async-iteration.ts
|
|
835
867
|
async function forEach(iterator, visitor) {
|
|
836
868
|
while (true) {
|
|
837
|
-
const {
|
|
838
|
-
done,
|
|
839
|
-
value
|
|
840
|
-
} = await iterator.next();
|
|
869
|
+
const { done, value } = await iterator.next();
|
|
841
870
|
if (done) {
|
|
842
871
|
iterator.return();
|
|
843
872
|
return;
|
|
@@ -1101,43 +1130,56 @@ var __exports__ = (() => {
|
|
|
1101
1130
|
var STAT_ACTIVE_REQUESTS_EVER = "Active Requests Ever";
|
|
1102
1131
|
var DEFAULT_PROPS2 = {
|
|
1103
1132
|
id: "request-scheduler",
|
|
1133
|
+
/** Specifies if the request scheduler should throttle incoming requests, mainly for comparative testing. */
|
|
1104
1134
|
throttleRequests: true,
|
|
1105
|
-
|
|
1135
|
+
/** The maximum number of simultaneous active requests. Un-throttled requests do not observe this limit. */
|
|
1136
|
+
maxRequests: 6,
|
|
1137
|
+
/**
|
|
1138
|
+
* Specifies a debounce time, in milliseconds. All requests are queued, until no new requests have
|
|
1139
|
+
* been added to the queue for this amount of time.
|
|
1140
|
+
*/
|
|
1141
|
+
debounceTime: 0
|
|
1106
1142
|
};
|
|
1107
1143
|
var RequestScheduler = class {
|
|
1108
|
-
activeRequestCount = 0;
|
|
1109
|
-
requestQueue = [];
|
|
1110
|
-
requestMap = /* @__PURE__ */ new Map();
|
|
1111
|
-
deferredUpdate = null;
|
|
1112
1144
|
constructor(props = {}) {
|
|
1113
|
-
this.
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
this.
|
|
1118
|
-
|
|
1119
|
-
});
|
|
1145
|
+
this.activeRequestCount = 0;
|
|
1146
|
+
/** Tracks the number of active requests and prioritizes/cancels queued requests. */
|
|
1147
|
+
this.requestQueue = [];
|
|
1148
|
+
this.requestMap = /* @__PURE__ */ new Map();
|
|
1149
|
+
this.updateTimer = null;
|
|
1150
|
+
this.props = { ...DEFAULT_PROPS2, ...props };
|
|
1151
|
+
this.stats = new Stats({ id: this.props.id });
|
|
1120
1152
|
this.stats.get(STAT_QUEUED_REQUESTS);
|
|
1121
1153
|
this.stats.get(STAT_ACTIVE_REQUESTS);
|
|
1122
1154
|
this.stats.get(STAT_CANCELLED_REQUESTS);
|
|
1123
1155
|
this.stats.get(STAT_QUEUED_REQUESTS_EVER);
|
|
1124
1156
|
this.stats.get(STAT_ACTIVE_REQUESTS_EVER);
|
|
1125
1157
|
}
|
|
1158
|
+
/**
|
|
1159
|
+
* Called by an application that wants to issue a request, without having it deeply queued by the browser
|
|
1160
|
+
*
|
|
1161
|
+
* When the returned promise resolved, it is OK for the application to issue a request.
|
|
1162
|
+
* The promise resolves to an object that contains a `done` method.
|
|
1163
|
+
* When the application's request has completed (or failed), the application must call the `done` function
|
|
1164
|
+
*
|
|
1165
|
+
* @param handle
|
|
1166
|
+
* @param getPriority will be called when request "slots" open up,
|
|
1167
|
+
* allowing the caller to update priority or cancel the request
|
|
1168
|
+
* Highest priority executes first, priority < 0 cancels the request
|
|
1169
|
+
* @returns a promise
|
|
1170
|
+
* - resolves to a object (with a `done` field) when the request can be issued without queueing,
|
|
1171
|
+
* - resolves to `null` if the request has been cancelled (by the callback return < 0).
|
|
1172
|
+
* In this case the application should not issue the request
|
|
1173
|
+
*/
|
|
1126
1174
|
scheduleRequest(handle, getPriority = () => 0) {
|
|
1127
1175
|
if (!this.props.throttleRequests) {
|
|
1128
|
-
return Promise.resolve({
|
|
1129
|
-
|
|
1130
|
-
}
|
|
1131
|
-
});
|
|
1176
|
+
return Promise.resolve({ done: () => {
|
|
1177
|
+
} });
|
|
1132
1178
|
}
|
|
1133
1179
|
if (this.requestMap.has(handle)) {
|
|
1134
1180
|
return this.requestMap.get(handle);
|
|
1135
1181
|
}
|
|
1136
|
-
const request = {
|
|
1137
|
-
handle,
|
|
1138
|
-
priority: 0,
|
|
1139
|
-
getPriority
|
|
1140
|
-
};
|
|
1182
|
+
const request = { handle, priority: 0, getPriority };
|
|
1141
1183
|
const promise = new Promise((resolve2) => {
|
|
1142
1184
|
request.resolve = resolve2;
|
|
1143
1185
|
return request;
|
|
@@ -1147,11 +1189,9 @@ var __exports__ = (() => {
|
|
|
1147
1189
|
this._issueNewRequests();
|
|
1148
1190
|
return promise;
|
|
1149
1191
|
}
|
|
1192
|
+
// PRIVATE
|
|
1150
1193
|
_issueRequest(request) {
|
|
1151
|
-
const {
|
|
1152
|
-
handle,
|
|
1153
|
-
resolve: resolve2
|
|
1154
|
-
} = request;
|
|
1194
|
+
const { handle, resolve: resolve2 } = request;
|
|
1155
1195
|
let isDone = false;
|
|
1156
1196
|
const done = () => {
|
|
1157
1197
|
if (!isDone) {
|
|
@@ -1162,19 +1202,21 @@ var __exports__ = (() => {
|
|
|
1162
1202
|
}
|
|
1163
1203
|
};
|
|
1164
1204
|
this.activeRequestCount++;
|
|
1165
|
-
return resolve2 ? resolve2({
|
|
1166
|
-
done
|
|
1167
|
-
}) : Promise.resolve({
|
|
1168
|
-
done
|
|
1169
|
-
});
|
|
1205
|
+
return resolve2 ? resolve2({ done }) : Promise.resolve({ done });
|
|
1170
1206
|
}
|
|
1207
|
+
/** We check requests asynchronously, to prevent multiple updates */
|
|
1171
1208
|
_issueNewRequests() {
|
|
1172
|
-
if (
|
|
1173
|
-
|
|
1209
|
+
if (this.updateTimer !== null) {
|
|
1210
|
+
clearTimeout(this.updateTimer);
|
|
1174
1211
|
}
|
|
1212
|
+
this.updateTimer = setTimeout(() => this._issueNewRequestsAsync(), this.props.debounceTime);
|
|
1175
1213
|
}
|
|
1214
|
+
/** Refresh all requests */
|
|
1176
1215
|
_issueNewRequestsAsync() {
|
|
1177
|
-
this.
|
|
1216
|
+
if (this.updateTimer !== null) {
|
|
1217
|
+
clearTimeout(this.updateTimer);
|
|
1218
|
+
}
|
|
1219
|
+
this.updateTimer = null;
|
|
1178
1220
|
const freeSlots = Math.max(this.props.maxRequests - this.activeRequestCount, 0);
|
|
1179
1221
|
if (freeSlots === 0) {
|
|
1180
1222
|
return;
|
|
@@ -1187,6 +1229,7 @@ var __exports__ = (() => {
|
|
|
1187
1229
|
}
|
|
1188
1230
|
}
|
|
1189
1231
|
}
|
|
1232
|
+
/** Ensure all requests have updated priorities, and that no longer valid requests are cancelled */
|
|
1190
1233
|
_updateAllRequests() {
|
|
1191
1234
|
const requestQueue = this.requestQueue;
|
|
1192
1235
|
for (let i = 0; i < requestQueue.length; ++i) {
|
|
@@ -1199,6 +1242,7 @@ var __exports__ = (() => {
|
|
|
1199
1242
|
}
|
|
1200
1243
|
requestQueue.sort((a, b) => a.priority - b.priority);
|
|
1201
1244
|
}
|
|
1245
|
+
/** Update a single request by calling the callback */
|
|
1202
1246
|
_updateRequest(request) {
|
|
1203
1247
|
request.priority = request.getPriority(request.handle);
|
|
1204
1248
|
if (request.priority < 0) {
|
|
@@ -1232,7 +1276,7 @@ var __exports__ = (() => {
|
|
|
1232
1276
|
}
|
|
1233
1277
|
|
|
1234
1278
|
// ../loader-utils/src/json-loader.ts
|
|
1235
|
-
var VERSION2 =
|
|
1279
|
+
var VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
1236
1280
|
var JSONLoader = {
|
|
1237
1281
|
name: "JSON",
|
|
1238
1282
|
id: "json",
|
|
@@ -1452,10 +1496,10 @@ var __exports__ = (() => {
|
|
|
1452
1496
|
// ../loader-utils/src/lib/files/node-file-facade.ts
|
|
1453
1497
|
var NOT_IMPLEMENTED = new Error("Not implemented");
|
|
1454
1498
|
var NodeFileFacade = class {
|
|
1455
|
-
size = 0;
|
|
1456
|
-
bigsize = 0n;
|
|
1457
|
-
url = "";
|
|
1458
1499
|
constructor(url, flags, mode) {
|
|
1500
|
+
this.size = 0;
|
|
1501
|
+
this.bigsize = 0n;
|
|
1502
|
+
this.url = "";
|
|
1459
1503
|
if (globalThis.loaders?.NodeFile) {
|
|
1460
1504
|
return new globalThis.loaders.NodeFile(url, flags, mode);
|
|
1461
1505
|
}
|
|
@@ -1464,21 +1508,27 @@ var __exports__ = (() => {
|
|
|
1464
1508
|
}
|
|
1465
1509
|
throw new Error("Can't instantiate NodeFile. Make sure to import @loaders.gl/polyfills first.");
|
|
1466
1510
|
}
|
|
1511
|
+
/** Read data */
|
|
1467
1512
|
async read(start, end) {
|
|
1468
1513
|
throw NOT_IMPLEMENTED;
|
|
1469
1514
|
}
|
|
1515
|
+
/** Write to file. The number of bytes written will be returned */
|
|
1470
1516
|
async write(arrayBuffer, offset, length) {
|
|
1471
1517
|
throw NOT_IMPLEMENTED;
|
|
1472
1518
|
}
|
|
1519
|
+
/** Get information about file */
|
|
1473
1520
|
async stat() {
|
|
1474
1521
|
throw NOT_IMPLEMENTED;
|
|
1475
1522
|
}
|
|
1523
|
+
/** Truncates the file descriptor. Only available on NodeFile. */
|
|
1476
1524
|
async truncate(length) {
|
|
1477
1525
|
throw NOT_IMPLEMENTED;
|
|
1478
1526
|
}
|
|
1527
|
+
/** Append data to a file. Only available on NodeFile. */
|
|
1479
1528
|
async append(data) {
|
|
1480
1529
|
throw NOT_IMPLEMENTED;
|
|
1481
1530
|
}
|
|
1531
|
+
/** Close the file */
|
|
1482
1532
|
async close() {
|
|
1483
1533
|
}
|
|
1484
1534
|
};
|
|
@@ -1604,12 +1654,8 @@ var __exports__ = (() => {
|
|
|
1604
1654
|
if (typeof resource === "string") {
|
|
1605
1655
|
resource = new TextEncoder().encode(resource);
|
|
1606
1656
|
}
|
|
1607
|
-
const response = new Response(resource, {
|
|
1608
|
-
|
|
1609
|
-
});
|
|
1610
|
-
Object.defineProperty(response, "url", {
|
|
1611
|
-
value: url
|
|
1612
|
-
});
|
|
1657
|
+
const response = new Response(resource, { headers });
|
|
1658
|
+
Object.defineProperty(response, "url", { value: url });
|
|
1613
1659
|
return response;
|
|
1614
1660
|
}
|
|
1615
1661
|
async function checkResponse(response) {
|
|
@@ -2230,9 +2276,7 @@ var __exports__ = (() => {
|
|
|
2230
2276
|
});
|
|
2231
2277
|
|
|
2232
2278
|
// src/lib/loader-utils/loggers.ts
|
|
2233
|
-
var probeLog = new Log({
|
|
2234
|
-
id: "loaders.gl"
|
|
2235
|
-
});
|
|
2279
|
+
var probeLog = new Log({ id: "loaders.gl" });
|
|
2236
2280
|
var NullLog = class {
|
|
2237
2281
|
log() {
|
|
2238
2282
|
return () => {
|
|
@@ -2271,29 +2315,39 @@ var __exports__ = (() => {
|
|
|
2271
2315
|
|
|
2272
2316
|
// src/lib/loader-utils/option-defaults.ts
|
|
2273
2317
|
var DEFAULT_LOADER_OPTIONS = {
|
|
2318
|
+
// baseUri
|
|
2274
2319
|
fetch: null,
|
|
2275
2320
|
mimeType: void 0,
|
|
2276
2321
|
nothrow: false,
|
|
2277
2322
|
log: new ConsoleLog(),
|
|
2323
|
+
// A probe.gl compatible (`log.log()()` syntax) that just logs to console
|
|
2278
2324
|
useLocalLibraries: false,
|
|
2279
2325
|
CDN: "https://unpkg.com/@loaders.gl",
|
|
2280
2326
|
worker: true,
|
|
2327
|
+
// By default, use worker if provided by loader.
|
|
2281
2328
|
maxConcurrency: 3,
|
|
2329
|
+
// How many worker instances should be created for each loader.
|
|
2282
2330
|
maxMobileConcurrency: 1,
|
|
2331
|
+
// How many worker instances should be created for each loader on mobile devices.
|
|
2283
2332
|
reuseWorkers: isBrowser,
|
|
2333
|
+
// By default reuse workers in browser (Node.js refuses to terminate if browsers are running)
|
|
2284
2334
|
_nodeWorkers: false,
|
|
2335
|
+
// By default do not support node workers
|
|
2285
2336
|
_workerType: "",
|
|
2337
|
+
// 'test' to use locally generated workers
|
|
2286
2338
|
limit: 0,
|
|
2287
2339
|
_limitMB: 0,
|
|
2288
2340
|
batchSize: "auto",
|
|
2289
2341
|
batchDebounceMs: 0,
|
|
2290
2342
|
metadata: false,
|
|
2343
|
+
// TODO - currently only implemented for parseInBatches, adds initial metadata batch,
|
|
2291
2344
|
transforms: []
|
|
2292
2345
|
};
|
|
2293
2346
|
var REMOVED_LOADER_OPTIONS = {
|
|
2294
2347
|
throws: "nothrow",
|
|
2295
2348
|
dataType: "(no longer used)",
|
|
2296
2349
|
uri: "baseUri",
|
|
2350
|
+
// Warn if fetch options are used on top-level
|
|
2297
2351
|
method: "fetch.method",
|
|
2298
2352
|
headers: "fetch.headers",
|
|
2299
2353
|
body: "fetch.body",
|
|
@@ -2311,17 +2365,15 @@ var __exports__ = (() => {
|
|
|
2311
2365
|
// src/lib/loader-utils/option-utils.ts
|
|
2312
2366
|
function getGlobalLoaderState() {
|
|
2313
2367
|
globalThis.loaders = globalThis.loaders || {};
|
|
2314
|
-
const {
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2368
|
+
const { loaders } = globalThis;
|
|
2369
|
+
if (!loaders._state) {
|
|
2370
|
+
loaders._state = {};
|
|
2371
|
+
}
|
|
2318
2372
|
return loaders._state;
|
|
2319
2373
|
}
|
|
2320
2374
|
function getGlobalLoaderOptions() {
|
|
2321
2375
|
const state = getGlobalLoaderState();
|
|
2322
|
-
state.globalOptions = state.globalOptions || {
|
|
2323
|
-
...DEFAULT_LOADER_OPTIONS
|
|
2324
|
-
};
|
|
2376
|
+
state.globalOptions = state.globalOptions || { ...DEFAULT_LOADER_OPTIONS };
|
|
2325
2377
|
return state.globalOptions;
|
|
2326
2378
|
}
|
|
2327
2379
|
function setGlobalOptions(options) {
|
|
@@ -2353,10 +2405,14 @@ var __exports__ = (() => {
|
|
|
2353
2405
|
const isWorkerUrlOption = key === "workerUrl" && id;
|
|
2354
2406
|
if (!(key in defaultOptions) && !isBaseUriOption && !isWorkerUrlOption) {
|
|
2355
2407
|
if (key in deprecatedOptions) {
|
|
2356
|
-
probeLog.warn(
|
|
2408
|
+
probeLog.warn(
|
|
2409
|
+
`${loaderName} loader option '${prefix}${key}' no longer supported, use '${deprecatedOptions[key]}'`
|
|
2410
|
+
)();
|
|
2357
2411
|
} else if (!isSubOptions) {
|
|
2358
2412
|
const suggestion = findSimilarOption(key, loaders);
|
|
2359
|
-
probeLog.warn(
|
|
2413
|
+
probeLog.warn(
|
|
2414
|
+
`${loaderName} loader option '${prefix}${key}' not recognized. ${suggestion}`
|
|
2415
|
+
)();
|
|
2360
2416
|
}
|
|
2361
2417
|
}
|
|
2362
2418
|
}
|
|
@@ -2380,9 +2436,7 @@ var __exports__ = (() => {
|
|
|
2380
2436
|
}
|
|
2381
2437
|
function normalizeOptionsInternal(loader, options, url) {
|
|
2382
2438
|
const loaderDefaultOptions = loader.options || {};
|
|
2383
|
-
const mergedOptions = {
|
|
2384
|
-
...loaderDefaultOptions
|
|
2385
|
-
};
|
|
2439
|
+
const mergedOptions = { ...loaderDefaultOptions };
|
|
2386
2440
|
addUrlOptions(mergedOptions, url);
|
|
2387
2441
|
if (mergedOptions.log === null) {
|
|
2388
2442
|
mergedOptions.log = new NullLog();
|
|
@@ -2432,10 +2486,7 @@ var __exports__ = (() => {
|
|
|
2432
2486
|
loader = loader[0];
|
|
2433
2487
|
loader = {
|
|
2434
2488
|
...loader,
|
|
2435
|
-
options: {
|
|
2436
|
-
...loader.options,
|
|
2437
|
-
...options
|
|
2438
|
-
}
|
|
2489
|
+
options: { ...loader.options, ...options }
|
|
2439
2490
|
};
|
|
2440
2491
|
}
|
|
2441
2492
|
if (loader?.parseTextSync || loader?.parseText) {
|
|
@@ -2472,9 +2523,7 @@ var __exports__ = (() => {
|
|
|
2472
2523
|
}
|
|
2473
2524
|
|
|
2474
2525
|
// src/lib/utils/log.ts
|
|
2475
|
-
var log = new Log({
|
|
2476
|
-
id: "loaders.gl"
|
|
2477
|
-
});
|
|
2526
|
+
var log = new Log({ id: "loaders.gl" });
|
|
2478
2527
|
|
|
2479
2528
|
// src/lib/api/select-loader.ts
|
|
2480
2529
|
var EXT_PATTERN = /\.([^.]+)$/;
|
|
@@ -2482,10 +2531,7 @@ var __exports__ = (() => {
|
|
|
2482
2531
|
if (!validHTTPResponse(data)) {
|
|
2483
2532
|
return null;
|
|
2484
2533
|
}
|
|
2485
|
-
let loader = selectLoaderSync(data, loaders, {
|
|
2486
|
-
...options,
|
|
2487
|
-
nothrow: true
|
|
2488
|
-
}, context);
|
|
2534
|
+
let loader = selectLoaderSync(data, loaders, { ...options, nothrow: true }, context);
|
|
2489
2535
|
if (loader) {
|
|
2490
2536
|
return loader;
|
|
2491
2537
|
}
|
|
@@ -2682,9 +2728,7 @@ var __exports__ = (() => {
|
|
|
2682
2728
|
// src/iterators/make-iterator/make-array-buffer-iterator.ts
|
|
2683
2729
|
var DEFAULT_CHUNK_SIZE2 = 256 * 1024;
|
|
2684
2730
|
function* makeArrayBufferIterator(arrayBuffer, options = {}) {
|
|
2685
|
-
const {
|
|
2686
|
-
chunkSize = DEFAULT_CHUNK_SIZE2
|
|
2687
|
-
} = options;
|
|
2731
|
+
const { chunkSize = DEFAULT_CHUNK_SIZE2 } = options;
|
|
2688
2732
|
let byteOffset = 0;
|
|
2689
2733
|
while (byteOffset < arrayBuffer.byteLength) {
|
|
2690
2734
|
const chunkByteLength = Math.min(arrayBuffer.byteLength - byteOffset, chunkSize);
|
|
@@ -2723,10 +2767,7 @@ var __exports__ = (() => {
|
|
|
2723
2767
|
if (options?._streamReadAhead) {
|
|
2724
2768
|
nextBatchPromise = reader.read();
|
|
2725
2769
|
}
|
|
2726
|
-
const {
|
|
2727
|
-
done,
|
|
2728
|
-
value
|
|
2729
|
-
} = await currentBatchPromise;
|
|
2770
|
+
const { done, value } = await currentBatchPromise;
|
|
2730
2771
|
if (done) {
|
|
2731
2772
|
return;
|
|
2732
2773
|
}
|
|
@@ -2922,11 +2963,12 @@ var __exports__ = (() => {
|
|
|
2922
2963
|
return null;
|
|
2923
2964
|
}
|
|
2924
2965
|
options = normalizeOptions(options, loader, candidateLoaders, url);
|
|
2925
|
-
context = getLoaderContext(
|
|
2926
|
-
|
|
2927
|
-
_parse: parse,
|
|
2928
|
-
|
|
2929
|
-
|
|
2966
|
+
context = getLoaderContext(
|
|
2967
|
+
// @ts-expect-error
|
|
2968
|
+
{ url, _parse: parse, loaders: candidateLoaders },
|
|
2969
|
+
options,
|
|
2970
|
+
context || null
|
|
2971
|
+
);
|
|
2930
2972
|
return await parseWithLoader(loader, data, options, context);
|
|
2931
2973
|
}
|
|
2932
2974
|
async function parseWithLoader(loader, data, options, context) {
|
|
@@ -2934,24 +2976,9 @@ var __exports__ = (() => {
|
|
|
2934
2976
|
options = mergeLoaderOptions(loader.options, options);
|
|
2935
2977
|
if (isResponse(data)) {
|
|
2936
2978
|
const response = data;
|
|
2937
|
-
const {
|
|
2938
|
-
ok,
|
|
2939
|
-
redirected,
|
|
2940
|
-
status,
|
|
2941
|
-
statusText,
|
|
2942
|
-
type,
|
|
2943
|
-
url
|
|
2944
|
-
} = response;
|
|
2979
|
+
const { ok, redirected, status, statusText, type, url } = response;
|
|
2945
2980
|
const headers = Object.fromEntries(response.headers.entries());
|
|
2946
|
-
context.response = {
|
|
2947
|
-
headers,
|
|
2948
|
-
ok,
|
|
2949
|
-
redirected,
|
|
2950
|
-
status,
|
|
2951
|
-
statusText,
|
|
2952
|
-
type,
|
|
2953
|
-
url
|
|
2954
|
-
};
|
|
2981
|
+
context.response = { headers, ok, redirected, status, statusText, type, url };
|
|
2955
2982
|
}
|
|
2956
2983
|
data = await getArrayBufferOrStringFromData(data, loader, options);
|
|
2957
2984
|
const loaderWithParser = loader;
|
|
@@ -2990,12 +3017,11 @@ var __exports__ = (() => {
|
|
|
2990
3017
|
const parse2 = () => {
|
|
2991
3018
|
throw new Error("parseSync called parse (which is async");
|
|
2992
3019
|
};
|
|
2993
|
-
context = getLoaderContext(
|
|
2994
|
-
url,
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
}, options, context || null);
|
|
3020
|
+
context = getLoaderContext(
|
|
3021
|
+
{ url, _parseSync: parse2, _parse: parse2, loaders },
|
|
3022
|
+
options,
|
|
3023
|
+
context || null
|
|
3024
|
+
);
|
|
2999
3025
|
return parseWithLoaderSync(loader, data, options, context);
|
|
3000
3026
|
}
|
|
3001
3027
|
function parseWithLoaderSync(loader, data, options, context) {
|
|
@@ -3006,7 +3032,9 @@ var __exports__ = (() => {
|
|
|
3006
3032
|
if (loader.parseSync && data instanceof ArrayBuffer) {
|
|
3007
3033
|
return loader.parseSync(data, options, context);
|
|
3008
3034
|
}
|
|
3009
|
-
throw new Error(
|
|
3035
|
+
throw new Error(
|
|
3036
|
+
`${loader.name} loader: 'parseSync' not supported by this loader, use 'parse' instead. ${context.url || ""}`
|
|
3037
|
+
);
|
|
3010
3038
|
}
|
|
3011
3039
|
|
|
3012
3040
|
// ../schema/src/lib/table/simple-table/table-accessors.ts
|
|
@@ -3048,11 +3076,7 @@ var __exports__ = (() => {
|
|
|
3048
3076
|
|
|
3049
3077
|
// ../schema/src/lib/table/simple-table/make-table-from-batches.ts
|
|
3050
3078
|
function makeBatchFromTable(table) {
|
|
3051
|
-
return {
|
|
3052
|
-
...table,
|
|
3053
|
-
length: getTableLength(table),
|
|
3054
|
-
batchType: "data"
|
|
3055
|
-
};
|
|
3079
|
+
return { ...table, length: getTableLength(table), batchType: "data" };
|
|
3056
3080
|
}
|
|
3057
3081
|
|
|
3058
3082
|
// src/lib/api/parse-in-batches.ts
|
|
@@ -3071,12 +3095,11 @@ var __exports__ = (() => {
|
|
|
3071
3095
|
return [];
|
|
3072
3096
|
}
|
|
3073
3097
|
options = normalizeOptions(options, loader, loaderArray, url);
|
|
3074
|
-
context = getLoaderContext(
|
|
3075
|
-
url,
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
}, options, context || null);
|
|
3098
|
+
context = getLoaderContext(
|
|
3099
|
+
{ url, _parseInBatches: parseInBatches, _parse: parse, loaders: loaderArray },
|
|
3100
|
+
options,
|
|
3101
|
+
context || null
|
|
3102
|
+
);
|
|
3080
3103
|
return await parseWithLoaderInBatches(loader, data, options, context);
|
|
3081
3104
|
}
|
|
3082
3105
|
async function parseWithLoaderInBatches(loader, data, options, context) {
|
|
@@ -3091,6 +3114,7 @@ var __exports__ = (() => {
|
|
|
3091
3114
|
_loader: loader,
|
|
3092
3115
|
_context: context
|
|
3093
3116
|
},
|
|
3117
|
+
// Populate with some default fields to avoid crashing
|
|
3094
3118
|
data: [],
|
|
3095
3119
|
bytesUsed: 0
|
|
3096
3120
|
};
|
|
@@ -3110,10 +3134,13 @@ var __exports__ = (() => {
|
|
|
3110
3134
|
}
|
|
3111
3135
|
async function* parseChunkInBatches(transformedIterator, loader, options, context) {
|
|
3112
3136
|
const arrayBuffer = await concatenateArrayBuffersAsync(transformedIterator);
|
|
3113
|
-
const parsedData = await parse(
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3137
|
+
const parsedData = await parse(
|
|
3138
|
+
arrayBuffer,
|
|
3139
|
+
loader,
|
|
3140
|
+
// TODO - Hack: supply loaders MIME type to ensure we match it
|
|
3141
|
+
{ ...options, mimeType: loader.mimeTypes[0] },
|
|
3142
|
+
context
|
|
3143
|
+
);
|
|
3117
3144
|
const batch = convertDataToBatch(parsedData, loader);
|
|
3118
3145
|
yield batch;
|
|
3119
3146
|
}
|
|
@@ -3172,7 +3199,9 @@ var __exports__ = (() => {
|
|
|
3172
3199
|
if (!Array.isArray(files)) {
|
|
3173
3200
|
return loadOneFileInBatches(files, loadersArray, options || {}, fetch2);
|
|
3174
3201
|
}
|
|
3175
|
-
const promises = files.map(
|
|
3202
|
+
const promises = files.map(
|
|
3203
|
+
(file) => loadOneFileInBatches(file, loadersArray, options || {}, fetch2)
|
|
3204
|
+
);
|
|
3176
3205
|
return promises;
|
|
3177
3206
|
}
|
|
3178
3207
|
async function loadOneFileInBatches(file, loaders, options, fetch2) {
|
|
@@ -3221,21 +3250,14 @@ var __exports__ = (() => {
|
|
|
3221
3250
|
throw new Error("Writer could not encode data in batches");
|
|
3222
3251
|
}
|
|
3223
3252
|
function getIterator(data) {
|
|
3224
|
-
const dataIterator = [{
|
|
3225
|
-
...data,
|
|
3226
|
-
start: 0,
|
|
3227
|
-
end: data.length
|
|
3228
|
-
}];
|
|
3253
|
+
const dataIterator = [{ ...data, start: 0, end: data.length }];
|
|
3229
3254
|
return dataIterator;
|
|
3230
3255
|
}
|
|
3231
3256
|
|
|
3232
3257
|
// src/lib/api/encode.ts
|
|
3233
3258
|
async function encode(data, writer, options) {
|
|
3234
3259
|
const globalOptions = getGlobalLoaderOptions();
|
|
3235
|
-
options = {
|
|
3236
|
-
...globalOptions,
|
|
3237
|
-
...options
|
|
3238
|
-
};
|
|
3260
|
+
options = { ...globalOptions, ...options };
|
|
3239
3261
|
if (writer.encodeURLtoURL) {
|
|
3240
3262
|
return encodeWithCommandLineTool(writer, data, options);
|
|
3241
3263
|
}
|
|
@@ -3305,11 +3327,7 @@ var __exports__ = (() => {
|
|
|
3305
3327
|
return response.arrayBuffer();
|
|
3306
3328
|
}
|
|
3307
3329
|
function getIterator2(data) {
|
|
3308
|
-
const dataIterator = [{
|
|
3309
|
-
...data,
|
|
3310
|
-
start: 0,
|
|
3311
|
-
end: data.length
|
|
3312
|
-
}];
|
|
3330
|
+
const dataIterator = [{ ...data, start: 0, end: data.length }];
|
|
3313
3331
|
return dataIterator;
|
|
3314
3332
|
}
|
|
3315
3333
|
function getTemporaryFilename(filename2) {
|
|
@@ -3322,34 +3340,40 @@ var __exports__ = (() => {
|
|
|
3322
3340
|
return globalThis.loaders.makeNodeStream(source, options);
|
|
3323
3341
|
}
|
|
3324
3342
|
const iterator = source[Symbol.asyncIterator] ? source[Symbol.asyncIterator]() : source[Symbol.iterator]();
|
|
3325
|
-
return new ReadableStream(
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3343
|
+
return new ReadableStream(
|
|
3344
|
+
{
|
|
3345
|
+
// Create a byte stream (enables `Response(stream).arrayBuffer()`)
|
|
3346
|
+
// Only supported on Chrome
|
|
3347
|
+
// See: https://developer.mozilla.org/en-US/docs/Web/API/ReadableByteStreamController
|
|
3348
|
+
// @ts-ignore
|
|
3349
|
+
type: "bytes",
|
|
3350
|
+
async pull(controller) {
|
|
3351
|
+
try {
|
|
3352
|
+
const { done, value } = await iterator.next();
|
|
3353
|
+
if (done) {
|
|
3354
|
+
controller.close();
|
|
3355
|
+
} else {
|
|
3356
|
+
controller.enqueue(new Uint8Array(value));
|
|
3357
|
+
}
|
|
3358
|
+
} catch (error) {
|
|
3359
|
+
controller.error(error);
|
|
3337
3360
|
}
|
|
3338
|
-
}
|
|
3339
|
-
|
|
3361
|
+
},
|
|
3362
|
+
async cancel() {
|
|
3363
|
+
await iterator?.return?.();
|
|
3340
3364
|
}
|
|
3341
3365
|
},
|
|
3342
|
-
|
|
3343
|
-
|
|
3366
|
+
// options: QueingStrategy<Uint8Array>
|
|
3367
|
+
{
|
|
3368
|
+
// This is bytes, not chunks
|
|
3369
|
+
highWaterMark: 2 ** 24,
|
|
3370
|
+
...options
|
|
3344
3371
|
}
|
|
3345
|
-
|
|
3346
|
-
highWaterMark: 2 ** 24,
|
|
3347
|
-
...options
|
|
3348
|
-
});
|
|
3372
|
+
);
|
|
3349
3373
|
}
|
|
3350
3374
|
|
|
3351
3375
|
// src/null-loader.ts
|
|
3352
|
-
var VERSION4 =
|
|
3376
|
+
var VERSION4 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
3353
3377
|
var NullWorkerLoader = {
|
|
3354
3378
|
name: "Null loader",
|
|
3355
3379
|
id: "null",
|
|
@@ -3416,10 +3440,7 @@ var __exports__ = (() => {
|
|
|
3416
3440
|
}
|
|
3417
3441
|
async function read(controller, reader, loadedBytes, totalBytes, onProgress, onDone, onError) {
|
|
3418
3442
|
try {
|
|
3419
|
-
const {
|
|
3420
|
-
done,
|
|
3421
|
-
value
|
|
3422
|
-
} = await reader.read();
|
|
3443
|
+
const { done, value } = await reader.read();
|
|
3423
3444
|
if (done) {
|
|
3424
3445
|
onDone();
|
|
3425
3446
|
controller.close();
|
|
@@ -3427,10 +3448,7 @@ var __exports__ = (() => {
|
|
|
3427
3448
|
}
|
|
3428
3449
|
loadedBytes += value.byteLength;
|
|
3429
3450
|
const percent = Math.round(loadedBytes / totalBytes * 100);
|
|
3430
|
-
onProgress(percent, {
|
|
3431
|
-
loadedBytes,
|
|
3432
|
-
totalBytes
|
|
3433
|
-
});
|
|
3451
|
+
onProgress(percent, { loadedBytes, totalBytes });
|
|
3434
3452
|
controller.enqueue(value);
|
|
3435
3453
|
await read(controller, reader, loadedBytes, totalBytes, onProgress, onDone, onError);
|
|
3436
3454
|
} catch (error) {
|
|
@@ -3441,10 +3459,15 @@ var __exports__ = (() => {
|
|
|
3441
3459
|
|
|
3442
3460
|
// src/lib/filesystems/browser-filesystem.ts
|
|
3443
3461
|
var BrowserFileSystem = class {
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3462
|
+
/**
|
|
3463
|
+
* A FileSystem API wrapper around a list of browser 'File' objects
|
|
3464
|
+
* @param files
|
|
3465
|
+
* @param options
|
|
3466
|
+
*/
|
|
3447
3467
|
constructor(files, options) {
|
|
3468
|
+
this.files = {};
|
|
3469
|
+
this.lowerCaseFiles = {};
|
|
3470
|
+
this.usedFiles = {};
|
|
3448
3471
|
this._fetch = options?.fetch || fetch;
|
|
3449
3472
|
for (let i = 0; i < files.length; ++i) {
|
|
3450
3473
|
const file = files[i];
|
|
@@ -3454,16 +3477,18 @@ var __exports__ = (() => {
|
|
|
3454
3477
|
}
|
|
3455
3478
|
this.fetch = this.fetch.bind(this);
|
|
3456
3479
|
}
|
|
3480
|
+
// implements IFileSystem
|
|
3481
|
+
/**
|
|
3482
|
+
* Implementation of fetch against this file system
|
|
3483
|
+
* Delegates to global fetch for http{s}:// or data://
|
|
3484
|
+
*/
|
|
3457
3485
|
async fetch(path, options) {
|
|
3458
3486
|
if (path.includes("://")) {
|
|
3459
3487
|
return this._fetch(path, options);
|
|
3460
3488
|
}
|
|
3461
3489
|
const file = this.files[path];
|
|
3462
3490
|
if (!file) {
|
|
3463
|
-
return new Response(path, {
|
|
3464
|
-
status: 400,
|
|
3465
|
-
statusText: "NOT FOUND"
|
|
3466
|
-
});
|
|
3491
|
+
return new Response(path, { status: 400, statusText: "NOT FOUND" });
|
|
3467
3492
|
}
|
|
3468
3493
|
const headers = new Headers(options?.headers);
|
|
3469
3494
|
const range = headers.get("Range");
|
|
@@ -3473,17 +3498,18 @@ var __exports__ = (() => {
|
|
|
3473
3498
|
const end = parseInt(bytes[2]);
|
|
3474
3499
|
const data = await file.slice(start, end).arrayBuffer();
|
|
3475
3500
|
const response2 = new Response(data);
|
|
3476
|
-
Object.defineProperty(response2, "url", {
|
|
3477
|
-
value: path
|
|
3478
|
-
});
|
|
3501
|
+
Object.defineProperty(response2, "url", { value: path });
|
|
3479
3502
|
return response2;
|
|
3480
3503
|
}
|
|
3481
3504
|
const response = new Response(file);
|
|
3482
|
-
Object.defineProperty(response, "url", {
|
|
3483
|
-
value: path
|
|
3484
|
-
});
|
|
3505
|
+
Object.defineProperty(response, "url", { value: path });
|
|
3485
3506
|
return response;
|
|
3486
3507
|
}
|
|
3508
|
+
/**
|
|
3509
|
+
* List filenames in this filesystem
|
|
3510
|
+
* @param dirname
|
|
3511
|
+
* @returns
|
|
3512
|
+
*/
|
|
3487
3513
|
async readdir(dirname2) {
|
|
3488
3514
|
const files = [];
|
|
3489
3515
|
for (const path in this.files) {
|
|
@@ -3491,23 +3517,31 @@ var __exports__ = (() => {
|
|
|
3491
3517
|
}
|
|
3492
3518
|
return files;
|
|
3493
3519
|
}
|
|
3520
|
+
/**
|
|
3521
|
+
* Return information (size) about files in this file system
|
|
3522
|
+
*/
|
|
3494
3523
|
async stat(path, options) {
|
|
3495
3524
|
const file = this.files[path];
|
|
3496
3525
|
if (!file) {
|
|
3497
3526
|
throw new Error(path);
|
|
3498
3527
|
}
|
|
3499
|
-
return {
|
|
3500
|
-
size: file.size
|
|
3501
|
-
};
|
|
3528
|
+
return { size: file.size };
|
|
3502
3529
|
}
|
|
3530
|
+
/**
|
|
3531
|
+
* Just removes the file from the list
|
|
3532
|
+
*/
|
|
3503
3533
|
async unlink(path) {
|
|
3504
3534
|
delete this.files[path];
|
|
3505
3535
|
delete this.lowerCaseFiles[path];
|
|
3506
3536
|
this.usedFiles[path] = true;
|
|
3507
3537
|
}
|
|
3538
|
+
// implements IRandomAccessFileSystem
|
|
3539
|
+
// RANDOM ACCESS
|
|
3508
3540
|
async openReadableFile(pathname, flags) {
|
|
3509
3541
|
return new BlobFile(this.files[pathname]);
|
|
3510
3542
|
}
|
|
3543
|
+
// PRIVATE
|
|
3544
|
+
// Supports case independent paths, and file usage tracking
|
|
3511
3545
|
_getFile(path, used) {
|
|
3512
3546
|
const file = this.files[path] || this.lowerCaseFiles[path];
|
|
3513
3547
|
if (file && used) {
|
|
@@ -3516,7 +3550,7 @@ var __exports__ = (() => {
|
|
|
3516
3550
|
return file;
|
|
3517
3551
|
}
|
|
3518
3552
|
};
|
|
3519
|
-
return __toCommonJS(
|
|
3553
|
+
return __toCommonJS(bundle_exports);
|
|
3520
3554
|
})();
|
|
3521
3555
|
return __exports__;
|
|
3522
3556
|
});
|