@loaders.gl/core 4.0.0-alpha.23 → 4.0.0-alpha.24
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/dist.min.js +40 -100
- package/dist/es5/lib/init.js +1 -1
- package/dist/es5/null-loader.js +1 -1
- package/dist/esm/lib/init.js +1 -1
- package/dist/esm/null-loader.js +1 -1
- package/dist/null-worker-node.js +1 -1
- package/dist/null-worker.js +1 -1
- package/package.json +4 -7
- package/dist/bundle.js +0 -5
- package/dist/core-addons/write-file-browser.js +0 -60
- package/dist/index.js +0 -105
- package/dist/iterators/batch-iterators/timed-batch-iterator.js +0 -22
- package/dist/iterators/make-iterator/make-array-buffer-iterator.js +0 -27
- package/dist/iterators/make-iterator/make-blob-iterator.js +0 -21
- package/dist/iterators/make-iterator/make-iterator.js +0 -37
- package/dist/iterators/make-iterator/make-stream-iterator.js +0 -96
- package/dist/iterators/make-iterator/make-string-iterator.js +0 -24
- package/dist/iterators/make-stream/make-dom-stream.js +0 -47
- package/dist/iterators/make-stream/make-node-stream.js +0 -85
- package/dist/javascript-utils/is-type.js +0 -41
- package/dist/lib/api/encode-table.js +0 -54
- package/dist/lib/api/encode.js +0 -121
- package/dist/lib/api/load-in-batches.js +0 -40
- package/dist/lib/api/load.js +0 -43
- package/dist/lib/api/loader-options.js +0 -7
- package/dist/lib/api/parse-in-batches.js +0 -117
- package/dist/lib/api/parse-sync.js +0 -54
- package/dist/lib/api/parse.js +0 -87
- package/dist/lib/api/register-loaders.js +0 -35
- package/dist/lib/api/save.js +0 -15
- package/dist/lib/api/select-loader.js +0 -258
- package/dist/lib/common.js +0 -2
- package/dist/lib/fetch/fetch-error-message.js +0 -25
- package/dist/lib/fetch/fetch-file.js +0 -61
- package/dist/lib/fetch/fetch-file.node.js +0 -57
- package/dist/lib/fetch/read-array-buffer.js +0 -41
- package/dist/lib/fetch/read-file.js +0 -29
- package/dist/lib/fetch/write-file.js +0 -22
- package/dist/lib/filesystems/browser-filesystem.js +0 -127
- package/dist/lib/filesystems/read-array-buffer.js +0 -29
- package/dist/lib/init.js +0 -17
- package/dist/lib/loader-utils/check-errors.js +0 -46
- package/dist/lib/loader-utils/get-data.js +0 -130
- package/dist/lib/loader-utils/get-fetch-function.js +0 -31
- package/dist/lib/loader-utils/loader-context.js +0 -59
- package/dist/lib/loader-utils/loggers.js +0 -41
- package/dist/lib/loader-utils/normalize-loader.js +0 -52
- package/dist/lib/loader-utils/option-defaults.js +0 -44
- package/dist/lib/loader-utils/option-utils.js +0 -162
- package/dist/lib/progress/fetch-progress.js +0 -60
- package/dist/lib/utils/log.js +0 -6
- package/dist/lib/utils/mime-type-utils.js +0 -42
- package/dist/lib/utils/resource-utils.js +0 -90
- package/dist/lib/utils/response-utils.js +0 -115
- package/dist/lib/utils/url-utils.js +0 -14
- package/dist/null-loader.js +0 -51
- package/dist/workers/null-worker.js +0 -5
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeStreamIterator = void 0;
|
|
4
|
-
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
5
|
-
/**
|
|
6
|
-
* Returns an async iterable that reads from a stream (works in both Node.js and browsers)
|
|
7
|
-
* @param stream stream to iterator over
|
|
8
|
-
*/
|
|
9
|
-
function makeStreamIterator(stream, options) {
|
|
10
|
-
return loader_utils_1.isBrowser
|
|
11
|
-
? makeBrowserStreamIterator(stream, options)
|
|
12
|
-
: makeNodeStreamIterator(stream, options);
|
|
13
|
-
}
|
|
14
|
-
exports.makeStreamIterator = makeStreamIterator;
|
|
15
|
-
/**
|
|
16
|
-
* Returns an async iterable that reads from a DOM (browser) stream
|
|
17
|
-
* @param stream stream to iterate from
|
|
18
|
-
* @see https://jakearchibald.com/2017/async-iterators-and-generators/#making-streams-iterate
|
|
19
|
-
*/
|
|
20
|
-
async function* makeBrowserStreamIterator(stream, options) {
|
|
21
|
-
// WhatWG: stream is supposed to have a `getIterator` method
|
|
22
|
-
// if (typeof stream.getIterator === 'function') {
|
|
23
|
-
// return stream.getIterator();
|
|
24
|
-
// }
|
|
25
|
-
// if (typeof stream[Symbol.asyncIterator] === 'function') {
|
|
26
|
-
// return makeToArrayBufferIterator(stream);
|
|
27
|
-
// }
|
|
28
|
-
// In the browser, we first need to get a lock on the stream
|
|
29
|
-
const reader = stream.getReader();
|
|
30
|
-
let nextBatchPromise;
|
|
31
|
-
try {
|
|
32
|
-
// eslint-disable-next-line no-constant-condition
|
|
33
|
-
while (true) {
|
|
34
|
-
const currentBatchPromise = nextBatchPromise || reader.read();
|
|
35
|
-
// Issue a read for an additional batch, while we await the next batch
|
|
36
|
-
// Idea is to make fetching happen in parallel with processing / parsing
|
|
37
|
-
if (options?._streamReadAhead) {
|
|
38
|
-
nextBatchPromise = reader.read();
|
|
39
|
-
}
|
|
40
|
-
// Read from the stream
|
|
41
|
-
// value is a Uint8Array
|
|
42
|
-
const { done, value } = await currentBatchPromise;
|
|
43
|
-
// Exit if we're done
|
|
44
|
-
if (done) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
// Else yield the chunk
|
|
48
|
-
yield (0, loader_utils_1.toArrayBuffer)(value);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
catch (error) {
|
|
52
|
-
// TODO - examples makes it look like this should always be called,
|
|
53
|
-
// but that generates exceptions so only call it if we do not reach the end
|
|
54
|
-
reader.releaseLock();
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Returns an async iterable that reads from a DOM (browser) stream
|
|
59
|
-
* @param stream stream to iterate from
|
|
60
|
-
* @note Requires Node.js >= 10
|
|
61
|
-
*/
|
|
62
|
-
async function* makeNodeStreamIterator(stream, options) {
|
|
63
|
-
// Hacky test for node version to ensure we don't call bad polyfills
|
|
64
|
-
// NODE 10+: stream is an asyncIterator
|
|
65
|
-
for await (const chunk of stream) {
|
|
66
|
-
yield (0, loader_utils_1.toArrayBuffer)(chunk); // Coerce each chunk to ArrayBuffer
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
/* TODO - remove NODE < 10
|
|
70
|
-
* @see https://github.com/bustle/streaming-iterables, MIT license
|
|
71
|
-
*
|
|
72
|
-
if (typeof stream[Symbol.asyncIterator] === 'function') {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// TODO - check if is this ever used in Node 10+?
|
|
77
|
-
// eslint-disable-next-line no-constant-condition
|
|
78
|
-
while (true) {
|
|
79
|
-
const data = stream.read();
|
|
80
|
-
if (data !== null) {
|
|
81
|
-
yield toArrayBuffer(data);
|
|
82
|
-
// eslint-disable-next-line no-continue
|
|
83
|
-
continue;
|
|
84
|
-
}
|
|
85
|
-
if (stream._readableState?.ended) {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
await onceReadable(stream);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
async function onceReadable(stream: Readable): Promise<any> {
|
|
92
|
-
return new Promise((resolve) => {
|
|
93
|
-
stream.once('readable', resolve);
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
*/
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeStringIterator = void 0;
|
|
4
|
-
const DEFAULT_CHUNK_SIZE = 256 * 1024;
|
|
5
|
-
/**
|
|
6
|
-
* Returns an iterator that breaks a big string into chunks and yields them one-by-one as ArrayBuffers
|
|
7
|
-
* @param blob string to iterate over
|
|
8
|
-
* @param options
|
|
9
|
-
* @param options.chunkSize
|
|
10
|
-
*/
|
|
11
|
-
function* makeStringIterator(string, options) {
|
|
12
|
-
const chunkSize = options?.chunkSize || DEFAULT_CHUNK_SIZE;
|
|
13
|
-
let offset = 0;
|
|
14
|
-
const textEncoder = new TextEncoder();
|
|
15
|
-
while (offset < string.length) {
|
|
16
|
-
// Create a chunk of the right size
|
|
17
|
-
const chunkLength = Math.min(string.length - offset, chunkSize);
|
|
18
|
-
const chunk = string.slice(offset, offset + chunkLength);
|
|
19
|
-
offset += chunkLength;
|
|
20
|
-
// yield an ArrayBuffer chunk
|
|
21
|
-
yield textEncoder.encode(chunk);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
exports.makeStringIterator = makeStringIterator;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeStream = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Builds a DOM stream from an iterator
|
|
6
|
-
* This stream is currently used in browsers only,
|
|
7
|
-
* but note that Web stream support is present in Node from Node 16
|
|
8
|
-
* https://nodejs.org/api/webstreams.html#webstreams_web_streams_api
|
|
9
|
-
*/
|
|
10
|
-
function makeStream(source, options) {
|
|
11
|
-
// TODO - add AsyncGenerator to parameter types?
|
|
12
|
-
const iterator = source[Symbol.asyncIterator]
|
|
13
|
-
? source[Symbol.asyncIterator]()
|
|
14
|
-
: source[Symbol.iterator]();
|
|
15
|
-
return new ReadableStream({
|
|
16
|
-
// Create a byte stream (enables `Response(stream).arrayBuffer()`)
|
|
17
|
-
// Only supported on Chrome
|
|
18
|
-
// See: https://developer.mozilla.org/en-US/docs/Web/API/ReadableByteStreamController
|
|
19
|
-
type: 'bytes',
|
|
20
|
-
async pull(controller) {
|
|
21
|
-
try {
|
|
22
|
-
const { done, value } = await iterator.next();
|
|
23
|
-
if (done) {
|
|
24
|
-
controller.close();
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
// TODO - ignores controller.desiredSize
|
|
28
|
-
// @ts-expect-error Unclear why value is not correctly typed
|
|
29
|
-
controller.enqueue(new Uint8Array(value));
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
catch (error) {
|
|
33
|
-
controller.error(error);
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
async cancel() {
|
|
37
|
-
await iterator?.return?.();
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
// options: QueingStrategy<Uint8Array>
|
|
41
|
-
{
|
|
42
|
-
// This is bytes, not chunks
|
|
43
|
-
highWaterMark: 2 ** 24,
|
|
44
|
-
...options
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
exports.makeStream = makeStream;
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.makeStream = void 0;
|
|
27
|
-
const Stream = __importStar(require("stream"));
|
|
28
|
-
class _Readable {
|
|
29
|
-
}
|
|
30
|
-
const Readable = Stream.Readable || _Readable;
|
|
31
|
-
/** Builds a node stream from an iterator */
|
|
32
|
-
function makeStream(source, options) {
|
|
33
|
-
// @ts-ignore AsyncGenerator
|
|
34
|
-
const iterator = source[Symbol.asyncIterator]
|
|
35
|
-
? // @ts-ignore AsyncGenerator
|
|
36
|
-
source[Symbol.asyncIterator]()
|
|
37
|
-
: // @ts-ignore AsyncGenerator
|
|
38
|
-
source[Symbol.iterator]();
|
|
39
|
-
return new AsyncIterableReadable(iterator, options);
|
|
40
|
-
}
|
|
41
|
-
exports.makeStream = makeStream;
|
|
42
|
-
class AsyncIterableReadable extends Readable {
|
|
43
|
-
constructor(it, options) {
|
|
44
|
-
super(options);
|
|
45
|
-
this._iterator = it;
|
|
46
|
-
this._pulling = false;
|
|
47
|
-
this._bytesMode = !options || !options.objectMode;
|
|
48
|
-
}
|
|
49
|
-
async _read(size) {
|
|
50
|
-
if (!this._pulling) {
|
|
51
|
-
this._pulling = true;
|
|
52
|
-
this._pulling = await this._pull(size, this._iterator);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
async _destroy(error, cb) {
|
|
56
|
-
if (!this._iterator) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
if (error) {
|
|
60
|
-
await this._iterator?.throw?.(error);
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
await this._iterator?.return?.(error);
|
|
64
|
-
}
|
|
65
|
-
cb?.(null);
|
|
66
|
-
}
|
|
67
|
-
// eslint-disable-next-line complexity
|
|
68
|
-
async _pull(size, it) {
|
|
69
|
-
const bm = this._bytesMode;
|
|
70
|
-
let r = null;
|
|
71
|
-
// while (this.readable && !(r = await it.next(bm ? size : null)).done) {
|
|
72
|
-
while (this.readable && !(r = await it.next()).done) {
|
|
73
|
-
if (size !== null) {
|
|
74
|
-
size -= bm && ArrayBuffer.isView(r.value) ? r.value.byteLength : 1;
|
|
75
|
-
}
|
|
76
|
-
if (!this.push(new Uint8Array(r.value)) || size <= 0) {
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
if ((r?.done || !this.readable) && (this.push(null) || true)) {
|
|
81
|
-
it?.return?.();
|
|
82
|
-
}
|
|
83
|
-
return !this.readable;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isWritableStream = exports.isReadableStream = exports.isReadableNodeStream = exports.isWritableNodeStream = exports.isReadableDOMStream = exports.isWritableDOMStream = exports.isBuffer = exports.isBlob = exports.isFile = exports.isResponse = exports.isIterator = exports.isAsyncIterable = exports.isIterable = exports.isPromise = exports.isPureObject = exports.isObject = void 0;
|
|
4
|
-
const isBoolean = (x) => typeof x === 'boolean';
|
|
5
|
-
const isFunction = (x) => typeof x === 'function';
|
|
6
|
-
const isObject = (x) => x !== null && typeof x === 'object';
|
|
7
|
-
exports.isObject = isObject;
|
|
8
|
-
const isPureObject = (x) => (0, exports.isObject)(x) && x.constructor === {}.constructor;
|
|
9
|
-
exports.isPureObject = isPureObject;
|
|
10
|
-
const isPromise = (x) => (0, exports.isObject)(x) && isFunction(x.then);
|
|
11
|
-
exports.isPromise = isPromise;
|
|
12
|
-
const isIterable = (x) => Boolean(x) && typeof x[Symbol.iterator] === 'function';
|
|
13
|
-
exports.isIterable = isIterable;
|
|
14
|
-
const isAsyncIterable = (x) => x && typeof x[Symbol.asyncIterator] === 'function';
|
|
15
|
-
exports.isAsyncIterable = isAsyncIterable;
|
|
16
|
-
const isIterator = (x) => x && isFunction(x.next);
|
|
17
|
-
exports.isIterator = isIterator;
|
|
18
|
-
const isResponse = (x) => (typeof Response !== 'undefined' && x instanceof Response) ||
|
|
19
|
-
(x && x.arrayBuffer && x.text && x.json);
|
|
20
|
-
exports.isResponse = isResponse;
|
|
21
|
-
const isFile = (x) => typeof File !== 'undefined' && x instanceof File;
|
|
22
|
-
exports.isFile = isFile;
|
|
23
|
-
const isBlob = (x) => typeof Blob !== 'undefined' && x instanceof Blob;
|
|
24
|
-
exports.isBlob = isBlob;
|
|
25
|
-
/** Check for Node.js `Buffer` without triggering bundler to include buffer polyfill */
|
|
26
|
-
const isBuffer = (x) => x && typeof x === 'object' && x.isBuffer;
|
|
27
|
-
exports.isBuffer = isBuffer;
|
|
28
|
-
const isWritableDOMStream = (x) => (0, exports.isObject)(x) && isFunction(x.abort) && isFunction(x.getWriter);
|
|
29
|
-
exports.isWritableDOMStream = isWritableDOMStream;
|
|
30
|
-
const isReadableDOMStream = (x) => (typeof ReadableStream !== 'undefined' && x instanceof ReadableStream) ||
|
|
31
|
-
((0, exports.isObject)(x) && isFunction(x.tee) && isFunction(x.cancel) && isFunction(x.getReader));
|
|
32
|
-
exports.isReadableDOMStream = isReadableDOMStream;
|
|
33
|
-
// Not implemented in Firefox: && isFunction(x.pipeTo)
|
|
34
|
-
const isWritableNodeStream = (x) => (0, exports.isObject)(x) && isFunction(x.end) && isFunction(x.write) && isBoolean(x.writable);
|
|
35
|
-
exports.isWritableNodeStream = isWritableNodeStream;
|
|
36
|
-
const isReadableNodeStream = (x) => (0, exports.isObject)(x) && isFunction(x.read) && isFunction(x.pipe) && isBoolean(x.readable);
|
|
37
|
-
exports.isReadableNodeStream = isReadableNodeStream;
|
|
38
|
-
const isReadableStream = (x) => (0, exports.isReadableDOMStream)(x) || (0, exports.isReadableNodeStream)(x);
|
|
39
|
-
exports.isReadableStream = isReadableStream;
|
|
40
|
-
const isWritableStream = (x) => (0, exports.isWritableDOMStream)(x) || (0, exports.isWritableNodeStream)(x);
|
|
41
|
-
exports.isWritableStream = isWritableStream;
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// loaders.gl, MIT license
|
|
3
|
-
// Copyright 2022 Foursquare Labs, Inc
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.encodeTableInBatches = exports.encodeTableAsText = exports.encodeTable = void 0;
|
|
6
|
-
/* global TextEncoder, TextDecoder */
|
|
7
|
-
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
8
|
-
async function encodeTable(data, writer, options) {
|
|
9
|
-
if (writer.encode) {
|
|
10
|
-
return await writer.encode(data, options);
|
|
11
|
-
}
|
|
12
|
-
if (writer.encodeText) {
|
|
13
|
-
const text = await writer.encodeText(data, options);
|
|
14
|
-
return new TextEncoder().encode(text);
|
|
15
|
-
}
|
|
16
|
-
if (writer.encodeInBatches) {
|
|
17
|
-
// Create an iterator representing the data
|
|
18
|
-
// TODO - Assumes this is a table
|
|
19
|
-
const batches = encodeTableInBatches(data, writer, options);
|
|
20
|
-
// Concatenate the output
|
|
21
|
-
const chunks = [];
|
|
22
|
-
for await (const batch of batches) {
|
|
23
|
-
chunks.push(batch);
|
|
24
|
-
}
|
|
25
|
-
return (0, loader_utils_1.concatenateArrayBuffers)(...chunks);
|
|
26
|
-
}
|
|
27
|
-
throw new Error('Writer could not encode data');
|
|
28
|
-
}
|
|
29
|
-
exports.encodeTable = encodeTable;
|
|
30
|
-
async function encodeTableAsText(data, writer, options) {
|
|
31
|
-
if (writer.text && writer.encodeText) {
|
|
32
|
-
return await writer.encodeText(data, options);
|
|
33
|
-
}
|
|
34
|
-
if (writer.text && (writer.encode || writer.encodeInBatches)) {
|
|
35
|
-
const arrayBuffer = await encodeTable(data, writer, options);
|
|
36
|
-
return new TextDecoder().decode(arrayBuffer);
|
|
37
|
-
}
|
|
38
|
-
throw new Error('Writer could not encode data as text');
|
|
39
|
-
}
|
|
40
|
-
exports.encodeTableAsText = encodeTableAsText;
|
|
41
|
-
function encodeTableInBatches(data, writer, options) {
|
|
42
|
-
if (writer.encodeInBatches) {
|
|
43
|
-
const dataIterator = getIterator(data);
|
|
44
|
-
// @ts-expect-error
|
|
45
|
-
return writer.encodeInBatches(dataIterator, options);
|
|
46
|
-
}
|
|
47
|
-
// TODO -fall back to atomic encode?
|
|
48
|
-
throw new Error('Writer could not encode data in batches');
|
|
49
|
-
}
|
|
50
|
-
exports.encodeTableInBatches = encodeTableInBatches;
|
|
51
|
-
function getIterator(data) {
|
|
52
|
-
const dataIterator = [{ table: data, start: 0, end: data.length }];
|
|
53
|
-
return dataIterator;
|
|
54
|
-
}
|
package/dist/lib/api/encode.js
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.encodeURLtoURL = exports.encodeInBatches = exports.encodeText = exports.encodeSync = exports.encode = void 0;
|
|
4
|
-
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
5
|
-
const worker_utils_1 = require("@loaders.gl/worker-utils");
|
|
6
|
-
const loader_utils_2 = require("@loaders.gl/loader-utils");
|
|
7
|
-
const loader_utils_3 = require("@loaders.gl/loader-utils");
|
|
8
|
-
const write_file_1 = require("../fetch/write-file");
|
|
9
|
-
const fetch_file_1 = require("../fetch/fetch-file");
|
|
10
|
-
const loader_options_1 = require("./loader-options");
|
|
11
|
-
/**
|
|
12
|
-
* Encode loaded data into a binary ArrayBuffer using the specified Writer.
|
|
13
|
-
*/
|
|
14
|
-
async function encode(data, writer, options) {
|
|
15
|
-
const globalOptions = (0, loader_options_1.getLoaderOptions)();
|
|
16
|
-
// const globalOptions: WriterOptions = {}; // getWriterOptions();
|
|
17
|
-
options = { ...globalOptions, ...options };
|
|
18
|
-
if ((0, loader_utils_1.canEncodeWithWorker)(writer, options)) {
|
|
19
|
-
return await (0, worker_utils_1.processOnWorker)(writer, data, options);
|
|
20
|
-
}
|
|
21
|
-
// TODO Merge default writer options with options argument like it is done in load module.
|
|
22
|
-
if (writer.encode) {
|
|
23
|
-
return await writer.encode(data, options);
|
|
24
|
-
}
|
|
25
|
-
if (writer.encodeSync) {
|
|
26
|
-
return writer.encodeSync(data, options);
|
|
27
|
-
}
|
|
28
|
-
if (writer.encodeText) {
|
|
29
|
-
return new TextEncoder().encode(await writer.encodeText(data, options));
|
|
30
|
-
}
|
|
31
|
-
if (writer.encodeInBatches) {
|
|
32
|
-
// Create an iterator representing the data
|
|
33
|
-
// TODO - Assumes this is a table
|
|
34
|
-
const batches = encodeInBatches(data, writer, options);
|
|
35
|
-
// Concatenate the output
|
|
36
|
-
const chunks = [];
|
|
37
|
-
for await (const batch of batches) {
|
|
38
|
-
chunks.push(batch);
|
|
39
|
-
}
|
|
40
|
-
// @ts-ignore
|
|
41
|
-
return (0, loader_utils_2.concatenateArrayBuffers)(...chunks);
|
|
42
|
-
}
|
|
43
|
-
if (!loader_utils_3.isBrowser && writer.encodeURLtoURL) {
|
|
44
|
-
// TODO - how to generate filenames with correct extensions?
|
|
45
|
-
const tmpInputFilename = getTemporaryFilename('input');
|
|
46
|
-
await (0, write_file_1.writeFile)(tmpInputFilename, data);
|
|
47
|
-
const tmpOutputFilename = getTemporaryFilename('output');
|
|
48
|
-
const outputFilename = await encodeURLtoURL(tmpInputFilename, tmpOutputFilename, writer, options);
|
|
49
|
-
const response = await (0, fetch_file_1.fetchFile)(outputFilename);
|
|
50
|
-
return response.arrayBuffer();
|
|
51
|
-
}
|
|
52
|
-
throw new Error('Writer could not encode data');
|
|
53
|
-
}
|
|
54
|
-
exports.encode = encode;
|
|
55
|
-
/**
|
|
56
|
-
* Encode loaded data into a binary ArrayBuffer using the specified Writer.
|
|
57
|
-
*/
|
|
58
|
-
function encodeSync(data, writer, options) {
|
|
59
|
-
if (writer.encodeSync) {
|
|
60
|
-
return writer.encodeSync(data, options);
|
|
61
|
-
}
|
|
62
|
-
throw new Error('Writer could not synchronously encode data');
|
|
63
|
-
}
|
|
64
|
-
exports.encodeSync = encodeSync;
|
|
65
|
-
/**
|
|
66
|
-
* Encode loaded data to text using the specified Writer
|
|
67
|
-
* @note This is a convenience function not intended for production use on large input data.
|
|
68
|
-
* It is not optimized for performance. Data maybe converted from text to binary and back.
|
|
69
|
-
* @throws if the writer does not generate text output
|
|
70
|
-
*/
|
|
71
|
-
async function encodeText(data, writer, options) {
|
|
72
|
-
if (writer.text && writer.encodeText) {
|
|
73
|
-
return await writer.encodeText(data, options);
|
|
74
|
-
}
|
|
75
|
-
if (writer.text && (writer.encode || writer.encodeInBatches)) {
|
|
76
|
-
const arrayBuffer = await encode(data, writer, options);
|
|
77
|
-
return new TextDecoder().decode(arrayBuffer);
|
|
78
|
-
}
|
|
79
|
-
throw new Error('Writer could not encode data as text');
|
|
80
|
-
}
|
|
81
|
-
exports.encodeText = encodeText;
|
|
82
|
-
/**
|
|
83
|
-
* Encode loaded data into a sequence (iterator) of binary ArrayBuffers using the specified Writer.
|
|
84
|
-
*/
|
|
85
|
-
function encodeInBatches(data, writer, options) {
|
|
86
|
-
if (writer.encodeInBatches) {
|
|
87
|
-
const dataIterator = getIterator(data);
|
|
88
|
-
// @ts-expect-error
|
|
89
|
-
return writer.encodeInBatches(dataIterator, options);
|
|
90
|
-
}
|
|
91
|
-
// TODO -fall back to atomic encode?
|
|
92
|
-
throw new Error('Writer could not encode data in batches');
|
|
93
|
-
}
|
|
94
|
-
exports.encodeInBatches = encodeInBatches;
|
|
95
|
-
/**
|
|
96
|
-
* Encode data stored in a file (on disk) to another file.
|
|
97
|
-
* @note Node.js only. This function enables using command-line converters as "writers".
|
|
98
|
-
*/
|
|
99
|
-
async function encodeURLtoURL(inputUrl, outputUrl, writer, options) {
|
|
100
|
-
inputUrl = (0, loader_utils_2.resolvePath)(inputUrl);
|
|
101
|
-
outputUrl = (0, loader_utils_2.resolvePath)(outputUrl);
|
|
102
|
-
if (loader_utils_3.isBrowser || !writer.encodeURLtoURL) {
|
|
103
|
-
throw new Error();
|
|
104
|
-
}
|
|
105
|
-
const outputFilename = await writer.encodeURLtoURL(inputUrl, outputUrl, options);
|
|
106
|
-
return outputFilename;
|
|
107
|
-
}
|
|
108
|
-
exports.encodeURLtoURL = encodeURLtoURL;
|
|
109
|
-
/**
|
|
110
|
-
* @todo TODO - this is an unacceptable hack!!!
|
|
111
|
-
*/
|
|
112
|
-
function getIterator(data) {
|
|
113
|
-
const dataIterator = [{ table: data, start: 0, end: data.length }];
|
|
114
|
-
return dataIterator;
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* @todo Move to utils
|
|
118
|
-
*/
|
|
119
|
-
function getTemporaryFilename(filename) {
|
|
120
|
-
return `/tmp/${filename}`;
|
|
121
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// loaders.gl, MIT license
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.loadInBatches = void 0;
|
|
5
|
-
const normalize_loader_1 = require("../loader-utils/normalize-loader");
|
|
6
|
-
const get_fetch_function_1 = require("../loader-utils/get-fetch-function");
|
|
7
|
-
const parse_in_batches_1 = require("./parse-in-batches");
|
|
8
|
-
function loadInBatches(files, loaders, options, context) {
|
|
9
|
-
let loadersArray;
|
|
10
|
-
// Signature: load(url, options)
|
|
11
|
-
if (!Array.isArray(loaders) && !(0, normalize_loader_1.isLoaderObject)(loaders)) {
|
|
12
|
-
context = undefined; // context not supported in short signature
|
|
13
|
-
options = loaders;
|
|
14
|
-
loadersArray = undefined;
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
loadersArray = loaders;
|
|
18
|
-
}
|
|
19
|
-
// Select fetch function
|
|
20
|
-
const fetch = (0, get_fetch_function_1.getFetchFunction)(options || {});
|
|
21
|
-
// Single url/file
|
|
22
|
-
if (!Array.isArray(files)) {
|
|
23
|
-
return loadOneFileInBatches(files, loadersArray, options || {}, fetch);
|
|
24
|
-
}
|
|
25
|
-
// Multiple URLs / files
|
|
26
|
-
const promises = files.map((file) => loadOneFileInBatches(file, loadersArray, options || {}, fetch));
|
|
27
|
-
// No point in waiting here for all responses before starting to stream individual streams?
|
|
28
|
-
return promises;
|
|
29
|
-
}
|
|
30
|
-
exports.loadInBatches = loadInBatches;
|
|
31
|
-
async function loadOneFileInBatches(file, loaders, options, fetch) {
|
|
32
|
-
if (typeof file === 'string') {
|
|
33
|
-
const url = file;
|
|
34
|
-
const response = await fetch(url);
|
|
35
|
-
// @ts-expect-error
|
|
36
|
-
return await (0, parse_in_batches_1.parseInBatches)(response, loaders, options);
|
|
37
|
-
}
|
|
38
|
-
// @ts-expect-error TODO
|
|
39
|
-
return await (0, parse_in_batches_1.parseInBatches)(file, loaders, options);
|
|
40
|
-
}
|
package/dist/lib/api/load.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// loaders.gl, MIT license
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.load = void 0;
|
|
5
|
-
const is_type_1 = require("../../javascript-utils/is-type");
|
|
6
|
-
const normalize_loader_1 = require("../loader-utils/normalize-loader");
|
|
7
|
-
const get_fetch_function_1 = require("../loader-utils/get-fetch-function");
|
|
8
|
-
const parse_1 = require("./parse");
|
|
9
|
-
// implementation signature
|
|
10
|
-
async function load(url, loaders, options, context) {
|
|
11
|
-
let resolvedLoaders;
|
|
12
|
-
let resolvedOptions;
|
|
13
|
-
// Signature: load(url, options)
|
|
14
|
-
if (!Array.isArray(loaders) && !(0, normalize_loader_1.isLoaderObject)(loaders)) {
|
|
15
|
-
resolvedLoaders = [];
|
|
16
|
-
resolvedOptions = loaders;
|
|
17
|
-
context = undefined; // context not supported in short signature
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
resolvedLoaders = loaders;
|
|
21
|
-
resolvedOptions = options;
|
|
22
|
-
}
|
|
23
|
-
// Select fetch function
|
|
24
|
-
const fetch = (0, get_fetch_function_1.getFetchFunction)(resolvedOptions);
|
|
25
|
-
// at this point, `url` could be already loaded binary data
|
|
26
|
-
let data = url;
|
|
27
|
-
// url is a string, fetch the url
|
|
28
|
-
if (typeof url === 'string') {
|
|
29
|
-
data = await fetch(url);
|
|
30
|
-
// URL is Blob or File, fetchFile handles it (alt: we could generate ObjectURL here)
|
|
31
|
-
}
|
|
32
|
-
if ((0, is_type_1.isBlob)(url)) {
|
|
33
|
-
// The fetch response object will contain blob.name
|
|
34
|
-
// @ts-expect-error TODO - This may not work for overridden fetch functions
|
|
35
|
-
data = await fetch(url);
|
|
36
|
-
}
|
|
37
|
-
// Data is loaded (at least we have a `Response` object) so time to hand over to `parse`
|
|
38
|
-
// return await parse(data, loaders as Loader[], options);
|
|
39
|
-
return Array.isArray(resolvedLoaders)
|
|
40
|
-
? await (0, parse_1.parse)(data, resolvedLoaders, resolvedOptions) // loader array overload
|
|
41
|
-
: await (0, parse_1.parse)(data, resolvedLoaders, resolvedOptions); // single loader overload
|
|
42
|
-
}
|
|
43
|
-
exports.load = load;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getLoaderOptions = exports.setLoaderOptions = void 0;
|
|
4
|
-
var option_utils_1 = require("../loader-utils/option-utils");
|
|
5
|
-
Object.defineProperty(exports, "setLoaderOptions", { enumerable: true, get: function () { return option_utils_1.setGlobalOptions; } });
|
|
6
|
-
var option_utils_2 = require("../loader-utils/option-utils");
|
|
7
|
-
Object.defineProperty(exports, "getLoaderOptions", { enumerable: true, get: function () { return option_utils_2.getGlobalLoaderOptions; } });
|