@loaders.gl/polyfills 4.2.0-alpha.5 → 4.2.0-beta.1
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/crypto/node-hash.js +6 -1
- package/dist/fetch/headers-polyfill.js +1 -0
- package/dist/fetch/response-polyfill.d.ts.map +1 -1
- package/dist/fetch/response-polyfill.js +9 -1
- package/dist/file/blob-stream-controller.js +3 -2
- package/dist/file/blob-stream.js +1 -0
- package/dist/file/blob.js +6 -0
- package/dist/file/file-reader.js +16 -0
- package/dist/file/file.js +11 -6
- package/dist/file/install-file-polyfills.d.ts +3 -2
- package/dist/file/install-file-polyfills.d.ts.map +1 -1
- package/dist/filesystems/fetch-node.d.ts.map +1 -1
- package/dist/filesystems/fetch-node.js +2 -0
- package/dist/filesystems/node-file.d.ts.map +1 -1
- package/dist/filesystems/node-file.js +12 -2
- package/dist/filesystems/node-filesystem.d.ts.map +1 -1
- package/dist/filesystems/node-filesystem.js +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/load-library/require-utils.node.js +1 -1
- package/dist/streams/make-node-stream.d.ts.map +1 -1
- package/dist/streams/make-node-stream.js +4 -0
- package/package.json +7 -7
- package/src/fetch/response-polyfill.ts +2 -0
- package/src/filesystems/fetch-node.ts +2 -0
- package/src/filesystems/node-file.ts +4 -0
- package/src/filesystems/node-filesystem.ts +1 -0
- package/src/index.ts +1 -0
- package/src/load-library/require-utils.node.ts +1 -1
- package/src/streams/make-node-stream.ts +3 -2
package/dist/crypto/node-hash.js
CHANGED
|
@@ -6,9 +6,14 @@ import * as crypto from 'crypto'; // Node.js builtin
|
|
|
6
6
|
* @deprecated Warning, experimental class
|
|
7
7
|
*/
|
|
8
8
|
export class NodeHash extends Hash {
|
|
9
|
+
name = 'crypto-node';
|
|
10
|
+
options;
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
_algorithm;
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
_hash;
|
|
9
15
|
constructor(options) {
|
|
10
16
|
super();
|
|
11
|
-
this.name = 'crypto-node';
|
|
12
17
|
this.options = options;
|
|
13
18
|
if (!this.options?.crypto?.algorithm) {
|
|
14
19
|
throw new Error(this.name);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response-polyfill.d.ts","sourceRoot":"","sources":["../../src/fetch/response-polyfill.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,OAAO,EAAC,8BAA2B;AAoB3C,qBAAa,QAAQ;IACnB,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,OAAO,CAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC;gBAIrB,IAAI,KAAA,EACJ,OAAO,EAAE;QACP,OAAO,CAAC,MAAC;QACT,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,GAAG,EAAE,MAAM,CAAC;KACb;
|
|
1
|
+
{"version":3,"file":"response-polyfill.d.ts","sourceRoot":"","sources":["../../src/fetch/response-polyfill.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,OAAO,EAAC,8BAA2B;AAoB3C,qBAAa,QAAQ;IACnB,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,OAAO,CAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC;gBAIrB,IAAI,KAAA,EACJ,OAAO,EAAE;QACP,OAAO,CAAC,MAAC;QACT,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,GAAG,EAAE,MAAM,CAAC;KACb;IAyBH,IAAI,IAAI,QAKP;IAIK,WAAW;IAQX,IAAI;IAMJ,IAAI;IAKJ,IAAI;CAMX"}
|
|
@@ -20,9 +20,15 @@ const isReadableNodeStream = (x) => isObject(x) && isFunction(x.read) && isFunct
|
|
|
20
20
|
*/
|
|
21
21
|
import * as stream from 'stream';
|
|
22
22
|
export class Response {
|
|
23
|
+
ok;
|
|
24
|
+
status;
|
|
25
|
+
statusText;
|
|
26
|
+
headers;
|
|
27
|
+
url;
|
|
28
|
+
bodyUsed = false;
|
|
29
|
+
_body;
|
|
23
30
|
// TODO - handle ArrayBuffer, ArrayBufferView, Buffer
|
|
24
31
|
constructor(body, options) {
|
|
25
|
-
this.bodyUsed = false;
|
|
26
32
|
const { headers, status = 200, statusText = 'OK', url } = options || {};
|
|
27
33
|
this.url = url;
|
|
28
34
|
this.ok = status === 200;
|
|
@@ -34,9 +40,11 @@ export class Response {
|
|
|
34
40
|
this._body = decompressReadStream(body, headers);
|
|
35
41
|
}
|
|
36
42
|
else if (typeof body === 'string') {
|
|
43
|
+
// @ts-expect-error
|
|
37
44
|
this._body = stream.Readable.from([new TextEncoder().encode(body)]);
|
|
38
45
|
}
|
|
39
46
|
else {
|
|
47
|
+
// @ts-expect-error
|
|
40
48
|
this._body = stream.Readable.from([body || new ArrayBuffer(0)]);
|
|
41
49
|
}
|
|
42
50
|
}
|
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
* @see https://github.com/Gozala/web-blob
|
|
4
4
|
*/
|
|
5
5
|
export class BlobStreamController {
|
|
6
|
+
chunks;
|
|
7
|
+
isWorking = false;
|
|
8
|
+
isCancelled = false;
|
|
6
9
|
/**
|
|
7
10
|
* @param chunks
|
|
8
11
|
*/
|
|
9
12
|
constructor(chunks) {
|
|
10
|
-
this.isWorking = false;
|
|
11
|
-
this.isCancelled = false;
|
|
12
13
|
this.chunks = chunks;
|
|
13
14
|
}
|
|
14
15
|
/**
|
package/dist/file/blob-stream.js
CHANGED
package/dist/file/blob.js
CHANGED
|
@@ -5,6 +5,12 @@ import { BlobStream } from "./blob-stream.js";
|
|
|
5
5
|
* @see https://github.com/Gozala/web-blob
|
|
6
6
|
*/
|
|
7
7
|
export class BlobPolyfill {
|
|
8
|
+
// implements Blob {
|
|
9
|
+
/** The MIME type of the data contained in the Blob. If type is unknown, string is empty. */
|
|
10
|
+
type;
|
|
11
|
+
/** The size, in bytes, of the data contained in the Blob object. */
|
|
12
|
+
size;
|
|
13
|
+
parts;
|
|
8
14
|
/**
|
|
9
15
|
* @param [init]
|
|
10
16
|
* @param [options]
|
package/dist/file/file-reader.js
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
import { atob } from "../buffer/btoa.node.js";
|
|
2
2
|
export class FileReaderPolyfill {
|
|
3
|
+
// onload: ({result: any}) => void;
|
|
4
|
+
onload;
|
|
5
|
+
onabort;
|
|
6
|
+
onerror;
|
|
7
|
+
error;
|
|
8
|
+
onloadstart;
|
|
9
|
+
onloadend;
|
|
10
|
+
onprogress;
|
|
11
|
+
readyState;
|
|
12
|
+
result;
|
|
13
|
+
DONE;
|
|
14
|
+
EMPTY;
|
|
15
|
+
LOADING;
|
|
16
|
+
addEventListener;
|
|
17
|
+
removeEventListener;
|
|
18
|
+
dispatchEvent;
|
|
3
19
|
constructor() {
|
|
4
20
|
this.onload = null;
|
|
5
21
|
}
|
package/dist/file/file.js
CHANGED
|
@@ -5,6 +5,17 @@
|
|
|
5
5
|
*/
|
|
6
6
|
// @ts-ignore
|
|
7
7
|
export class FilePolyfill extends globalThis.Blob {
|
|
8
|
+
// implements File {
|
|
9
|
+
// public API
|
|
10
|
+
/** The name of the file referenced by the File object. */
|
|
11
|
+
name = '';
|
|
12
|
+
/** The path the URL of the File is relative to. */
|
|
13
|
+
webkitRelativePath = '';
|
|
14
|
+
/**
|
|
15
|
+
* Returns the last modified time of the file, in millisecond since the UNIX
|
|
16
|
+
* epoch (January 1st, 1970 at Midnight).
|
|
17
|
+
*/
|
|
18
|
+
lastModified;
|
|
8
19
|
/**
|
|
9
20
|
* @param init
|
|
10
21
|
* @param name - A USVString representing the file name or the path
|
|
@@ -13,12 +24,6 @@ export class FilePolyfill extends globalThis.Blob {
|
|
|
13
24
|
*/
|
|
14
25
|
constructor(init, name, options = {}) {
|
|
15
26
|
super(init, options);
|
|
16
|
-
// implements File {
|
|
17
|
-
// public API
|
|
18
|
-
/** The name of the file referenced by the File object. */
|
|
19
|
-
this.name = '';
|
|
20
|
-
/** The path the URL of the File is relative to. */
|
|
21
|
-
this.webkitRelativePath = '';
|
|
22
27
|
// Per File API spec https://w3c.github.io/FileAPI/#file-constructor
|
|
23
28
|
// Every "/" character of file name must be replaced with a ":".
|
|
24
29
|
/** @private */
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export declare
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export declare function installFilePolyfills(): NodeJS.Global;
|
|
3
|
+
export declare const File_: NodeJS.Global;
|
|
3
4
|
//# sourceMappingURL=install-file-polyfills.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"install-file-polyfills.d.ts","sourceRoot":"","sources":["../../src/file/install-file-polyfills.ts"],"names":[],"mappings":"AAIA,wBAAgB,oBAAoB,
|
|
1
|
+
{"version":3,"file":"install-file-polyfills.d.ts","sourceRoot":"","sources":["../../src/file/install-file-polyfills.ts"],"names":[],"mappings":";AAIA,wBAAgB,oBAAoB,kBAanC;AAED,eAAO,MAAM,KAAK,eAAyB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-node.d.ts","sourceRoot":"","sources":["../../src/filesystems/fetch-node.ts"],"names":[],"mappings":"AAeA;;;;;GAKG;AAEH,wBAAsB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,
|
|
1
|
+
{"version":3,"file":"fetch-node.d.ts","sourceRoot":"","sources":["../../src/filesystems/fetch-node.ts"],"names":[],"mappings":"AAeA;;;;;GAKG;AAEH,wBAAsB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,CA2DrF"}
|
|
@@ -47,9 +47,11 @@ export async function fetchNode(url, options) {
|
|
|
47
47
|
bodyStream = decompressReadStream(body, responseHeaders);
|
|
48
48
|
}
|
|
49
49
|
else if (typeof body === 'string') {
|
|
50
|
+
// @ts-expect-error
|
|
50
51
|
bodyStream = Readable.from([new TextEncoder().encode(body)]);
|
|
51
52
|
}
|
|
52
53
|
else {
|
|
54
|
+
// @ts-expect-error
|
|
53
55
|
bodyStream = Readable.from([body || new ArrayBuffer(0)]);
|
|
54
56
|
}
|
|
55
57
|
const status = 200;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-file.d.ts","sourceRoot":"","sources":["../../src/filesystems/node-file.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAE,YAAY,EAAE,IAAI,EAAC,MAAM,0BAA0B,CAAC;AAI/E,qBAAa,QAAS,YAAW,YAAY,EAAE,YAAY;IACzD,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;gBAEA,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,EAAE,IAAI,CAAC,EAAE,MAAM;
|
|
1
|
+
{"version":3,"file":"node-file.d.ts","sourceRoot":"","sources":["../../src/filesystems/node-file.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAE,YAAY,EAAE,IAAI,EAAC,MAAM,0BAA0B,CAAC;AAI/E,qBAAa,QAAS,YAAW,YAAY,EAAE,YAAY;IACzD,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;gBAEA,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,EAAE,IAAI,CAAC,EAAE,MAAM;IAWjE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAMtB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAcvC,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAcvC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAkBrB,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IA6BnE,KAAK,CACT,WAAW,EAAE,WAAW,EACxB,MAAM,GAAE,MAAM,GAAG,MAAU,EAC3B,MAAM,GAAE,MAA+B,GACtC,OAAO,CAAC,MAAM,CAAC;CAUnB"}
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { resolvePath } from '@loaders.gl/loader-utils';
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
export class NodeFile {
|
|
4
|
+
handle;
|
|
5
|
+
size;
|
|
6
|
+
bigsize;
|
|
7
|
+
url;
|
|
4
8
|
constructor(path, flags, mode) {
|
|
5
9
|
path = resolvePath(path);
|
|
6
10
|
this.handle = fs.openSync(path, flags, mode);
|
|
11
|
+
// @ts-expect-error Nodew 20?
|
|
7
12
|
const stats = fs.fstatSync(this.handle, { bigint: true });
|
|
8
13
|
this.size = Number(stats.size);
|
|
14
|
+
// @ts-expect-error
|
|
9
15
|
this.bigsize = stats.size;
|
|
10
16
|
this.url = path;
|
|
11
17
|
}
|
|
@@ -43,7 +49,9 @@ export class NodeFile {
|
|
|
43
49
|
});
|
|
44
50
|
}
|
|
45
51
|
async stat() {
|
|
46
|
-
return await new Promise((resolve, reject) =>
|
|
52
|
+
return await new Promise((resolve, reject) =>
|
|
53
|
+
// @ts-expect-error bigint typings
|
|
54
|
+
fs.fstat(this.handle, { bigint: true }, (err, info) => {
|
|
47
55
|
const stats = {
|
|
48
56
|
size: Number(info.size),
|
|
49
57
|
bigsize: info.size,
|
|
@@ -90,7 +98,9 @@ export class NodeFile {
|
|
|
90
98
|
}
|
|
91
99
|
}
|
|
92
100
|
async function readBytes(fd, uint8Array, offset, length, position) {
|
|
93
|
-
return await new Promise((resolve, reject) =>
|
|
101
|
+
return await new Promise((resolve, reject) =>
|
|
102
|
+
// @ts-expect-error bigint?
|
|
103
|
+
fs.read(fd, uint8Array, offset, length, position, (err, bytesRead) => err ? reject(err) : resolve(bytesRead)));
|
|
94
104
|
}
|
|
95
105
|
// TODO - implement streaming write
|
|
96
106
|
/*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-filesystem.d.ts","sourceRoot":"","sources":["../../src/filesystems/node-filesystem.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,IAAI,EAAE,sBAAsB,EAAC,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"node-filesystem.d.ts","sourceRoot":"","sources":["../../src/filesystems/node-filesystem.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,IAAI,EAAE,sBAAsB,EAAC,MAAM,0BAA0B,CAAC;AAGtE,OAAO,EAAC,QAAQ,EAAC,uBAAoB;AAMrC;;;;GAIG;AACH,qBAAa,cAAe,YAAW,sBAAsB;IAC3D,QAAQ,EAAE,OAAO,CAAQ;IACzB,QAAQ,EAAE,OAAO,CAAQ;;IAKnB,OAAO,CAAC,OAAO,SAAM,EAAE,OAAO,CAAC,EAAE,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAIpD,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IASjC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAInC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC;IAK5D,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,GAAE,GAAS,GAAG,OAAO,CAAC,QAAQ,CAAC;IAInE,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,GAAE,GAAG,GAAG,IAAU,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,QAAQ,CAAC;CAG7F"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// loaders.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
|
+
// @ts-expect-error
|
|
4
5
|
import fsPromise from 'fs/promises';
|
|
5
6
|
import { NodeFile } from "./node-file.js";
|
|
6
7
|
import { fetchNode } from "./fetch-node.js";
|
|
@@ -12,11 +13,10 @@ import { fetchNode } from "./fetch-node.js";
|
|
|
12
13
|
* @param options
|
|
13
14
|
*/
|
|
14
15
|
export class NodeFileSystem {
|
|
16
|
+
readable = true;
|
|
17
|
+
writable = true;
|
|
15
18
|
// implements FileSystem
|
|
16
|
-
constructor() {
|
|
17
|
-
this.readable = true;
|
|
18
|
-
this.writable = true;
|
|
19
|
-
}
|
|
19
|
+
constructor() { }
|
|
20
20
|
async readdir(dirname = '.', options) {
|
|
21
21
|
return await fsPromise.readdir(dirname, options);
|
|
22
22
|
}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAqBA,eAAO,MAAM,WAAW,QAAwC,CAAC;AAMjE,OAAO,EAAC,KAAK,IAAI,IAAI,EAAC,yCAAsC;AAC5D,OAAO,EAAC,KAAK,IAAI,IAAI,EAAC,yCAAsC;AAY5D,OAAO,EAAC,cAAc,EAAC,sCAAmC;AA8D1D,OAAO,EAAC,oBAAoB,EAAC,yCAAsC"}
|
package/dist/index.js
CHANGED
|
@@ -11,6 +11,7 @@ import { NodeFileSystem } from "./filesystems/node-filesystem.js";
|
|
|
11
11
|
import { fetchNode } from "./filesystems/fetch-node.js";
|
|
12
12
|
import { NodeHash } from "./crypto/node-hash.js";
|
|
13
13
|
// NODE VERSION
|
|
14
|
+
// @ts-expect-error
|
|
14
15
|
import { versions } from 'node:process';
|
|
15
16
|
export const nodeVersion = parseInt(versions.node.split('.')[0]);
|
|
16
17
|
// STREAM POLYFILLS
|
|
@@ -44,7 +44,7 @@ export async function requireFromFile(filename) {
|
|
|
44
44
|
if (!filename.startsWith('/')) {
|
|
45
45
|
filename = `${process.cwd()}/${filename}`;
|
|
46
46
|
}
|
|
47
|
-
const code =
|
|
47
|
+
const code = fs.readFileSync(filename, 'utf8');
|
|
48
48
|
return requireFromString(code);
|
|
49
49
|
}
|
|
50
50
|
// Dynamically require from string
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"make-node-stream.d.ts","sourceRoot":"","sources":["../../src/streams/make-node-stream.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,QAAQ,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAEjC,cAAM,SAAS;CAAG;AAElB,KAAK,YAAY,GAAG,MAAM,CAAC,QAAQ,GAAG,SAAS,CAAC;AAGhD,MAAM,MAAM,iBAAiB,GAAG,eAAe,CAAC;AAEhD,4CAA4C;AAC5C,wBAAgB,cAAc,CAAC,WAAW,EACxC,MAAM,EAAE,QAAQ,CAAC,WAAW,CAAC,GAAG,aAAa,CAAC,WAAW,CAAC,EAC1D,OAAO,CAAC,EAAE,eAAe,GACxB,YAAY,
|
|
1
|
+
{"version":3,"file":"make-node-stream.d.ts","sourceRoot":"","sources":["../../src/streams/make-node-stream.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,QAAQ,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAEjC,cAAM,SAAS;CAAG;AAElB,KAAK,YAAY,GAAG,MAAM,CAAC,QAAQ,GAAG,SAAS,CAAC;AAGhD,MAAM,MAAM,iBAAiB,GAAG,eAAe,CAAC;AAEhD,4CAA4C;AAC5C,wBAAgB,cAAc,CAAC,WAAW,EACxC,MAAM,EAAE,QAAQ,CAAC,WAAW,CAAC,GAAG,aAAa,CAAC,WAAW,CAAC,EAC1D,OAAO,CAAC,EAAE,eAAe,GACxB,YAAY,CASd"}
|
|
@@ -5,6 +5,7 @@ const Readable = Stream.Readable || _Readable;
|
|
|
5
5
|
/** Builds a node stream from an iterator */
|
|
6
6
|
export function makeNodeStream(source, options) {
|
|
7
7
|
// @ts-ignore AsyncGenerator
|
|
8
|
+
// prettier-ignore
|
|
8
9
|
const iterator = source[Symbol.asyncIterator]
|
|
9
10
|
? // @ts-ignore AsyncGenerator
|
|
10
11
|
source[Symbol.asyncIterator]()
|
|
@@ -13,6 +14,9 @@ export function makeNodeStream(source, options) {
|
|
|
13
14
|
return new AsyncIterableReadable(iterator, options);
|
|
14
15
|
}
|
|
15
16
|
class AsyncIterableReadable extends Readable {
|
|
17
|
+
_pulling;
|
|
18
|
+
_bytesMode;
|
|
19
|
+
_iterator;
|
|
16
20
|
constructor(it, options) {
|
|
17
21
|
super(options);
|
|
18
22
|
this._iterator = it;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/polyfills",
|
|
3
|
-
"version": "4.2.0-
|
|
3
|
+
"version": "4.2.0-beta.1",
|
|
4
4
|
"description": "Polyfills for TextEncoder/TextDecoder",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
"README.md"
|
|
35
35
|
],
|
|
36
36
|
"browser": {
|
|
37
|
-
"
|
|
38
|
-
"path": false,
|
|
37
|
+
"./dist/index.js": "./dist/index.browser.js",
|
|
39
38
|
"./src/index.ts": "./src/index.browser.ts",
|
|
40
|
-
"
|
|
39
|
+
"fs": false,
|
|
40
|
+
"path": false
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
43
|
"pre-build": "npm run build-bundle && npm run build-bundle-dev",
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"build-bundle-dev": "# ocular-bundle ./bundle.ts --env=dev --output=dist/dist.dev.js"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@loaders.gl/crypto": "4.2.0-
|
|
49
|
-
"@loaders.gl/loader-utils": "4.2.0-
|
|
48
|
+
"@loaders.gl/crypto": "4.2.0-beta.1",
|
|
49
|
+
"@loaders.gl/loader-utils": "4.2.0-beta.1",
|
|
50
50
|
"buffer": "^6.0.3",
|
|
51
51
|
"get-pixels": "^3.3.3",
|
|
52
52
|
"ndarray": "^1.0.19",
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"@loaders.gl/core": "^4.0.0"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "c386a9196516fe3ff24847b40e6c77be039cf905"
|
|
62
62
|
}
|
|
@@ -55,8 +55,10 @@ export class Response {
|
|
|
55
55
|
if (isReadableNodeStream(body)) {
|
|
56
56
|
this._body = decompressReadStream(body, headers);
|
|
57
57
|
} else if (typeof body === 'string') {
|
|
58
|
+
// @ts-expect-error
|
|
58
59
|
this._body = stream.Readable.from([new TextEncoder().encode(body)]);
|
|
59
60
|
} else {
|
|
61
|
+
// @ts-expect-error
|
|
60
62
|
this._body = stream.Readable.from([body || new ArrayBuffer(0)]);
|
|
61
63
|
}
|
|
62
64
|
}
|
|
@@ -55,8 +55,10 @@ export async function fetchNode(url: string, options?: RequestInit): Promise<Res
|
|
|
55
55
|
if (isReadableNodeStream(body)) {
|
|
56
56
|
bodyStream = decompressReadStream(body, responseHeaders);
|
|
57
57
|
} else if (typeof body === 'string') {
|
|
58
|
+
// @ts-expect-error
|
|
58
59
|
bodyStream = Readable.from([new TextEncoder().encode(body)]);
|
|
59
60
|
} else {
|
|
61
|
+
// @ts-expect-error
|
|
60
62
|
bodyStream = Readable.from([body || new ArrayBuffer(0)]);
|
|
61
63
|
}
|
|
62
64
|
|
|
@@ -11,8 +11,10 @@ export class NodeFile implements ReadableFile, WritableFile {
|
|
|
11
11
|
constructor(path: string, flags: 'r' | 'w' | 'wx' | 'a+', mode?: number) {
|
|
12
12
|
path = resolvePath(path);
|
|
13
13
|
this.handle = fs.openSync(path, flags, mode);
|
|
14
|
+
// @ts-expect-error Nodew 20?
|
|
14
15
|
const stats = fs.fstatSync(this.handle, {bigint: true});
|
|
15
16
|
this.size = Number(stats.size);
|
|
17
|
+
// @ts-expect-error
|
|
16
18
|
this.bigsize = stats.size;
|
|
17
19
|
this.url = path;
|
|
18
20
|
}
|
|
@@ -53,6 +55,7 @@ export class NodeFile implements ReadableFile, WritableFile {
|
|
|
53
55
|
|
|
54
56
|
async stat(): Promise<Stat> {
|
|
55
57
|
return await new Promise((resolve, reject) =>
|
|
58
|
+
// @ts-expect-error bigint typings
|
|
56
59
|
fs.fstat(this.handle, {bigint: true}, (err, info) => {
|
|
57
60
|
const stats: Stat = {
|
|
58
61
|
size: Number(info.size),
|
|
@@ -121,6 +124,7 @@ async function readBytes(
|
|
|
121
124
|
position: number | bigint | null
|
|
122
125
|
): Promise<number> {
|
|
123
126
|
return await new Promise<number>((resolve, reject) =>
|
|
127
|
+
// @ts-expect-error bigint?
|
|
124
128
|
fs.read(fd, uint8Array, offset, length, position, (err, bytesRead) =>
|
|
125
129
|
err ? reject(err) : resolve(bytesRead)
|
|
126
130
|
)
|
package/src/index.ts
CHANGED
|
@@ -50,7 +50,7 @@ export async function requireFromFile(filename: string): Promise<any> {
|
|
|
50
50
|
if (!filename.startsWith('/')) {
|
|
51
51
|
filename = `${process.cwd()}/${filename}`;
|
|
52
52
|
}
|
|
53
|
-
const code =
|
|
53
|
+
const code = fs.readFileSync(filename, 'utf8');
|
|
54
54
|
return requireFromString(code);
|
|
55
55
|
}
|
|
56
56
|
|
|
@@ -14,11 +14,12 @@ export function makeNodeStream<ArrayBuffer>(
|
|
|
14
14
|
options?: ReadableOptions
|
|
15
15
|
): ReadableType {
|
|
16
16
|
// @ts-ignore AsyncGenerator
|
|
17
|
+
// prettier-ignore
|
|
17
18
|
const iterator = source[Symbol.asyncIterator]
|
|
18
19
|
? // @ts-ignore AsyncGenerator
|
|
19
|
-
|
|
20
|
+
source[Symbol.asyncIterator]()
|
|
20
21
|
: // @ts-ignore AsyncGenerator
|
|
21
|
-
|
|
22
|
+
source[Symbol.iterator]();
|
|
22
23
|
return new AsyncIterableReadable(iterator, options);
|
|
23
24
|
}
|
|
24
25
|
|