@loaders.gl/loader-utils 3.1.0-alpha.1 → 3.1.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/es5/index.js +323 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/json-loader.js +29 -0
- package/dist/es5/json-loader.js.map +1 -0
- package/dist/es5/lib/binary-utils/array-buffer-utils.js +102 -0
- package/dist/es5/lib/binary-utils/array-buffer-utils.js.map +1 -0
- package/dist/es5/lib/binary-utils/binary-copy-utils.js +35 -0
- package/dist/es5/lib/binary-utils/binary-copy-utils.js.map +1 -0
- package/dist/es5/lib/binary-utils/buffer-utils.js +32 -0
- package/dist/es5/lib/binary-utils/buffer-utils.js.map +1 -0
- package/dist/es5/lib/binary-utils/encode-utils.js +42 -0
- package/dist/es5/lib/binary-utils/encode-utils.js.map +1 -0
- package/dist/es5/lib/binary-utils/get-first-characters.js +36 -0
- package/dist/es5/lib/binary-utils/get-first-characters.js.map +1 -0
- package/dist/es5/lib/binary-utils/memory-copy-utils.js +39 -0
- package/dist/es5/lib/binary-utils/memory-copy-utils.js.map +1 -0
- package/dist/es5/lib/env-utils/assert.js +13 -0
- package/dist/es5/lib/env-utils/assert.js.map +1 -0
- package/dist/es5/lib/env-utils/globals.js +28 -0
- package/dist/es5/lib/env-utils/globals.js.map +1 -0
- package/dist/es5/lib/filesystems/node-filesystem.js +74 -0
- package/dist/es5/lib/filesystems/node-filesystem.js.map +1 -0
- package/dist/es5/lib/iterators/async-iteration.js +51 -0
- package/dist/es5/lib/iterators/async-iteration.js.map +1 -0
- package/dist/es5/lib/iterators/text-iterators.js +59 -0
- package/dist/es5/lib/iterators/text-iterators.js.map +1 -0
- package/dist/es5/lib/node/buffer.js +38 -0
- package/dist/es5/lib/node/buffer.js.map +1 -0
- package/dist/es5/lib/node/fs.js +52 -0
- package/dist/es5/lib/node/fs.js.map +1 -0
- package/dist/es5/lib/node/util.js +16 -0
- package/dist/es5/lib/node/util.js.map +1 -0
- package/dist/es5/lib/parser-utils/parse-json.js +17 -0
- package/dist/es5/lib/parser-utils/parse-json.js.map +1 -0
- package/dist/es5/lib/path-utils/file-aliases.js +39 -0
- package/dist/es5/lib/path-utils/file-aliases.js.map +1 -0
- package/dist/es5/lib/path-utils/path.js +35 -0
- package/dist/es5/lib/path-utils/path.js.map +1 -0
- package/dist/es5/lib/request-utils/request-scheduler.js +154 -0
- package/dist/es5/lib/request-utils/request-scheduler.js.map +1 -0
- package/dist/es5/lib/worker-loader-utils/create-loader-worker.js +117 -0
- package/dist/es5/lib/worker-loader-utils/create-loader-worker.js.map +1 -0
- package/dist/es5/lib/worker-loader-utils/parse-with-worker.js +76 -0
- package/dist/es5/lib/worker-loader-utils/parse-with-worker.js.map +1 -0
- package/dist/es5/types.js +2 -0
- package/dist/{types.js.map → es5/types.js.map} +0 -0
- package/dist/es5/workers/json-worker.js +8 -0
- package/dist/es5/workers/json-worker.js.map +1 -0
- package/dist/{index.js → esm/index.js} +8 -4
- package/dist/esm/index.js.map +1 -0
- package/dist/{json-loader.js → esm/json-loader.js} +1 -1
- package/dist/esm/json-loader.js.map +1 -0
- package/dist/{lib → esm/lib}/binary-utils/array-buffer-utils.js +0 -0
- package/dist/esm/lib/binary-utils/array-buffer-utils.js.map +1 -0
- package/dist/{lib → esm/lib}/binary-utils/binary-copy-utils.js +0 -0
- package/dist/esm/lib/binary-utils/binary-copy-utils.js.map +1 -0
- package/dist/{lib → esm/lib}/binary-utils/buffer-utils.js +1 -1
- package/dist/esm/lib/binary-utils/buffer-utils.js.map +1 -0
- package/dist/{lib → esm/lib}/binary-utils/encode-utils.js +0 -0
- package/dist/esm/lib/binary-utils/encode-utils.js.map +1 -0
- package/dist/{lib → esm/lib}/binary-utils/get-first-characters.js +0 -0
- package/dist/esm/lib/binary-utils/get-first-characters.js.map +1 -0
- package/dist/{lib → esm/lib}/binary-utils/memory-copy-utils.js +0 -0
- package/dist/esm/lib/binary-utils/memory-copy-utils.js.map +1 -0
- package/dist/{lib → esm/lib}/env-utils/assert.js +0 -0
- package/dist/esm/lib/env-utils/assert.js.map +1 -0
- package/dist/{lib → esm/lib}/env-utils/globals.js +1 -1
- package/dist/esm/lib/env-utils/globals.js.map +1 -0
- package/dist/esm/lib/filesystems/node-filesystem.js +60 -0
- package/dist/esm/lib/filesystems/node-filesystem.js.map +1 -0
- package/dist/{lib → esm/lib}/iterators/async-iteration.js +0 -0
- package/dist/esm/lib/iterators/async-iteration.js.map +1 -0
- package/dist/{lib → esm/lib}/iterators/text-iterators.js +0 -0
- package/dist/esm/lib/iterators/text-iterators.js.map +1 -0
- package/dist/{lib/node/buffer-utils.node.js → esm/lib/node/buffer.js} +1 -1
- package/dist/esm/lib/node/buffer.js.map +1 -0
- package/dist/esm/lib/node/fs.js +27 -0
- package/dist/esm/lib/node/fs.js.map +1 -0
- package/dist/esm/lib/node/util.js +3 -0
- package/dist/esm/lib/node/util.js.map +1 -0
- package/dist/{lib → esm/lib}/parser-utils/parse-json.js +1 -1
- package/dist/esm/lib/parser-utils/parse-json.js.map +1 -0
- package/dist/{lib → esm/lib}/path-utils/file-aliases.js +1 -1
- package/dist/esm/lib/path-utils/file-aliases.js.map +1 -0
- package/dist/{lib → esm/lib}/path-utils/path.js +6 -2
- package/dist/esm/lib/path-utils/path.js.map +1 -0
- package/dist/{lib → esm/lib}/request-utils/request-scheduler.js +0 -0
- package/dist/esm/lib/request-utils/request-scheduler.js.map +1 -0
- package/dist/{lib → esm/lib}/worker-loader-utils/create-loader-worker.js +1 -1
- package/dist/esm/lib/worker-loader-utils/create-loader-worker.js.map +1 -0
- package/dist/{lib → esm/lib}/worker-loader-utils/parse-with-worker.js +1 -1
- package/dist/esm/lib/worker-loader-utils/parse-with-worker.js.map +1 -0
- package/dist/{types.js → esm/types.js} +0 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/{workers → esm/workers}/json-worker.js +0 -0
- package/dist/esm/workers/json-worker.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/json-loader.d.ts +21 -0
- package/dist/lib/binary-utils/array-buffer-utils.d.ts +30 -0
- package/dist/lib/binary-utils/binary-copy-utils.d.ts +23 -0
- package/dist/lib/binary-utils/buffer-utils.d.ts +15 -0
- package/dist/lib/binary-utils/encode-utils.d.ts +3 -0
- package/dist/lib/binary-utils/get-first-characters.d.ts +2 -0
- package/dist/lib/binary-utils/memory-copy-utils.d.ts +24 -0
- package/dist/lib/env-utils/assert.d.ts +5 -0
- package/dist/lib/env-utils/globals.d.ts +14 -0
- package/dist/lib/filesystems/node-filesystem.d.ts +37 -0
- package/dist/lib/iterators/async-iteration.d.ts +19 -0
- package/dist/lib/iterators/text-iterators.d.ts +18 -0
- package/dist/lib/node/buffer.d.ts +9 -0
- package/dist/lib/node/fs.d.ts +25 -0
- package/dist/lib/node/util.d.ts +4 -0
- package/dist/lib/parser-utils/parse-json.d.ts +4 -0
- package/dist/lib/path-utils/file-aliases.d.ts +16 -0
- package/dist/lib/path-utils/path.d.ts +15 -0
- package/dist/lib/request-utils/request-scheduler.d.ts +61 -0
- package/dist/lib/worker-loader-utils/create-loader-worker.d.ts +6 -0
- package/dist/lib/worker-loader-utils/parse-with-worker.d.ts +14 -0
- package/dist/types.d.ts +206 -0
- package/dist/workers/json-worker.d.ts +1 -0
- package/package.json +15 -10
- package/src/index.ts +26 -8
- package/src/lib/binary-utils/buffer-utils.ts +1 -1
- package/src/lib/env-utils/globals.ts +1 -1
- package/src/lib/filesystems/node-filesystem.ts +79 -0
- package/src/lib/node/{buffer-utils.node.ts → buffer.ts} +0 -0
- package/src/lib/node/fs.ts +29 -13
- package/src/lib/node/util.ts +4 -0
- package/src/lib/path-utils/path.ts +9 -0
- package/dist/index.js.map +0 -1
- package/dist/json-loader.js.map +0 -1
- package/dist/lib/binary-utils/array-buffer-utils.js.map +0 -1
- package/dist/lib/binary-utils/binary-copy-utils.js.map +0 -1
- package/dist/lib/binary-utils/buffer-utils.js.map +0 -1
- package/dist/lib/binary-utils/encode-utils.js.map +0 -1
- package/dist/lib/binary-utils/get-first-characters.js.map +0 -1
- package/dist/lib/binary-utils/memory-copy-utils.js.map +0 -1
- package/dist/lib/env-utils/assert.js.map +0 -1
- package/dist/lib/env-utils/globals.js.map +0 -1
- package/dist/lib/iterators/async-iteration.js.map +0 -1
- package/dist/lib/iterators/text-iterators.js.map +0 -1
- package/dist/lib/node/buffer-utils.node.js.map +0 -1
- package/dist/lib/node/fs.js +0 -29
- package/dist/lib/node/fs.js.map +0 -1
- package/dist/lib/parser-utils/parse-json.js.map +0 -1
- package/dist/lib/path-utils/file-aliases.js.map +0 -1
- package/dist/lib/path-utils/path.js.map +0 -1
- package/dist/lib/request-utils/request-scheduler.js.map +0 -1
- package/dist/lib/worker-loader-utils/create-loader-worker.js.map +0 -1
- package/dist/lib/worker-loader-utils/parse-with-worker.js.map +0 -1
- package/dist/workers/json-worker.js.map +0 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare function setPathPrefix(prefix: string): void;
|
|
2
|
+
export declare function getPathPrefix(): string;
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param aliases
|
|
6
|
+
*
|
|
7
|
+
* Note: addAliases are an experimental export, they are only for testing of loaders.gl loaders
|
|
8
|
+
* not intended as a generic aliasing mechanism
|
|
9
|
+
*/
|
|
10
|
+
export declare function addAliases(aliases: {
|
|
11
|
+
[aliasPath: string]: string;
|
|
12
|
+
}): void;
|
|
13
|
+
/**
|
|
14
|
+
* Resolves aliases and adds path-prefix to paths
|
|
15
|
+
*/
|
|
16
|
+
export declare function resolvePath(filename: string): string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Replacement for Node.js path.filename
|
|
3
|
+
* @param url
|
|
4
|
+
*/
|
|
5
|
+
export declare function filename(url: string): string;
|
|
6
|
+
/**
|
|
7
|
+
* Replacement for Node.js path.dirname
|
|
8
|
+
* @param url
|
|
9
|
+
*/
|
|
10
|
+
export declare function dirname(url: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Replacement for Node.js path.join
|
|
13
|
+
* @param parts
|
|
14
|
+
*/
|
|
15
|
+
export declare function join(...parts: string[]): string;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Stats } from '@probe.gl/stats';
|
|
2
|
+
declare type Handle = any;
|
|
3
|
+
declare type DoneFunction = () => any;
|
|
4
|
+
declare type GetPriorityFunction = () => number;
|
|
5
|
+
declare type RequestResult = {
|
|
6
|
+
done: DoneFunction;
|
|
7
|
+
} | null;
|
|
8
|
+
/** RequestScheduler Options */
|
|
9
|
+
export declare type RequestSchedulerProps = {
|
|
10
|
+
id?: string;
|
|
11
|
+
throttleRequests?: boolean;
|
|
12
|
+
maxRequests?: number;
|
|
13
|
+
};
|
|
14
|
+
/** Tracks one request */
|
|
15
|
+
declare type Request = {
|
|
16
|
+
handle: Handle;
|
|
17
|
+
priority: number;
|
|
18
|
+
getPriority: GetPriorityFunction;
|
|
19
|
+
resolve?: (value: any) => any;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Used to issue a request, without having them "deeply queued" by the browser.
|
|
23
|
+
* @todo - Track requests globally, across multiple servers
|
|
24
|
+
*/
|
|
25
|
+
export default class RequestScheduler {
|
|
26
|
+
readonly props: Required<RequestSchedulerProps>;
|
|
27
|
+
readonly stats: Stats;
|
|
28
|
+
activeRequestCount: number;
|
|
29
|
+
/** Tracks the number of active requests and prioritizes/cancels queued requests. */
|
|
30
|
+
private requestQueue;
|
|
31
|
+
private requestMap;
|
|
32
|
+
private deferredUpdate;
|
|
33
|
+
constructor(props?: RequestSchedulerProps);
|
|
34
|
+
/**
|
|
35
|
+
* Called by an application that wants to issue a request, without having it deeply queued by the browser
|
|
36
|
+
*
|
|
37
|
+
* When the returned promise resolved, it is OK for the application to issue a request.
|
|
38
|
+
* The promise resolves to an object that contains a `done` method.
|
|
39
|
+
* When the application's request has completed (or failed), the application must call the `done` function
|
|
40
|
+
*
|
|
41
|
+
* @param handle
|
|
42
|
+
* @param getPriority will be called when request "slots" open up,
|
|
43
|
+
* allowing the caller to update priority or cancel the request
|
|
44
|
+
* Highest priority executes first, priority < 0 cancels the request
|
|
45
|
+
* @returns a promise
|
|
46
|
+
* - resolves to a object (with a `done` field) when the request can be issued without queueing,
|
|
47
|
+
* - resolves to `null` if the request has been cancelled (by the callback return < 0).
|
|
48
|
+
* In this case the application should not issue the request
|
|
49
|
+
*/
|
|
50
|
+
scheduleRequest(handle: Handle, getPriority?: GetPriorityFunction): Promise<RequestResult>;
|
|
51
|
+
_issueRequest(request: Request): Promise<any>;
|
|
52
|
+
/** We check requests asynchronously, to prevent multiple updates */
|
|
53
|
+
_issueNewRequests(): void;
|
|
54
|
+
/** Refresh all requests */
|
|
55
|
+
_issueNewRequestsAsync(): void;
|
|
56
|
+
/** Ensure all requests have updated priorities, and that no longer valid requests are cancelled */
|
|
57
|
+
_updateAllRequests(): void;
|
|
58
|
+
/** Update a single request by calling the callback */
|
|
59
|
+
_updateRequest(request: any): boolean;
|
|
60
|
+
}
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Loader, LoaderOptions, LoaderContext } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Determines if a loader can parse with worker
|
|
4
|
+
* @param loader
|
|
5
|
+
* @param options
|
|
6
|
+
*/
|
|
7
|
+
export declare function canParseWithWorker(loader: Loader, options?: LoaderOptions): boolean | "" | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* this function expects that the worker function sends certain messages,
|
|
10
|
+
* this can be automated if the worker is wrapper by a call to createLoaderWorker in @loaders.gl/loader-utils.
|
|
11
|
+
*/
|
|
12
|
+
export declare function parseWithWorker(loader: Loader, data: any, options?: LoaderOptions, context?: LoaderContext, parseOnMainThread?: (arrayBuffer: ArrayBuffer, options: {
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
}) => Promise<void>): Promise<any>;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export declare type TypedIntArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Int32Array | Uint32Array;
|
|
3
|
+
export declare type TypedFloatArray = Uint16Array | Float32Array | Float64Array;
|
|
4
|
+
export declare type TypedArray = TypedIntArray | TypedFloatArray;
|
|
5
|
+
export declare type NumericArray = Array<number> | TypedIntArray | TypedFloatArray;
|
|
6
|
+
declare type FetchLike = (url: string, options?: RequestInit) => Promise<Response>;
|
|
7
|
+
export declare type LoaderOptions = {
|
|
8
|
+
/** fetch options or a custom fetch function */
|
|
9
|
+
fetch?: typeof fetch | FetchLike | RequestInit | null;
|
|
10
|
+
/** Do not throw on errors */
|
|
11
|
+
nothrow?: boolean;
|
|
12
|
+
/** loader selection, search first for supplied mimeType */
|
|
13
|
+
mimeType?: string;
|
|
14
|
+
/** loader selection, provide fallback mimeType is server does not provide */
|
|
15
|
+
fallbackMimeType?: string;
|
|
16
|
+
/** loader selection, avoid searching registered loaders */
|
|
17
|
+
ignoreRegisteredLoaders?: boolean;
|
|
18
|
+
/** Experimental: Supply a logger to the parser */
|
|
19
|
+
log?: any;
|
|
20
|
+
/** Size of each batch. `auto` matches batches to size of incoming chunks */
|
|
21
|
+
batchSize?: number | 'auto';
|
|
22
|
+
/** Minimal amount of time between batches */
|
|
23
|
+
batchDebounceMs?: number;
|
|
24
|
+
/** Stop loading after a given number of rows (compare SQL limit clause) */
|
|
25
|
+
limit?: 0;
|
|
26
|
+
/** Experimental: Stop loading after reaching */
|
|
27
|
+
_limitMB?: 0;
|
|
28
|
+
/** Generate metadata batches */
|
|
29
|
+
metadata?: boolean;
|
|
30
|
+
/** Transforms to run on incoming batches */
|
|
31
|
+
transforms?: TransformBatches[];
|
|
32
|
+
/** CDN load workers from */
|
|
33
|
+
CDN?: string;
|
|
34
|
+
/** Set to `false` to disable workers */
|
|
35
|
+
worker?: boolean;
|
|
36
|
+
/** Number of concurrent workers (per loader) on desktop browser */
|
|
37
|
+
maxConcurrency?: number;
|
|
38
|
+
/** Number of concurrent workers (per loader) on mobile browsers */
|
|
39
|
+
maxMobileConcurrency?: number;
|
|
40
|
+
/** Set to `false` to prevent reuse workers */
|
|
41
|
+
reuseWorkers?: boolean;
|
|
42
|
+
/** set to 'test' to run worker type */
|
|
43
|
+
_workerType?: string;
|
|
44
|
+
/** @deprecated `options.batchType` removed, Use `options.<loader>.type` instead */
|
|
45
|
+
batchType?: 'row' | 'columnar' | 'arrow';
|
|
46
|
+
/** @deprecated `options.throw removed`, Use `options.nothrow` instead */
|
|
47
|
+
throws?: boolean;
|
|
48
|
+
/** @deprecated `options.dataType` no longer used */
|
|
49
|
+
dataType?: any;
|
|
50
|
+
/** @deprecated `options.uri` no longer used */
|
|
51
|
+
uri?: any;
|
|
52
|
+
/** @deprecated `options.method` removed. Use `options.fetch.method` */
|
|
53
|
+
method?: any;
|
|
54
|
+
/** @deprecated `options.headers` removed. Use `options.fetch.headers` */
|
|
55
|
+
headers?: any;
|
|
56
|
+
/** @deprecated `options.body` removed. Use `options.fetch.body` */
|
|
57
|
+
body?: any;
|
|
58
|
+
/** @deprecated `options.mode` removed. Use `options.fetch.mode` */
|
|
59
|
+
mode?: any;
|
|
60
|
+
/** @deprecated `options.credentials` removed. Use `options.fetch.credentials` */
|
|
61
|
+
credentials?: any;
|
|
62
|
+
/** @deprecated `options.cache` removed. Use `options.fetch.cache` */
|
|
63
|
+
cache?: any;
|
|
64
|
+
/** @deprecated `options.redirect` removed. Use `options.fetch.redirect` */
|
|
65
|
+
redirect?: any;
|
|
66
|
+
/** @deprecated `options.referrer` removed. Use `options.fetch.referrer` */
|
|
67
|
+
referrer?: any;
|
|
68
|
+
/** @deprecated `options.referrerPolicy` removed. Use `options.fetch.referrerPolicy` */
|
|
69
|
+
referrerPolicy?: any;
|
|
70
|
+
/** @deprecated `options.integrity` removed. Use `options.fetch.integrity` */
|
|
71
|
+
integrity?: any;
|
|
72
|
+
/** @deprecated `options.keepalive` removed. Use `options.fetch.keepalive` */
|
|
73
|
+
keepalive?: any;
|
|
74
|
+
/** @deprecated `options.signal` removed. Use `options.fetch.signal` */
|
|
75
|
+
signal?: any;
|
|
76
|
+
[loaderId: string]: any;
|
|
77
|
+
};
|
|
78
|
+
declare type PreloadOptions = {
|
|
79
|
+
[key: string]: any;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* A worker loader definition that can be used with `@loaders.gl/core` functions
|
|
83
|
+
*/
|
|
84
|
+
export declare type Loader = {
|
|
85
|
+
name: string;
|
|
86
|
+
id: string;
|
|
87
|
+
module: string;
|
|
88
|
+
version: string;
|
|
89
|
+
worker?: string | boolean;
|
|
90
|
+
options: object;
|
|
91
|
+
deprecatedOptions?: object;
|
|
92
|
+
category?: string;
|
|
93
|
+
extensions: string[];
|
|
94
|
+
mimeTypes: string[];
|
|
95
|
+
binary?: boolean;
|
|
96
|
+
text?: boolean;
|
|
97
|
+
tests?: (((ArrayBuffer: any) => boolean) | ArrayBuffer | string)[];
|
|
98
|
+
supported?: boolean;
|
|
99
|
+
testText?: (string: any) => boolean;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* A "bundled" loader definition that can be used with `@loaders.gl/core` functions
|
|
103
|
+
* If a worker loader is supported it will also be supported.
|
|
104
|
+
*/
|
|
105
|
+
export declare type LoaderWithParser = Loader & {
|
|
106
|
+
testText?: (string: any) => boolean;
|
|
107
|
+
parse: Parse;
|
|
108
|
+
preload?: Preload;
|
|
109
|
+
parseSync?: ParseSync;
|
|
110
|
+
parseText?: ParseText;
|
|
111
|
+
parseTextSync?: ParseTextSync;
|
|
112
|
+
parseInBatches?: ParseInBatches;
|
|
113
|
+
parseFileInBatches?: ParseFileInBatches;
|
|
114
|
+
};
|
|
115
|
+
/** Options for writers */
|
|
116
|
+
export declare type WriterOptions = {};
|
|
117
|
+
/**
|
|
118
|
+
* A writer definition that can be used with `@loaders.gl/core` functions
|
|
119
|
+
*/
|
|
120
|
+
export declare type Writer = {
|
|
121
|
+
name: string;
|
|
122
|
+
id: string;
|
|
123
|
+
module: string;
|
|
124
|
+
version: string;
|
|
125
|
+
options: object;
|
|
126
|
+
deprecatedOptions?: object;
|
|
127
|
+
binary?: boolean;
|
|
128
|
+
extensions?: string[];
|
|
129
|
+
mimeTypes?: string[];
|
|
130
|
+
text?: boolean;
|
|
131
|
+
encode?: Encode;
|
|
132
|
+
encodeSync?: EncodeSync;
|
|
133
|
+
encodeInBatches?: EncodeInBatches;
|
|
134
|
+
encodeURLtoURL?: EncodeURLtoURL;
|
|
135
|
+
encodeText?: EncodeText;
|
|
136
|
+
};
|
|
137
|
+
export declare type LoaderContext = {
|
|
138
|
+
loaders?: Loader[] | null;
|
|
139
|
+
url?: string;
|
|
140
|
+
fetch: typeof fetch;
|
|
141
|
+
parse: (arrayBuffer: ArrayBuffer, loaders?: any, options?: LoaderOptions, context?: LoaderContext) => Promise<any>;
|
|
142
|
+
parseSync?: (arrayBuffer: ArrayBuffer, loaders?: any, options?: LoaderOptions, context?: LoaderContext) => any;
|
|
143
|
+
parseInBatches?: (iterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>, loaders?: any, options?: LoaderOptions, context?: LoaderContext) => AsyncIterable<any> | Promise<AsyncIterable<any>>;
|
|
144
|
+
};
|
|
145
|
+
declare type Parse = (arrayBuffer: ArrayBuffer, options?: LoaderOptions, context?: LoaderContext) => Promise<any>;
|
|
146
|
+
declare type ParseSync = (arrayBuffer: ArrayBuffer, options?: LoaderOptions, context?: LoaderContext) => any;
|
|
147
|
+
declare type ParseText = (text: string, options?: LoaderOptions) => Promise<any>;
|
|
148
|
+
declare type ParseTextSync = (text: string, options?: LoaderOptions) => any;
|
|
149
|
+
declare type ParseInBatches = (iterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>, options?: LoaderOptions, context?: LoaderContext) => AsyncIterable<any>;
|
|
150
|
+
declare type ParseFileInBatches = (file: Blob, options?: LoaderOptions, context?: LoaderContext) => AsyncIterable<any>;
|
|
151
|
+
declare type Encode = (data: any, options?: WriterOptions) => Promise<ArrayBuffer>;
|
|
152
|
+
declare type EncodeSync = (data: any, options?: WriterOptions) => ArrayBuffer;
|
|
153
|
+
declare type EncodeText = Function;
|
|
154
|
+
declare type EncodeInBatches = Function;
|
|
155
|
+
declare type EncodeURLtoURL = (inputUrl: string, outputUrl: string, options?: WriterOptions) => Promise<string>;
|
|
156
|
+
declare type Preload = (url: string, options?: PreloadOptions) => any;
|
|
157
|
+
export declare type TransformBatches = (asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>) => AsyncIterable<ArrayBuffer>;
|
|
158
|
+
/** Types that can be synchronously parsed */
|
|
159
|
+
export declare type SyncDataType = string | ArrayBuffer;
|
|
160
|
+
/** Types that can be parsed async */
|
|
161
|
+
export declare type DataType = string | ArrayBuffer | File | Blob | Response | ReadableStream | Iterable<ArrayBuffer> | AsyncIterable<ArrayBuffer>;
|
|
162
|
+
/** Types that can be parsed in batches */
|
|
163
|
+
export declare type BatchableDataType = DataType | Iterable<ArrayBuffer> | AsyncIterable<ArrayBuffer> | Promise<AsyncIterable<ArrayBuffer>>;
|
|
164
|
+
/**
|
|
165
|
+
* A FileSystem interface can encapsulate a FileList, a ZipFile, a GoogleDrive etc.
|
|
166
|
+
*/
|
|
167
|
+
export interface IFileSystem {
|
|
168
|
+
/**
|
|
169
|
+
* Return a list of file names
|
|
170
|
+
* @param dirname directory name. file system root directory if omitted
|
|
171
|
+
*/
|
|
172
|
+
readdir(dirname?: string, options?: {
|
|
173
|
+
recursive?: boolean;
|
|
174
|
+
}): Promise<string[]>;
|
|
175
|
+
/**
|
|
176
|
+
* Gets information from a local file from the filesystem
|
|
177
|
+
* @param filename file name to stat
|
|
178
|
+
* @param options currently unused
|
|
179
|
+
* @throws if filename is not in local filesystem
|
|
180
|
+
*/
|
|
181
|
+
stat(filename: string, options?: object): Promise<{
|
|
182
|
+
size: number;
|
|
183
|
+
}>;
|
|
184
|
+
/**
|
|
185
|
+
* Fetches a local file from the filesystem (or a URL)
|
|
186
|
+
* @param filename
|
|
187
|
+
* @param options
|
|
188
|
+
*/
|
|
189
|
+
fetch(filename: string, options?: object): Promise<Response>;
|
|
190
|
+
}
|
|
191
|
+
declare type ReadOptions = {
|
|
192
|
+
buffer?: ArrayBuffer;
|
|
193
|
+
offset?: number;
|
|
194
|
+
length?: number;
|
|
195
|
+
position?: number;
|
|
196
|
+
};
|
|
197
|
+
export interface IRandomAccessReadFileSystem extends IFileSystem {
|
|
198
|
+
open(path: string, flags: any, mode?: any): Promise<any>;
|
|
199
|
+
close(fd: any): Promise<void>;
|
|
200
|
+
fstat(fd: any): Promise<object>;
|
|
201
|
+
read(fd: any, options?: ReadOptions): Promise<{
|
|
202
|
+
bytesRead: number;
|
|
203
|
+
buffer: Buffer;
|
|
204
|
+
}>;
|
|
205
|
+
}
|
|
206
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/loader-utils",
|
|
3
|
-
"version": "3.1.0-alpha.
|
|
3
|
+
"version": "3.1.0-alpha.5",
|
|
4
4
|
"description": "Framework-independent loaders for 3D graphics formats",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
"mesh",
|
|
18
18
|
"point cloud"
|
|
19
19
|
],
|
|
20
|
-
"types": "
|
|
21
|
-
"main": "dist/index.js",
|
|
22
|
-
"module": "dist/index.js",
|
|
20
|
+
"types": "dist/index.d.ts",
|
|
21
|
+
"main": "dist/es5/index.js",
|
|
22
|
+
"module": "dist/esm/index.js",
|
|
23
23
|
"sideEffects": false,
|
|
24
24
|
"files": [
|
|
25
25
|
"src",
|
|
@@ -27,25 +27,30 @@
|
|
|
27
27
|
"README.md"
|
|
28
28
|
],
|
|
29
29
|
"browser": {
|
|
30
|
-
"./src/lib/node/buffer
|
|
31
|
-
"./src/lib/node/buffer
|
|
32
|
-
"./dist/es5/lib/node/buffer
|
|
33
|
-
"./dist/esm/lib/node/buffer
|
|
30
|
+
"./src/lib/node/buffer.ts": false,
|
|
31
|
+
"./src/lib/node/buffer.js": false,
|
|
32
|
+
"./dist/es5/lib/node/buffer.js": false,
|
|
33
|
+
"./dist/esm/lib/node/buffer.js": false,
|
|
34
34
|
"./src/lib/node/fs.ts": false,
|
|
35
35
|
"./src/lib/node/fs.js": false,
|
|
36
36
|
"./dist/es5/lib/node/fs.js": false,
|
|
37
37
|
"./dist/esm/lib/node/fs.js": false,
|
|
38
|
+
"./src/lib/node/util.ts": false,
|
|
39
|
+
"./src/lib/node/util.js": false,
|
|
40
|
+
"./dist/es5/lib/node/util.js": false,
|
|
41
|
+
"./dist/esm/lib/node/util.js": false,
|
|
38
42
|
"fs": false,
|
|
39
43
|
"util": false
|
|
40
44
|
},
|
|
41
45
|
"scripts": {
|
|
42
46
|
"pre-build-disabled": "npm run build-bundle",
|
|
47
|
+
"post-build": "tsc",
|
|
43
48
|
"build-bundle": "webpack --config ../../scripts/webpack/bundle.js"
|
|
44
49
|
},
|
|
45
50
|
"dependencies": {
|
|
46
51
|
"@babel/runtime": "^7.3.1",
|
|
47
|
-
"@loaders.gl/worker-utils": "3.1.0-alpha.
|
|
52
|
+
"@loaders.gl/worker-utils": "3.1.0-alpha.5",
|
|
48
53
|
"@probe.gl/stats": "^3.4.0"
|
|
49
54
|
},
|
|
50
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "352241dd910a8c6307a235dadbe154ca915b885b"
|
|
51
56
|
}
|
package/src/index.ts
CHANGED
|
@@ -64,17 +64,35 @@ export {forEach, concatenateArrayBuffersAsync} from './lib/iterators/async-itera
|
|
|
64
64
|
// REQUEST UTILS
|
|
65
65
|
export {default as RequestScheduler} from './lib/request-utils/request-scheduler';
|
|
66
66
|
|
|
67
|
-
//
|
|
68
|
-
import * as path from './lib/path-utils/path';
|
|
69
|
-
export {path};
|
|
67
|
+
// PATH HELPERS
|
|
70
68
|
export {setPathPrefix, getPathPrefix, resolvePath} from './lib/path-utils/file-aliases';
|
|
71
69
|
export {addAliases as _addAliases} from './lib/path-utils/file-aliases';
|
|
72
70
|
|
|
73
|
-
//
|
|
74
|
-
|
|
75
|
-
|
|
71
|
+
// MICRO LOADERS
|
|
72
|
+
export {JSONLoader} from './json-loader';
|
|
73
|
+
|
|
74
|
+
// NODE support
|
|
75
|
+
|
|
76
|
+
// Node.js emulation (can be used in browser)
|
|
77
|
+
|
|
78
|
+
// `path` replacement (avoids bundling big path polyfill)
|
|
79
|
+
import * as path from './lib/path-utils/path';
|
|
80
|
+
export {path};
|
|
76
81
|
|
|
77
|
-
//
|
|
82
|
+
// Avoid direct use of `Buffer` which pulls in 50KB polyfill
|
|
78
83
|
export {isBuffer, toBuffer, bufferToArrayBuffer} from './lib/binary-utils/buffer-utils';
|
|
79
84
|
|
|
80
|
-
|
|
85
|
+
// Note.js wrappers (can be safely imported, but not used in browser)
|
|
86
|
+
|
|
87
|
+
// Use instead of importing 'util'
|
|
88
|
+
import * as util from './lib/node/util';
|
|
89
|
+
export {util};
|
|
90
|
+
// TODO - remove
|
|
91
|
+
export {promisify} from './lib/node/util';
|
|
92
|
+
|
|
93
|
+
// Use instead of importing 'fs';`
|
|
94
|
+
import * as fs from './lib/node/fs';
|
|
95
|
+
export {fs};
|
|
96
|
+
|
|
97
|
+
// EXPERIMENTAL
|
|
98
|
+
export {default as _NodeFileSystem} from './lib/filesystems/node-filesystem';
|
|
@@ -20,7 +20,7 @@ export {self_ as self, window_ as window, global_ as global, document_ as docume
|
|
|
20
20
|
/** true if running in a browser */
|
|
21
21
|
export const isBrowser: boolean =
|
|
22
22
|
// @ts-ignore process does not exist on browser
|
|
23
|
-
typeof process !== 'object' || String(process) !== '[object process]' || process.browser;
|
|
23
|
+
Boolean(typeof process !== 'object' || String(process) !== '[object process]' || process.browser);
|
|
24
24
|
|
|
25
25
|
/** true if running in a worker thread */
|
|
26
26
|
export const isWorker: boolean = typeof importScripts === 'function';
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import * as fs from '../node/fs';
|
|
2
|
+
import {IFileSystem, IRandomAccessReadFileSystem} from '../../types';
|
|
3
|
+
// import {fetchFile} from "../fetch/fetch-file"
|
|
4
|
+
// import {selectLoader} from "../api/select-loader";
|
|
5
|
+
|
|
6
|
+
type Stat = {
|
|
7
|
+
size: number;
|
|
8
|
+
isDirectory: () => boolean;
|
|
9
|
+
info?: fs.Stats;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
type ReadOptions = {
|
|
13
|
+
buffer?: Buffer;
|
|
14
|
+
offset?: number;
|
|
15
|
+
length?: number;
|
|
16
|
+
position?: number;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* FileSystem pass-through for Node.js
|
|
21
|
+
* Compatible with BrowserFileSystem.
|
|
22
|
+
* @param options
|
|
23
|
+
*/
|
|
24
|
+
export default class NodeFileSystem implements IFileSystem, IRandomAccessReadFileSystem {
|
|
25
|
+
// implements IFileSystem
|
|
26
|
+
constructor(options: {[key: string]: any}) {
|
|
27
|
+
this.fetch = options._fetch;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async readdir(dirname = '.', options?: {}): Promise<any[]> {
|
|
31
|
+
return await fs.readdir(dirname, options);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async stat(path: string, options?: {}): Promise<Stat> {
|
|
35
|
+
const info = await fs.stat(path, options);
|
|
36
|
+
return {size: Number(info.size), isDirectory: () => false, info};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async fetch(path: string, options: {[key: string]: any}) {
|
|
40
|
+
// Falls back to handle https:/http:/data: etc fetches
|
|
41
|
+
// eslint-disable-next-line
|
|
42
|
+
const fallbackFetch = options.fetch || this.fetch;
|
|
43
|
+
return fallbackFetch(path, options);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// implements IRandomAccessFileSystem
|
|
47
|
+
async open(path: string, flags: string | number, mode?: any): Promise<number> {
|
|
48
|
+
return await fs.open(path, flags);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async close(fd: number): Promise<void> {
|
|
52
|
+
return await fs.close(fd);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async fstat(fd: number): Promise<Stat> {
|
|
56
|
+
const info = await fs.fstat(fd);
|
|
57
|
+
return info;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async read(
|
|
61
|
+
fd: number,
|
|
62
|
+
// @ts-ignore Possibly null
|
|
63
|
+
{buffer = null, offset = 0, length = buffer.byteLength, position = null}: ReadOptions
|
|
64
|
+
): Promise<{bytesRead: number; buffer: Buffer}> {
|
|
65
|
+
let totalBytesRead = 0;
|
|
66
|
+
// Read in loop until we get required number of bytes
|
|
67
|
+
while (totalBytesRead < length) {
|
|
68
|
+
const {bytesRead} = await fs.read(
|
|
69
|
+
fd,
|
|
70
|
+
buffer,
|
|
71
|
+
offset + totalBytesRead,
|
|
72
|
+
length - totalBytesRead,
|
|
73
|
+
position + totalBytesRead
|
|
74
|
+
);
|
|
75
|
+
totalBytesRead += bytesRead;
|
|
76
|
+
}
|
|
77
|
+
return {bytesRead: totalBytesRead, buffer};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
File without changes
|
package/src/lib/node/fs.ts
CHANGED
|
@@ -1,22 +1,38 @@
|
|
|
1
1
|
// fs wrapper (promisified fs + avoids bundling fs in browsers)
|
|
2
2
|
import fs from 'fs';
|
|
3
|
-
import {toArrayBuffer} from './buffer
|
|
4
|
-
import {promisify} from 'util';
|
|
3
|
+
import {toArrayBuffer} from './buffer';
|
|
4
|
+
import {promisify} from './util';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
throw new Error(`${fsFunction} not available in browser`);
|
|
8
|
-
};
|
|
6
|
+
export type {Stats} from 'fs';
|
|
9
7
|
|
|
10
|
-
|
|
8
|
+
// paths
|
|
9
|
+
|
|
10
|
+
/** Wrapper for Node.js fs method */
|
|
11
|
+
export const readdir = promisify(fs.readdir);
|
|
12
|
+
/** Wrapper for Node.js fs method */
|
|
13
|
+
export const stat = promisify(fs.stat);
|
|
14
|
+
|
|
15
|
+
/** Wrapper for Node.js fs method */
|
|
16
|
+
export const readFile = promisify(fs.readFile);
|
|
17
|
+
/** Wrapper for Node.js fs method */
|
|
18
|
+
export const readFileSync = fs.readFileSync;
|
|
19
|
+
/** Wrapper for Node.js fs method */
|
|
20
|
+
export const writeFile = promisify(fs.writeFile);
|
|
21
|
+
/** Wrapper for Node.js fs method */
|
|
22
|
+
export const writeFileSync = fs.writeFileSync;
|
|
11
23
|
|
|
12
|
-
|
|
13
|
-
export const close = fs?.close ? promisify(fs.close) : error('fs.close');
|
|
14
|
-
export const read = fs?.read ? promisify(fs.read) : error('fs.read');
|
|
24
|
+
// file descriptors
|
|
15
25
|
|
|
16
|
-
|
|
17
|
-
export const
|
|
18
|
-
|
|
19
|
-
export const
|
|
26
|
+
/** Wrapper for Node.js fs method */
|
|
27
|
+
export const open = promisify(fs.open);
|
|
28
|
+
/** Wrapper for Node.js fs method */
|
|
29
|
+
export const close = promisify(fs.close);
|
|
30
|
+
/** Wrapper for Node.js fs method */
|
|
31
|
+
export const read = promisify(fs.read);
|
|
32
|
+
/** Wrapper for Node.js fs method */
|
|
33
|
+
export const fstat = promisify(fs.fstat);
|
|
34
|
+
|
|
35
|
+
export const isSupported = Boolean(fs);
|
|
20
36
|
|
|
21
37
|
export async function _readToArrayBuffer(fd: number, start: number, length: number) {
|
|
22
38
|
const buffer = Buffer.alloc(length);
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
// Beginning of a minimal implementation of the Node.js path API, that doesn't pull in big polyfills.
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Replacement for Node.js path.filename
|
|
5
|
+
* @param url
|
|
6
|
+
*/
|
|
7
|
+
export function filename(url: string): string {
|
|
8
|
+
const slashIndex = url && url.lastIndexOf('/');
|
|
9
|
+
return slashIndex >= 0 ? url.substr((slashIndex as number) + 1) : '';
|
|
10
|
+
}
|
|
11
|
+
|
|
3
12
|
/**
|
|
4
13
|
* Replacement for Node.js path.dirname
|
|
5
14
|
* @param url
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":["assert","isBrowser","isWorker","nodeVersion","self","window","global","document","createLoaderWorker","parseWithWorker","canParseWithWorker","parseJSON","toArrayBuffer","sliceArrayBuffer","concatenateArrayBuffers","concatenateTypedArrays","compareArrayBuffers","padToNBytes","copyToArray","copyArrayBuffer","copyPaddedArrayBufferToDataView","copyPaddedStringToDataView","padStringToByteAlignment","copyStringToDataView","copyBinaryToDataView","getFirstCharacters","getMagicString","makeTextEncoderIterator","makeTextDecoderIterator","makeLineIterator","makeNumberedLineIterator","forEach","concatenateArrayBuffersAsync","default","RequestScheduler","path","setPathPrefix","getPathPrefix","resolvePath","addAliases","_addAliases","fs","isBuffer","toBuffer","bufferToArrayBuffer","JSONLoader"],"mappings":"AAgBA,SAAQA,MAAR,QAAqB,wBAArB;AACA,SACEC,SADF,EAEEC,QAFF,EAGEC,WAHF,EAIEC,IAJF,EAKEC,MALF,EAMEC,MANF,EAOEC,QAPF,QAQO,yBARP;AAWA,SAAQC,kBAAR,QAAiC,gDAAjC;AACA,SAAQC,eAAR,EAAyBC,kBAAzB,QAAkD,6CAAlD;AAGA,SAAQC,SAAR,QAAwB,+BAAxB;AAGA,SACEC,aADF,EAEEC,gBAFF,EAGEC,uBAHF,EAIEC,sBAJF,EAKEC,mBALF,QAMO,uCANP;AAOA,SAAQC,WAAR,EAAqBC,WAArB,EAAkCC,eAAlC,QAAwD,sCAAxD;AACA,SACEC,+BADF,EAEEC,0BAFF,QAGO,sCAHP;AAIA,SACEC,wBADF,EAEEC,oBAFF,EAGEC,oBAHF,QAIO,iCAJP;AAKA,SAAQC,kBAAR,EAA4BC,cAA5B,QAAiD,yCAAjD;AAGA,SACEC,uBADF,EAEEC,uBAFF,EAGEC,gBAHF,EAIEC,wBAJF,QAKO,gCALP;AAMA,SAAQC,OAAR,EAAiBC,4BAAjB,QAAoD,iCAApD;AAGA,SAAQC,OAAO,IAAIC,gBAAnB,QAA0C,uCAA1C;AAGA,OAAO,KAAKC,IAAZ,MAAsB,uBAAtB;AACA,SAAQA,IAAR;AACA,SAAQC,aAAR,EAAuBC,aAAvB,EAAsCC,WAAtC,QAAwD,+BAAxD;AACA,SAAQC,UAAU,IAAIC,WAAtB,QAAwC,+BAAxC;AAGA,OAAO,KAAKC,EAAZ,MAAoB,eAApB;AACA,SAAQA,EAAR;AAGA,SAAQC,QAAR,EAAkBC,QAAlB,EAA4BC,mBAA5B,QAAsD,iCAAtD;AAEA,SAAQC,UAAR,QAAyB,eAAzB","sourcesContent":["// TYPES\nexport type {\n Loader,\n LoaderWithParser,\n LoaderContext,\n LoaderOptions,\n Writer,\n WriterOptions,\n DataType,\n SyncDataType,\n BatchableDataType,\n IFileSystem,\n IRandomAccessReadFileSystem\n} from './types';\n\n// GENERAL UTILS\nexport {assert} from './lib/env-utils/assert';\nexport {\n isBrowser,\n isWorker,\n nodeVersion,\n self,\n window,\n global,\n document\n} from './lib/env-utils/globals';\n\n// LOADERS.GL-SPECIFIC WORKER UTILS\nexport {createLoaderWorker} from './lib/worker-loader-utils/create-loader-worker';\nexport {parseWithWorker, canParseWithWorker} from './lib/worker-loader-utils/parse-with-worker';\n\n// PARSER UTILS\nexport {parseJSON} from './lib/parser-utils/parse-json';\n\n// MEMORY COPY UTILS\nexport {\n toArrayBuffer,\n sliceArrayBuffer,\n concatenateArrayBuffers,\n concatenateTypedArrays,\n compareArrayBuffers\n} from './lib/binary-utils/array-buffer-utils';\nexport {padToNBytes, copyToArray, copyArrayBuffer} from './lib/binary-utils/memory-copy-utils';\nexport {\n copyPaddedArrayBufferToDataView,\n copyPaddedStringToDataView\n} from './lib/binary-utils/binary-copy-utils';\nexport {\n padStringToByteAlignment,\n copyStringToDataView,\n copyBinaryToDataView\n} from './lib/binary-utils/encode-utils';\nexport {getFirstCharacters, getMagicString} from './lib/binary-utils/get-first-characters';\n\n// ITERATOR UTILS\nexport {\n makeTextEncoderIterator,\n makeTextDecoderIterator,\n makeLineIterator,\n makeNumberedLineIterator\n} from './lib/iterators/text-iterators';\nexport {forEach, concatenateArrayBuffersAsync} from './lib/iterators/async-iteration';\n\n// REQUEST UTILS\nexport {default as RequestScheduler} from './lib/request-utils/request-scheduler';\n\n// NODE `path`` REPLACEMENT\nimport * as path from './lib/path-utils/path';\nexport {path};\nexport {setPathPrefix, getPathPrefix, resolvePath} from './lib/path-utils/file-aliases';\nexport {addAliases as _addAliases} from './lib/path-utils/file-aliases';\n\n// NODE `fs` WRAPPERS\nimport * as fs from './lib/node/fs';\nexport {fs};\n\n// NODE `buffer` WRAPPERS\nexport {isBuffer, toBuffer, bufferToArrayBuffer} from './lib/binary-utils/buffer-utils';\n\nexport {JSONLoader} from './json-loader';\n"],"file":"index.js"}
|
package/dist/json-loader.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/json-loader.ts"],"names":["VERSION","JSONLoader","name","id","module","version","extensions","mimeTypes","category","text","parseTextSync","parse","arrayBuffer","TextDecoder","decode","options","JSON","_typecheckJSONLoader"],"mappings":"AAIA,MAAMA,OAAO,GAAG,2BAAuB,WAAvB,qBAAmD,QAAnE;AAMA,OAAO,MAAMC,UAAU,GAAG;AACxBC,EAAAA,IAAI,EAAE,MADkB;AAExBC,EAAAA,EAAE,EAAE,MAFoB;AAGxBC,EAAAA,MAAM,EAAE,MAHgB;AAIxBC,EAAAA,OAAO,EAAEL,OAJe;AAKxBM,EAAAA,UAAU,EAAE,CAAC,MAAD,EAAS,SAAT,CALY;AAMxBC,EAAAA,SAAS,EAAE,CAAC,kBAAD,CANa;AAOxBC,EAAAA,QAAQ,EAAE,MAPc;AAQxBC,EAAAA,IAAI,EAAE,IARkB;AASxBC,EAAAA,aATwB;AAUxBC,EAAAA,KAAK,EAAE,MAAOC,WAAP,IAAuBF,aAAa,CAAC,IAAIG,WAAJ,GAAkBC,MAAlB,CAAyBF,WAAzB,CAAD,CAVnB;AAWxBG,EAAAA,OAAO,EAAE;AAXe,CAAnB;;AAeP,SAASL,aAAT,CAAuBD,IAAvB,EAA6B;AAC3B,SAAOO,IAAI,CAACL,KAAL,CAAWF,IAAX,CAAP;AACD;;AAED,OAAO,MAAMQ,oBAAsC,GAAGhB,UAA/C","sourcesContent":["import type {LoaderWithParser} from './types';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\n/**\n * A JSON Micro loader (minimal bundle size)\n * Alternative to `@loaders.gl/json`\n */\nexport const JSONLoader = {\n name: 'JSON',\n id: 'json',\n module: 'json',\n version: VERSION,\n extensions: ['json', 'geojson'],\n mimeTypes: ['application/json'],\n category: 'json',\n text: true,\n parseTextSync,\n parse: async (arrayBuffer) => parseTextSync(new TextDecoder().decode(arrayBuffer)),\n options: {}\n};\n\n// TODO - deprecated\nfunction parseTextSync(text) {\n return JSON.parse(text);\n}\n\nexport const _typecheckJSONLoader: LoaderWithParser = JSONLoader;\n"],"file":"json-loader.js"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/binary-utils/array-buffer-utils.ts"],"names":["isBuffer","bufferToArrayBuffer","toArrayBuffer","data","ArrayBuffer","isView","byteOffset","byteLength","buffer","slice","text","uint8Array","TextEncoder","encode","_toArrayBuffer","Error","compareArrayBuffers","arrayBuffer1","arrayBuffer2","array1","Uint8Array","array2","i","length","concatenateArrayBuffers","sources","sourceArrays","map","source2","reduce","typedArray","result","offset","sourceArray","set","concatenateTypedArrays","typedArrays","arrays","TypedArrayConstructor","constructor","sumLength","acc","value","array","sliceArrayBuffer","arrayBuffer","subArray","undefined","subarray","arrayCopy"],"mappings":"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","sourcesContent":["import {TypedArray} from '../../types';\nimport {isBuffer, bufferToArrayBuffer} from './buffer-utils';\n\n/**\n * Convert an object to an array buffer\n */\nexport function toArrayBuffer(data: any): ArrayBuffer {\n // Note: Should be called first, Buffers can trigger other detections below\n if (isBuffer(data)) {\n return bufferToArrayBuffer(data);\n }\n\n if (data instanceof ArrayBuffer) {\n return data;\n }\n\n // Careful - Node Buffers look like Uint8Arrays (keep after isBuffer)\n if (ArrayBuffer.isView(data)) {\n if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) {\n return data.buffer;\n }\n return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);\n }\n\n if (typeof data === 'string') {\n const text = data;\n const uint8Array = new TextEncoder().encode(text);\n return uint8Array.buffer;\n }\n\n // HACK to support Blob polyfill\n if (data && typeof data === 'object' && data._toArrayBuffer) {\n return data._toArrayBuffer();\n }\n\n throw new Error('toArrayBuffer');\n}\n\n/**\n * compare two binary arrays for equality\n * @param {ArrayBuffer} a\n * @param {ArrayBuffer} b\n * @param {number} byteLength\n */\nexport function compareArrayBuffers(\n arrayBuffer1: ArrayBuffer,\n arrayBuffer2: ArrayBuffer,\n byteLength?: number\n): boolean {\n byteLength = byteLength || arrayBuffer1.byteLength;\n if (arrayBuffer1.byteLength < byteLength || arrayBuffer2.byteLength < byteLength) {\n return false;\n }\n const array1 = new Uint8Array(arrayBuffer1);\n const array2 = new Uint8Array(arrayBuffer2);\n for (let i = 0; i < array1.length; ++i) {\n if (array1[i] !== array2[i]) {\n return false;\n }\n }\n return true;\n}\n\n/**\n * Concatenate a sequence of ArrayBuffers\n * @return A concatenated ArrayBuffer\n */\nexport function concatenateArrayBuffers(...sources: (ArrayBuffer | Uint8Array)[]): ArrayBuffer {\n // Make sure all inputs are wrapped in typed arrays\n const sourceArrays = sources.map((source2) =>\n source2 instanceof ArrayBuffer ? new Uint8Array(source2) : source2\n );\n\n // Get length of all inputs\n const byteLength = sourceArrays.reduce((length, typedArray) => length + typedArray.byteLength, 0);\n\n // Allocate array with space for all inputs\n const result = new Uint8Array(byteLength);\n\n // Copy the subarrays\n let offset = 0;\n for (const sourceArray of sourceArrays) {\n result.set(sourceArray, offset);\n offset += sourceArray.byteLength;\n }\n\n // We work with ArrayBuffers, discard the typed array wrapper\n return result.buffer;\n}\n\n/**\n * Concatenate arbitrary count of typed arrays\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays\n * @param {...*} arrays - list of arrays. All arrays should be the same type\n * @return A concatenated TypedArray\n */\nexport function concatenateTypedArrays<T>(...typedArrays: T[]): T {\n // @ts-ignore\n const arrays = typedArrays as TypedArray[];\n // @ts-ignore\n const TypedArrayConstructor = (arrays && arrays.length > 1 && arrays[0].constructor) || null;\n if (!TypedArrayConstructor) {\n throw new Error(\n '\"concatenateTypedArrays\" - incorrect quantity of arguments or arguments have incompatible data types'\n );\n }\n\n const sumLength = arrays.reduce((acc, value) => acc + value.length, 0);\n // @ts-ignore typescript does not like dynamic constructors\n const result = new TypedArrayConstructor(sumLength);\n let offset = 0;\n for (const array of arrays) {\n result.set(array, offset);\n offset += array.length;\n }\n return result;\n}\n\n/**\n * Copy a view of an ArrayBuffer into new ArrayBuffer with byteOffset = 0\n * @param arrayBuffer\n * @param byteOffset\n * @param byteLength\n */\nexport function sliceArrayBuffer(\n arrayBuffer: ArrayBuffer,\n byteOffset: number,\n byteLength?: number\n): ArrayBuffer {\n const subArray =\n byteLength !== undefined\n ? new Uint8Array(arrayBuffer).subarray(byteOffset, byteOffset + byteLength)\n : new Uint8Array(arrayBuffer).subarray(byteOffset);\n const arrayCopy = new Uint8Array(subArray);\n return arrayCopy.buffer;\n}\n"],"file":"array-buffer-utils.js"}
|