@loaders.gl/loader-utils 4.1.0-alpha.1 → 4.1.0-alpha.10
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/index.cjs +35 -6
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/json-loader.js +1 -1
- package/dist/json-loader.js.map +1 -1
- package/dist/lib/binary-utils/array-buffer-utils.d.ts +7 -2
- package/dist/lib/binary-utils/array-buffer-utils.d.ts.map +1 -1
- package/dist/lib/binary-utils/array-buffer-utils.js +3 -0
- package/dist/lib/binary-utils/array-buffer-utils.js.map +1 -1
- package/dist/lib/binary-utils/get-first-characters.d.ts.map +1 -1
- package/dist/lib/binary-utils/get-first-characters.js.map +1 -1
- package/dist/lib/binary-utils/memory-conversion-utils.d.ts.map +1 -1
- package/dist/lib/binary-utils/memory-conversion-utils.js.map +1 -1
- package/dist/lib/file-provider/file-handle-file.d.ts +11 -3
- package/dist/lib/file-provider/file-handle-file.d.ts.map +1 -1
- package/dist/lib/file-provider/file-handle-file.js +9 -4
- package/dist/lib/file-provider/file-handle-file.js.map +1 -1
- package/dist/lib/files/blob-file.d.ts.map +1 -1
- package/dist/lib/files/blob-file.js.map +1 -1
- package/dist/lib/files/file.d.ts.map +1 -1
- package/dist/lib/files/file.js.map +1 -1
- package/dist/lib/files/http-file.d.ts.map +1 -1
- package/dist/lib/files/http-file.js.map +1 -1
- package/dist/lib/files/node-file-facade.d.ts +5 -1
- package/dist/lib/files/node-file-facade.d.ts.map +1 -1
- package/dist/lib/files/node-file-facade.js +6 -0
- package/dist/lib/files/node-file-facade.js.map +1 -1
- package/dist/lib/filesystems/filesystem.d.ts.map +1 -1
- package/dist/lib/filesystems/filesystem.js.map +1 -1
- package/dist/lib/filesystems/node-filesystem-facade.d.ts.map +1 -1
- package/dist/lib/filesystems/node-filesystem-facade.js.map +1 -1
- package/dist/lib/node/buffer.browser.d.ts.map +1 -1
- package/dist/lib/node/buffer.browser.js.map +1 -1
- package/dist/lib/node/buffer.d.ts.map +1 -1
- package/dist/lib/node/buffer.js.map +1 -1
- package/dist/lib/node/stream.d.ts.map +1 -1
- package/dist/lib/node/stream.js.map +1 -1
- package/dist/lib/option-utils/merge-loader-options.d.ts.map +1 -1
- package/dist/lib/option-utils/merge-loader-options.js +5 -1
- package/dist/lib/option-utils/merge-loader-options.js.map +1 -1
- package/dist/lib/sources/data-source.d.ts.map +1 -1
- package/dist/lib/sources/data-source.js.map +1 -1
- package/dist/lib/sources/image-source.d.ts.map +1 -1
- package/dist/lib/sources/image-source.js.map +1 -1
- package/dist/lib/sources/image-tile-source.d.ts.map +1 -1
- package/dist/lib/sources/image-tile-source.js.map +1 -1
- package/dist/lib/sources/tile-source-adapter.d.ts.map +1 -1
- package/dist/lib/sources/tile-source-adapter.js.map +1 -1
- package/dist/lib/sources/tile-source.d.ts.map +1 -1
- package/dist/lib/sources/tile-source.js.map +1 -1
- package/dist/lib/sources/utils/utils.d.ts.map +1 -1
- package/dist/lib/sources/utils/utils.js.map +1 -1
- package/dist/lib/sources/vector-tile-source.d.ts.map +1 -1
- package/dist/lib/sources/vector-tile-source.js.map +1 -1
- package/dist/loader-types.d.ts +4 -4
- package/dist/loader-types.d.ts.map +1 -1
- package/dist/loader-types.js.map +1 -1
- package/dist/service-types.d.ts.map +1 -1
- package/dist/service-types.js.map +1 -1
- package/dist/writer-types.d.ts +10 -2
- package/dist/writer-types.d.ts.map +1 -1
- package/dist/writer-types.js.map +1 -1
- package/package.json +5 -5
- package/src/index.ts +3 -1
- package/src/lib/binary-utils/array-buffer-utils.ts +10 -2
- package/src/lib/binary-utils/get-first-characters.ts +2 -1
- package/src/lib/binary-utils/memory-conversion-utils.ts +2 -1
- package/src/lib/file-provider/file-handle-file.ts +21 -8
- package/src/lib/files/blob-file.ts +2 -1
- package/src/lib/files/file.ts +2 -1
- package/src/lib/files/http-file.ts +2 -1
- package/src/lib/files/node-file-facade.ts +13 -2
- package/src/lib/filesystems/filesystem.ts +2 -1
- package/src/lib/filesystems/node-filesystem-facade.ts +2 -1
- package/src/lib/node/buffer.browser.ts +2 -1
- package/src/lib/node/buffer.ts +2 -1
- package/src/lib/node/stream.ts +2 -1
- package/src/lib/option-utils/merge-loader-options.ts +11 -3
- package/src/lib/sources/data-source.ts +2 -1
- package/src/lib/sources/image-source.ts +2 -1
- package/src/lib/sources/image-tile-source.ts +2 -1
- package/src/lib/sources/tile-source-adapter.ts +2 -1
- package/src/lib/sources/tile-source.ts +2 -1
- package/src/lib/sources/utils/utils.ts +2 -1
- package/src/lib/sources/vector-tile-source.ts +2 -1
- package/src/loader-types.ts +7 -5
- package/src/service-types.ts +2 -1
- package/src/writer-types.ts +15 -4
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
// loaders.gl
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
|
|
4
5
|
import {FileProvider} from './file-provider';
|
|
@@ -12,13 +13,25 @@ export class FileHandleFile implements FileProvider {
|
|
|
12
13
|
/** The FileHandle from which data is provided */
|
|
13
14
|
private file: NodeFile;
|
|
14
15
|
|
|
15
|
-
/** The file length in bytes */
|
|
16
|
-
private size: bigint;
|
|
17
|
-
|
|
18
16
|
/** Create a new FileHandleFile */
|
|
19
|
-
constructor(path: string) {
|
|
20
|
-
this.file = new NodeFile(path, 'r');
|
|
21
|
-
|
|
17
|
+
constructor(path: string, append: boolean = false) {
|
|
18
|
+
this.file = new NodeFile(path, append ? 'a+' : 'r');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Truncates the file descriptor.
|
|
23
|
+
* @param length desired file lenght
|
|
24
|
+
*/
|
|
25
|
+
async truncate(length: number): Promise<void> {
|
|
26
|
+
await this.file.truncate(length);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Append data to a file.
|
|
31
|
+
* @param buffer data to append
|
|
32
|
+
*/
|
|
33
|
+
async append(buffer: Uint8Array): Promise<void> {
|
|
34
|
+
await this.file.append(buffer);
|
|
22
35
|
}
|
|
23
36
|
|
|
24
37
|
/** Close file */
|
|
@@ -96,6 +109,6 @@ export class FileHandleFile implements FileProvider {
|
|
|
96
109
|
* the length (in bytes) of the data.
|
|
97
110
|
*/
|
|
98
111
|
get length(): bigint {
|
|
99
|
-
return this.
|
|
112
|
+
return this.file.bigsize;
|
|
100
113
|
}
|
|
101
114
|
}
|
package/src/lib/files/file.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
// loaders.gl
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
|
|
4
5
|
import {isBrowser} from '../env-utils/globals';
|
|
@@ -13,7 +14,7 @@ export class NodeFileFacade implements ReadableFile, WritableFile {
|
|
|
13
14
|
bigsize: bigint = 0n;
|
|
14
15
|
url: string = '';
|
|
15
16
|
|
|
16
|
-
constructor(url: string, flags?: 'r' | 'w' | 'wx', mode?: number) {
|
|
17
|
+
constructor(url: string, flags?: 'r' | 'w' | 'wx' | 'a+', mode?: number) {
|
|
17
18
|
// Return the actual implementation instance
|
|
18
19
|
if (globalThis.loaders?.NodeFile) {
|
|
19
20
|
return new globalThis.loaders.NodeFile(url, flags, mode);
|
|
@@ -35,6 +36,16 @@ export class NodeFileFacade implements ReadableFile, WritableFile {
|
|
|
35
36
|
async stat(): Promise<Stat> {
|
|
36
37
|
throw NOT_IMPLEMENTED;
|
|
37
38
|
}
|
|
39
|
+
|
|
40
|
+
/** Truncates the file descriptor. Only available on NodeFile. */
|
|
41
|
+
async truncate(length: number): Promise<void> {
|
|
42
|
+
throw NOT_IMPLEMENTED;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Append data to a file. Only available on NodeFile. */
|
|
46
|
+
async append(data: Uint8Array): Promise<void> {
|
|
47
|
+
throw NOT_IMPLEMENTED;
|
|
48
|
+
}
|
|
38
49
|
/** Close the file */
|
|
39
50
|
async close(): Promise<void> {}
|
|
40
51
|
}
|
package/src/lib/node/buffer.ts
CHANGED
package/src/lib/node/stream.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
// loaders.gl
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
|
|
4
5
|
import {LoaderOptions} from '../../loader-types';
|
|
@@ -18,14 +19,21 @@ export function mergeLoaderOptions<Options extends LoaderOptions>(
|
|
|
18
19
|
|
|
19
20
|
function mergeOptionsRecursively(
|
|
20
21
|
baseOptions: Record<string, unknown>,
|
|
21
|
-
newOptions: Record<string, unknown
|
|
22
|
+
newOptions: Record<string, unknown>,
|
|
23
|
+
level = 0
|
|
22
24
|
): Record<string, unknown> {
|
|
25
|
+
// Sanity check (jest test runner overwrites the console object which can lead to infinite recursion)
|
|
26
|
+
if (level > 3) {
|
|
27
|
+
return newOptions;
|
|
28
|
+
}
|
|
29
|
+
|
|
23
30
|
const options = {...baseOptions};
|
|
24
31
|
for (const [key, newValue] of Object.entries(newOptions)) {
|
|
25
32
|
if (newValue && typeof newValue === 'object' && !Array.isArray(newValue)) {
|
|
26
33
|
options[key] = mergeOptionsRecursively(
|
|
27
34
|
(options[key] as Record<string, unknown>) || {},
|
|
28
|
-
newOptions[key] as Record<string, unknown
|
|
35
|
+
newOptions[key] as Record<string, unknown>,
|
|
36
|
+
level + 1
|
|
29
37
|
);
|
|
30
38
|
// Object.assign(options[key] as object, newOptions[key]);
|
|
31
39
|
} else {
|
package/src/loader-types.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
// loaders.gl
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
|
|
4
5
|
import {
|
|
@@ -180,10 +181,6 @@ export type LoaderWithParser<DataT = any, BatchT = any, LoaderOptionsT = LoaderO
|
|
|
180
181
|
options?: LoaderOptionsT,
|
|
181
182
|
context?: LoaderContext
|
|
182
183
|
) => DataT;
|
|
183
|
-
/** Parse atomically from a string asynchronously */
|
|
184
|
-
parseText?: (text: string, options?: LoaderOptionsT, context?: LoaderContext) => Promise<DataT>;
|
|
185
|
-
/** Parse atomically from a string synchronously */
|
|
186
|
-
parseTextSync?: (text: string, options?: LoaderOptionsT, context?: LoaderContext) => DataT;
|
|
187
184
|
/** Parse batches of data from an iterator (e.g. fetch stream), return an iterator that yield parsed batches. */
|
|
188
185
|
parseInBatches?: (
|
|
189
186
|
iterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,
|
|
@@ -196,6 +193,11 @@ export type LoaderWithParser<DataT = any, BatchT = any, LoaderOptionsT = LoaderO
|
|
|
196
193
|
options?: LoaderOptionsT,
|
|
197
194
|
context?: LoaderContext
|
|
198
195
|
) => AsyncIterable<BatchT>;
|
|
196
|
+
|
|
197
|
+
/** Parse atomically from a string asynchronously */
|
|
198
|
+
parseText?: (text: string, options?: LoaderOptionsT, context?: LoaderContext) => Promise<DataT>;
|
|
199
|
+
/** Parse atomically from a string synchronously */
|
|
200
|
+
parseTextSync?: (text: string, options?: LoaderOptionsT, context?: LoaderContext) => DataT;
|
|
199
201
|
};
|
|
200
202
|
|
|
201
203
|
/**
|
package/src/service-types.ts
CHANGED
package/src/writer-types.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
// loaders.gl
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
|
|
4
5
|
// WRITERS
|
|
@@ -47,6 +48,7 @@ export type Writer<DataT = unknown, BatchT = unknown, WriterOptionsT = WriterOpt
|
|
|
47
48
|
/** Is the input of this loader text */
|
|
48
49
|
text?: boolean;
|
|
49
50
|
|
|
51
|
+
/** Default options for this writer */
|
|
50
52
|
options: WriterOptionsT;
|
|
51
53
|
deprecatedOptions?: Record<string, string>;
|
|
52
54
|
};
|
|
@@ -59,13 +61,22 @@ export type WriterWithEncoder<
|
|
|
59
61
|
BatchT = unknown,
|
|
60
62
|
WriterOptionsT = WriterOptions
|
|
61
63
|
> = Writer<DataT, BatchT, WriterOptionsT> & {
|
|
62
|
-
|
|
64
|
+
/** Encode to binary, asynchronously */
|
|
65
|
+
encode(data: DataT, options?: WriterOptionsT): Promise<ArrayBuffer>;
|
|
66
|
+
/** Encode to binary, synchronously */
|
|
63
67
|
encodeSync?(data: DataT, options?: WriterOptionsT): ArrayBuffer;
|
|
68
|
+
/** Encode to binary in batches */
|
|
69
|
+
encodeInBatches?(data: AsyncIterable<any>, options?: WriterOptionsT): AsyncIterable<ArrayBuffer>;
|
|
64
70
|
|
|
71
|
+
/** Encode to text, asynchronously. For text formats. */
|
|
65
72
|
encodeText?(table: DataT, options?: WriterOptionsT): Promise<string>;
|
|
73
|
+
/** Encode to text, synchronously. For text formats. */
|
|
66
74
|
encodeTextSync?(table: DataT, options?: WriterOptionsT): string;
|
|
67
|
-
|
|
68
|
-
|
|
75
|
+
/** Encode to text in batched. For text formats. */
|
|
76
|
+
encodeTextInBatches?(
|
|
77
|
+
data: AsyncIterable<any>,
|
|
78
|
+
options?: WriterOptionsT
|
|
79
|
+
): AsyncIterable<ArrayBuffer>;
|
|
69
80
|
|
|
70
81
|
encodeURLtoURL?: (
|
|
71
82
|
inputUrl: string,
|