@loaders.gl/polyfills 4.0.0-alpha.9 → 4.0.0-beta.2
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 +10 -1818
- package/dist/es5/filesystems/node-filesystem.js +214 -0
- package/dist/es5/filesystems/node-filesystem.js.map +1 -0
- package/dist/es5/index.browser.js +15 -0
- package/dist/es5/index.browser.js.map +1 -0
- package/dist/es5/index.js +32 -49
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/node/fetch/fetch.node.js +2 -3
- package/dist/es5/node/fetch/fetch.node.js.map +1 -1
- package/dist/es5/node/file/install-file-polyfills.js +1 -4
- package/dist/es5/node/file/install-file-polyfills.js.map +1 -1
- package/dist/esm/filesystems/node-filesystem.js +56 -0
- package/dist/esm/filesystems/node-filesystem.js.map +1 -0
- package/dist/esm/index.browser.js +7 -0
- package/dist/esm/index.browser.js.map +1 -0
- package/dist/esm/index.js +32 -31
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/node/fetch/fetch.node.js +2 -3
- package/dist/esm/node/fetch/fetch.node.js.map +1 -1
- package/dist/esm/node/file/install-file-polyfills.js +1 -4
- package/dist/esm/node/file/install-file-polyfills.js.map +1 -1
- package/dist/filesystems/node-filesystem.d.ts +39 -0
- package/dist/filesystems/node-filesystem.d.ts.map +1 -0
- package/dist/index.browser.d.ts +3 -0
- package/dist/index.browser.d.ts.map +1 -0
- package/dist/index.d.ts +1 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/node/fetch/fetch.node.d.ts +1 -1
- package/dist/node/fetch/fetch.node.d.ts.map +1 -1
- package/package.json +6 -66
- package/src/filesystems/node-filesystem.ts +87 -0
- package/src/index.browser.ts +14 -0
- package/src/index.ts +54 -38
- package/src/node/fetch/fetch.node.ts +6 -5
- package/src/node/file/install-file-polyfills.ts +2 -2
- package/dist/bundle.js +0 -5
- package/dist/es5/node/fetch/fetch-file.node.js +0 -83
- package/dist/es5/node/fetch/fetch-file.node.js.map +0 -1
- package/dist/esm/node/fetch/fetch-file.node.js +0 -50
- package/dist/esm/node/fetch/fetch-file.node.js.map +0 -1
- package/dist/index.js +0 -97
- package/dist/lib/encoding-indexes.js +0 -35
- package/dist/lib/encoding.js +0 -2779
- package/dist/libs/encoding-indexes-asian.js +0 -14
- package/dist/node/buffer/btoa.node.js +0 -14
- package/dist/node/buffer/to-array-buffer.node.js +0 -12
- package/dist/node/fetch/fetch-file.node.d.ts +0 -4
- package/dist/node/fetch/fetch-file.node.d.ts.map +0 -1
- package/dist/node/fetch/fetch-file.node.js +0 -51
- package/dist/node/fetch/fetch.node.js +0 -143
- package/dist/node/fetch/headers.node.js +0 -106
- package/dist/node/fetch/response.node.js +0 -76
- package/dist/node/fetch/utils/decode-data-uri.node.js +0 -65
- package/dist/node/fetch/utils/stream-utils.node.js +0 -73
- package/dist/node/file/blob-stream-controller.js +0 -63
- package/dist/node/file/blob-stream.js +0 -37
- package/dist/node/file/blob.js +0 -160
- package/dist/node/file/file-reader.js +0 -35
- package/dist/node/file/file.js +0 -37
- package/dist/node/file/install-file-polyfills.js +0 -27
- package/dist/node/file/readable-stream.js +0 -11
- package/dist/node/images/encode-image.node.js +0 -41
- package/dist/node/images/parse-image.node.js +0 -41
- package/dist/promise/all-settled.js +0 -24
- package/dist/utils/assert.js +0 -9
- package/dist/utils/globals.js +0 -36
- package/src/node/fetch/fetch-file.node.ts +0 -51
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.browser.js","names":["allSettled","Promise","installFilePolyfills","NodeFileSystem"],"sources":["../../src/index.browser.ts"],"sourcesContent":["// loaders.gl, MIT License\n\nimport {allSettled} from './promise/all-settled';\n\nif (!('allSettled' in Promise)) {\n // @ts-ignore\n Promise.allSettled = allSettled;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-empty-function\nexport function installFilePolyfills() {}\n\n// Dummy export to avoid import errors in browser tests\nexport const NodeFileSystem = null;\n"],"mappings":"AAEA,SAAQA,UAAU,QAAO,uBAAuB;AAEhD,IAAI,EAAE,YAAY,IAAIC,OAAO,CAAC,EAAE;EAE9BA,OAAO,CAACD,UAAU,GAAGA,UAAU;AACjC;AAGA,OAAO,SAASE,oBAAoBA,CAAA,EAAG,CAAC;AAGxC,OAAO,MAAMC,cAAc,GAAG,IAAI"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,50 +1,51 @@
|
|
|
1
|
-
import { isBrowser
|
|
1
|
+
import { isBrowser } from './utils/globals';
|
|
2
2
|
import { TextDecoder, TextEncoder } from './lib/encoding';
|
|
3
3
|
import { allSettled } from './promise/all-settled';
|
|
4
4
|
import * as base64 from './node/buffer/btoa.node';
|
|
5
|
-
import { Headers as HeadersNode } from './node/fetch/headers.node';
|
|
6
|
-
import { Response as ResponseNode } from './node/fetch/response.node';
|
|
7
|
-
import { fetchNode } from './node/fetch/fetch.node';
|
|
8
5
|
import { encodeImageNode } from './node/images/encode-image.node';
|
|
9
6
|
import { parseImageNode, NODE_FORMAT_SUPPORT } from './node/images/parse-image.node';
|
|
10
|
-
export { ReadableStreamPolyfill } from './node/file/readable-stream';
|
|
11
|
-
export { BlobPolyfill } from './node/file/blob';
|
|
12
7
|
export { FileReaderPolyfill } from './node/file/file-reader';
|
|
13
8
|
export { FilePolyfill } from './node/file/file';
|
|
14
9
|
export { installFilePolyfills } from './node/file/install-file-polyfills';
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const installTextEncoder = !isBrowser || !('TextEncoder' in global);
|
|
18
|
-
if (installTextEncoder) {
|
|
19
|
-
global['TextEncoder'] = TextEncoder;
|
|
10
|
+
if (isBrowser) {
|
|
11
|
+
console.error('loaders.gl: The @loaders.gl/polyfills should only be used in Node.js environments');
|
|
20
12
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
global['TextDecoder'] = TextDecoder;
|
|
13
|
+
if (!globalThis.TextEncoder) {
|
|
14
|
+
globalThis.TextEncoder = TextEncoder;
|
|
24
15
|
}
|
|
25
|
-
if (!
|
|
26
|
-
|
|
16
|
+
if (!globalThis.TextDecoder) {
|
|
17
|
+
globalThis.TextDecoder = TextDecoder;
|
|
27
18
|
}
|
|
28
|
-
if (!isBrowser && !('
|
|
29
|
-
|
|
19
|
+
if (!isBrowser && !('atob' in globalThis) && base64.atob) {
|
|
20
|
+
globalThis['atob'] = base64.atob;
|
|
30
21
|
}
|
|
31
|
-
if (!isBrowser && !('
|
|
32
|
-
|
|
22
|
+
if (!isBrowser && !('btoa' in globalThis) && base64.btoa) {
|
|
23
|
+
globalThis['btoa'] = base64.btoa;
|
|
33
24
|
}
|
|
34
|
-
|
|
35
|
-
|
|
25
|
+
globalThis.loaders = globalThis.loaders || {};
|
|
26
|
+
export { NodeFileSystem } from './filesystems/node-filesystem';
|
|
27
|
+
import { NodeFileSystem } from './filesystems/node-filesystem';
|
|
28
|
+
globalThis.loaders.NodeFileSystem = NodeFileSystem;
|
|
29
|
+
if (!isBrowser && !('_encodeImageNode' in globalThis) && encodeImageNode) {
|
|
30
|
+
globalThis['_encodeImageNode'] = encodeImageNode;
|
|
36
31
|
}
|
|
37
|
-
if (!isBrowser && !('
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (!isBrowser && !('_encodeImageNode' in global) && encodeImageNode) {
|
|
41
|
-
global['_encodeImageNode'] = encodeImageNode;
|
|
42
|
-
}
|
|
43
|
-
if (!isBrowser && !('_parseImageNode' in global) && parseImageNode) {
|
|
44
|
-
global['_parseImageNode'] = parseImageNode;
|
|
45
|
-
global['_imageFormatsNode'] = NODE_FORMAT_SUPPORT;
|
|
32
|
+
if (!isBrowser && !('_parseImageNode' in globalThis) && parseImageNode) {
|
|
33
|
+
globalThis['_parseImageNode'] = parseImageNode;
|
|
34
|
+
globalThis['_imageFormatsNode'] = NODE_FORMAT_SUPPORT;
|
|
46
35
|
}
|
|
47
36
|
if (!('allSettled' in Promise)) {
|
|
48
37
|
Promise.allSettled = allSettled;
|
|
49
38
|
}
|
|
39
|
+
import { Headers as HeadersNode } from './node/fetch/headers.node';
|
|
40
|
+
import { Response as ResponseNode } from './node/fetch/response.node';
|
|
41
|
+
import { fetchNode } from './node/fetch/fetch.node';
|
|
42
|
+
if (!isBrowser && !('Headers' in globalThis) && HeadersNode) {
|
|
43
|
+
globalThis.Headers = HeadersNode;
|
|
44
|
+
}
|
|
45
|
+
if (!isBrowser && !('Response' in globalThis) && ResponseNode) {
|
|
46
|
+
globalThis.Response = ResponseNode;
|
|
47
|
+
}
|
|
48
|
+
if (!isBrowser && !('fetch' in globalThis) && fetchNode) {
|
|
49
|
+
globalThis.fetch = fetchNode;
|
|
50
|
+
}
|
|
50
51
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["isBrowser","
|
|
1
|
+
{"version":3,"file":"index.js","names":["isBrowser","TextDecoder","TextEncoder","allSettled","base64","encodeImageNode","parseImageNode","NODE_FORMAT_SUPPORT","FileReaderPolyfill","FilePolyfill","installFilePolyfills","console","error","globalThis","atob","btoa","loaders","NodeFileSystem","Promise","Headers","HeadersNode","Response","ResponseNode","fetchNode","fetch"],"sources":["../../src/index.ts"],"sourcesContent":["/* eslint-disable dot-notation */\nimport {isBrowser} from './utils/globals';\n\nimport {TextDecoder, TextEncoder} from './lib/encoding';\nimport {allSettled} from './promise/all-settled';\n\n// Node specific\nimport * as base64 from './node/buffer/btoa.node';\n\nimport {encodeImageNode} from './node/images/encode-image.node';\nimport {parseImageNode, NODE_FORMAT_SUPPORT} from './node/images/parse-image.node';\n\n// export {ReadableStreamPolyfill} from './node/file/readable-stream';\n// export {BlobPolyfill} from './node/file/blob';\nexport {FileReaderPolyfill} from './node/file/file-reader';\nexport {FilePolyfill} from './node/file/file';\nexport {installFilePolyfills} from './node/file/install-file-polyfills';\n\nif (isBrowser) {\n // eslint-disable-next-line no-console\n console.error(\n 'loaders.gl: The @loaders.gl/polyfills should only be used in Node.js environments'\n );\n}\n\n// POLYFILLS: TextEncoder, TextDecoder\n// - Recent Node versions have these classes but virtually no encodings unless special build.\n// - Browser: Edge, IE11 do not have these\n\nif (!globalThis.TextEncoder) {\n // @ts-expect-error\n globalThis.TextEncoder = TextEncoder;\n}\n\nif (!globalThis.TextDecoder) {\n // @ts-expect-error\n globalThis.TextDecoder = TextDecoder;\n}\n\n// POLYFILLS: btoa, atob\n// - Node: Yes\n// - Browser: No\n\nif (!isBrowser && !('atob' in globalThis) && base64.atob) {\n globalThis['atob'] = base64.atob;\n}\nif (!isBrowser && !('btoa' in globalThis) && base64.btoa) {\n globalThis['btoa'] = base64.btoa;\n}\n\nglobalThis.loaders = globalThis.loaders || {};\n\n// FILESYSTEM POLYFILLS:\nexport {NodeFileSystem} from './filesystems/node-filesystem';\nimport {NodeFileSystem} from './filesystems/node-filesystem';\nglobalThis.loaders.NodeFileSystem = NodeFileSystem;\n\n// NODE IMAGE FUNCTIONS:\n// These are not official polyfills but used by the @loaders.gl/images module if installed\n// TODO - is there an appropriate Image API we could polyfill using an adapter?\n\nif (!isBrowser && !('_encodeImageNode' in globalThis) && encodeImageNode) {\n globalThis['_encodeImageNode'] = encodeImageNode;\n}\n\nif (!isBrowser && !('_parseImageNode' in globalThis) && parseImageNode) {\n globalThis['_parseImageNode'] = parseImageNode;\n globalThis['_imageFormatsNode'] = NODE_FORMAT_SUPPORT;\n}\n\nif (!('allSettled' in Promise)) {\n // @ts-ignore\n Promise.allSettled = allSettled;\n}\n\n// DEPRECATED POLYFILL:\n// - Node v18+: No, not needed\n// - Node v16 and lower: Yes\n// - Browsers (evergreen): Not needed.\n// - IE11: No. This polyfill is node only, install external polyfill\nimport {Headers as HeadersNode} from './node/fetch/headers.node';\nimport {Response as ResponseNode} from './node/fetch/response.node';\nimport {fetchNode as fetchNode} from './node/fetch/fetch.node';\n\nif (!isBrowser && !('Headers' in globalThis) && HeadersNode) {\n // @ts-expect-error\n globalThis.Headers = HeadersNode;\n}\n\nif (!isBrowser && !('Response' in globalThis) && ResponseNode) {\n // @ts-expect-error\n globalThis.Response = ResponseNode;\n}\n\nif (!isBrowser && !('fetch' in globalThis) && fetchNode) {\n // @ts-expect-error\n globalThis.fetch = fetchNode;\n}\n"],"mappings":"AACA,SAAQA,SAAS,QAAO,iBAAiB;AAEzC,SAAQC,WAAW,EAAEC,WAAW,QAAO,gBAAgB;AACvD,SAAQC,UAAU,QAAO,uBAAuB;AAGhD,OAAO,KAAKC,MAAM,MAAM,yBAAyB;AAEjD,SAAQC,eAAe,QAAO,iCAAiC;AAC/D,SAAQC,cAAc,EAAEC,mBAAmB,QAAO,gCAAgC;AAIlF,SAAQC,kBAAkB,QAAO,yBAAyB;AAC1D,SAAQC,YAAY,QAAO,kBAAkB;AAC7C,SAAQC,oBAAoB,QAAO,oCAAoC;AAEvE,IAAIV,SAAS,EAAE;EAEbW,OAAO,CAACC,KAAK,CACX,mFACF,CAAC;AACH;AAMA,IAAI,CAACC,UAAU,CAACX,WAAW,EAAE;EAE3BW,UAAU,CAACX,WAAW,GAAGA,WAAW;AACtC;AAEA,IAAI,CAACW,UAAU,CAACZ,WAAW,EAAE;EAE3BY,UAAU,CAACZ,WAAW,GAAGA,WAAW;AACtC;AAMA,IAAI,CAACD,SAAS,IAAI,EAAE,MAAM,IAAIa,UAAU,CAAC,IAAIT,MAAM,CAACU,IAAI,EAAE;EACxDD,UAAU,CAAC,MAAM,CAAC,GAAGT,MAAM,CAACU,IAAI;AAClC;AACA,IAAI,CAACd,SAAS,IAAI,EAAE,MAAM,IAAIa,UAAU,CAAC,IAAIT,MAAM,CAACW,IAAI,EAAE;EACxDF,UAAU,CAAC,MAAM,CAAC,GAAGT,MAAM,CAACW,IAAI;AAClC;AAEAF,UAAU,CAACG,OAAO,GAAGH,UAAU,CAACG,OAAO,IAAI,CAAC,CAAC;AAG7C,SAAQC,cAAc,QAAO,+BAA+B;AAC5D,SAAQA,cAAc,QAAO,+BAA+B;AAC5DJ,UAAU,CAACG,OAAO,CAACC,cAAc,GAAGA,cAAc;AAMlD,IAAI,CAACjB,SAAS,IAAI,EAAE,kBAAkB,IAAIa,UAAU,CAAC,IAAIR,eAAe,EAAE;EACxEQ,UAAU,CAAC,kBAAkB,CAAC,GAAGR,eAAe;AAClD;AAEA,IAAI,CAACL,SAAS,IAAI,EAAE,iBAAiB,IAAIa,UAAU,CAAC,IAAIP,cAAc,EAAE;EACtEO,UAAU,CAAC,iBAAiB,CAAC,GAAGP,cAAc;EAC9CO,UAAU,CAAC,mBAAmB,CAAC,GAAGN,mBAAmB;AACvD;AAEA,IAAI,EAAE,YAAY,IAAIW,OAAO,CAAC,EAAE;EAE9BA,OAAO,CAACf,UAAU,GAAGA,UAAU;AACjC;AAOA,SAAQgB,OAAO,IAAIC,WAAW,QAAO,2BAA2B;AAChE,SAAQC,QAAQ,IAAIC,YAAY,QAAO,4BAA4B;AACnE,SAAQC,SAAsB,QAAO,yBAAyB;AAE9D,IAAI,CAACvB,SAAS,IAAI,EAAE,SAAS,IAAIa,UAAU,CAAC,IAAIO,WAAW,EAAE;EAE3DP,UAAU,CAACM,OAAO,GAAGC,WAAW;AAClC;AAEA,IAAI,CAACpB,SAAS,IAAI,EAAE,UAAU,IAAIa,UAAU,CAAC,IAAIS,YAAY,EAAE;EAE7DT,UAAU,CAACQ,QAAQ,GAAGC,YAAY;AACpC;AAEA,IAAI,CAACtB,SAAS,IAAI,EAAE,OAAO,IAAIa,UAAU,CAAC,IAAIU,SAAS,EAAE;EAEvDV,UAAU,CAACW,KAAK,GAAGD,SAAS;AAC9B"}
|
|
@@ -3,13 +3,12 @@ import https from 'https';
|
|
|
3
3
|
import { Response } from './response.node';
|
|
4
4
|
import { Headers } from './headers.node';
|
|
5
5
|
import { decodeDataUri } from './utils/decode-data-uri.node';
|
|
6
|
-
import { fetchFileNode } from './fetch-file.node';
|
|
7
6
|
const isDataURL = url => url.startsWith('data:');
|
|
8
7
|
const isRequestURL = url => url.startsWith('http:') || url.startsWith('https:');
|
|
9
8
|
export async function fetchNode(url, options) {
|
|
10
9
|
try {
|
|
11
|
-
if (
|
|
12
|
-
return await
|
|
10
|
+
if (globalThis.fetch !== fetchNode && (isRequestURL(url) || isDataURL(url))) {
|
|
11
|
+
return await fetch(url, options);
|
|
13
12
|
}
|
|
14
13
|
if (isDataURL(url)) {
|
|
15
14
|
const {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.node.js","names":["http","https","Response","Headers","decodeDataUri","fetchFileNode","isDataURL","url","startsWith","isRequestURL","fetchNode","options","arrayBuffer","mimeType","response","headers","syntheticResponseHeaders","originalUrl","endsWith","slice","body","createHTTPRequestReadStream","getHeaders","status","statusText","getStatus","followRedirect","undefined","has","redirectUrl","generateRedirectUrl","get","error","String","Promise","resolve","reject","requestOptions","getRequestOptions","req","request","res","on","end","location","URL","pathname","href","originalHeaders","key","Object","keys","toLowerCase","urlObject","hostname","path","method","fetch","port","httpResponse","statusCode","statusMessage","additionalHeaders","arguments","length","httpHeaders","header","contentLength","getContentLength","Number","isFinite","assign"],"sources":["../../../../src/node/fetch/fetch.node.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport http from 'http';\nimport https from 'https';\nimport {Response} from './response.node';\nimport {Headers} from './headers.node';\nimport {decodeDataUri} from './utils/decode-data-uri.node';\n\nimport {fetchFileNode} from './fetch-file.node';\n\nconst isDataURL = (url: string): boolean => url.startsWith('data:');\nconst isRequestURL = (url: string): boolean => url.startsWith('http:') || url.startsWith('https:');\n\n/**\n * Emulation of Browser fetch for Node.js\n * @param url\n * @param options\n */\n// eslint-disable-next-line complexity\nexport async function fetchNode(url: string, options): Promise<Response> {\n try {\n // Handle file streams in node\n if (!isRequestURL(url) && !isDataURL(url)) {\n return await fetchFileNode(url, options);\n }\n\n // Handle data urls in node, to match `fetch``\n // Note - this loses the MIME type, data URIs are handled directly in fetch\n if (isDataURL(url)) {\n const {arrayBuffer, mimeType} = decodeDataUri(url);\n const response = new Response(arrayBuffer, {\n headers: {'content-type': mimeType},\n url\n });\n return response;\n }\n\n // Automatically decompress gzipped files with .gz extension\n const syntheticResponseHeaders = {};\n const originalUrl = url;\n if (url.endsWith('.gz')) {\n url = url.slice(0, -3);\n syntheticResponseHeaders['content-encoding'] = 'gzip';\n }\n\n // Need to create the stream in advance since Response constructor needs to be sync\n const body = await createHTTPRequestReadStream(originalUrl, options);\n const headers = getHeaders(url, body, syntheticResponseHeaders);\n const {status, statusText} = getStatus(body);\n\n const followRedirect =\n !options || options.followRedirect || options.followRedirect === undefined;\n\n if (status >= 300 && status < 400 && headers.has('location') && followRedirect) {\n const redirectUrl = generateRedirectUrl(url, headers.get('location'));\n\n // Redirect\n return await fetchNode(redirectUrl, options);\n }\n return new Response(body, {headers, status, statusText, url});\n } catch (error) {\n // TODO - what error code to use here?\n return new Response(null, {status: 400, statusText: String(error), url});\n }\n}\n\n/** Returns a promise that resolves to a readable stream */\nexport async function createHTTPRequestReadStream(\n url: string,\n options\n): Promise<http.IncomingMessage> {\n // HANDLE HTTP/HTTPS REQUESTS IN NODE\n // TODO: THIS IS BAD SINCE WE RETURN A PROMISE INSTEAD OF A STREAM\n return await new Promise((resolve, reject) => {\n const requestOptions = getRequestOptions(url, options);\n const req = url.startsWith('https:')\n ? https.request(requestOptions, (res) => resolve(res))\n : http.request(requestOptions, (res) => resolve(res));\n req.on('error', (error) => reject(error));\n req.end();\n });\n}\n\n/**\n * Generate redirect url from location without origin and protocol.\n * @param originalUrl\n * @param redirectUrl\n */\nfunction generateRedirectUrl(originalUrl: string, location: string): string {\n if (location.startsWith('http')) {\n return location;\n }\n // If url doesn't have origin and protocol just extend current url origin with location.\n const url = new URL(originalUrl);\n url.pathname = location;\n\n return url.href;\n}\n\n// HELPER FUNCTIONS\n\nfunction getRequestOptions(url: string, options?: {fetch?: typeof fetch; headers?}) {\n // Ensure header keys are lower case so that we can merge without duplicates\n const originalHeaders = options?.headers || {};\n const headers = {};\n for (const key of Object.keys(originalHeaders)) {\n headers[key.toLowerCase()] = originalHeaders[key];\n }\n\n // Add default accept-encoding to headers\n headers['accept-encoding'] = headers['accept-encoding'] || 'gzip,br,deflate';\n\n const urlObject = new URL(url);\n return {\n hostname: urlObject.hostname,\n path: urlObject.pathname,\n method: 'GET',\n // Add options and user provided 'options.fetch' overrides if available\n ...options,\n ...options?.fetch,\n // Override with updated headers with accepted encodings:\n headers,\n port: urlObject.port\n };\n}\n\nfunction getStatus(httpResponse: http.IncomingMessage): {status: number; statusText: string} {\n if (httpResponse.statusCode) {\n return {status: httpResponse.statusCode, statusText: httpResponse.statusMessage || 'NA'};\n }\n return {status: 200, statusText: 'OK'};\n}\n\nfunction getHeaders(url, httpResponse, additionalHeaders = {}) {\n const headers = {};\n\n if (httpResponse && httpResponse.headers) {\n const httpHeaders = httpResponse.headers;\n for (const key in httpHeaders) {\n const header = httpHeaders[key];\n headers[key.toLowerCase()] = String(header);\n }\n }\n\n // Fix up content length if we can for best progress experience\n if (!headers['content-length']) {\n const contentLength = getContentLength(url);\n if (Number.isFinite(contentLength)) {\n headers['content-length'] = contentLength;\n }\n }\n\n Object.assign(headers, additionalHeaders);\n\n return new Headers(headers);\n}\n\n/** Needs to be read from actual headers */\nfunction getContentLength(url: string): number | null {\n // TODO - remove media type etc\n return isDataURL(url) ? url.length - 'data:'.length : null;\n}\n"],"mappings":"AAEA,OAAOA,IAAI,MAAM,MAAM;AACvB,OAAOC,KAAK,MAAM,OAAO;AACzB,SAAQC,QAAQ,QAAO,iBAAiB;AACxC,SAAQC,OAAO,QAAO,gBAAgB;AACtC,SAAQC,aAAa,QAAO,8BAA8B;AAE1D,SAAQC,aAAa,QAAO,mBAAmB;AAE/C,MAAMC,SAAS,GAAIC,GAAW,IAAcA,GAAG,CAACC,UAAU,CAAC,OAAO,CAAC;AACnE,MAAMC,YAAY,GAAIF,GAAW,IAAcA,GAAG,CAACC,UAAU,CAAC,OAAO,CAAC,IAAID,GAAG,CAACC,UAAU,CAAC,QAAQ,CAAC;AAQlG,OAAO,eAAeE,SAASA,C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AAA,QAAApC,SAAA,GAAAoC,SAAA,MAAG,CAAC,CAAC;EAC3D,MAAMhD,OAAO,GAAG,CAAC,CAAC;EAElB,IAAI4C,YAAY,IAAIA,YAAY,CAAC5C,OAAO,EAAE;IACxC,MAAMkD,WAAW,GAAGN,YAAY,CAAC5C,OAAO;IACxC,KAAK,MAAMkC,GAAG,IAAIgB,WAAW,EAAE;MAC7B,MAAMC,MAAM,GAAGD,WAAW,CAAChB,GAAG,CAAC;MAC/BlC,OAAO,CAACkC,GAAG,CAACG,WAAW,CAAC,CAAC,CAAC,GAAGnB,MAAM,CAACiC,MAAM,CAAC;IAC7C;EACF;EAGA,IAAI,CAACnD,OAAO,CAAC,gBAAgB,CAAC,EAAE;IAC9B,MAAMoD,aAAa,GAAGC,gBAAgB,CAAC7D,GAAG,CAAC;IAC3C,IAAI8D,MAAM,CAACC,QAAQ,CAACH,aAAa,CAAC,EAAE;MAClCpD,OAAO,CAAC,gBAAgB,CAAC,GAAGoD,aAAa;IAC3C;EACF;EAEAjB,MAAM,CAACqB,MAAM,CAACxD,OAAO,EAAE+C,iBAAiB,CAAC;EAEzC,OAAO,IAAI3D,OAAO,CAACY,OAAO,CAAC;AAC7B;AAGA,SAASqD,gBAAgBA,CAAC7D,GAAW,EAAiB;EAEpD,OAAOD,SAAS,CAACC,GAAG,CAAC,GAAGA,GAAG,CAACyD,MAAM,GAAG,OAAO,CAACA,MAAM,GAAG,IAAI;AAC5D"}
|
|
1
|
+
{"version":3,"file":"fetch.node.js","names":["http","https","Response","Headers","decodeDataUri","isDataURL","url","startsWith","isRequestURL","fetchNode","options","globalThis","fetch","arrayBuffer","mimeType","response","headers","syntheticResponseHeaders","originalUrl","endsWith","slice","body","createHTTPRequestReadStream","getHeaders","status","statusText","getStatus","followRedirect","undefined","has","redirectUrl","generateRedirectUrl","get","error","String","Promise","resolve","reject","requestOptions","getRequestOptions","req","request","res","on","end","location","URL","pathname","href","originalHeaders","key","Object","keys","toLowerCase","urlObject","hostname","path","method","port","httpResponse","statusCode","statusMessage","additionalHeaders","arguments","length","httpHeaders","header","contentLength","getContentLength","Number","isFinite","assign"],"sources":["../../../../src/node/fetch/fetch.node.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport http from 'http';\nimport https from 'https';\nimport {Response} from './response.node';\nimport {Headers} from './headers.node';\nimport {decodeDataUri} from './utils/decode-data-uri.node';\n\nconst isDataURL = (url: string): boolean => url.startsWith('data:');\nconst isRequestURL = (url: string): boolean => url.startsWith('http:') || url.startsWith('https:');\n\n/**\n * Emulation of Browser fetch for Node.js\n * @param url\n * @param options\n */\n// eslint-disable-next-line complexity\nexport async function fetchNode(url: string, options: RequestInit): Promise<Response> {\n try {\n // Handle file streams in node\n // @ts-expect-error\n if (globalThis.fetch !== fetchNode && (isRequestURL(url) || isDataURL(url))) {\n // @ts-expect-error\n return await fetch(url, options);\n }\n\n // Handle data urls in node, to match `fetch``\n // Note - this loses the MIME type, data URIs are handled directly in fetch\n if (isDataURL(url)) {\n const {arrayBuffer, mimeType} = decodeDataUri(url);\n const response = new Response(arrayBuffer, {\n headers: {'content-type': mimeType},\n url\n });\n return response;\n }\n\n // Automatically decompress gzipped files with .gz extension\n const syntheticResponseHeaders = {};\n const originalUrl = url;\n if (url.endsWith('.gz')) {\n url = url.slice(0, -3);\n syntheticResponseHeaders['content-encoding'] = 'gzip';\n }\n\n // Need to create the stream in advance since Response constructor needs to be sync\n const body = await createHTTPRequestReadStream(originalUrl, options);\n const headers = getHeaders(url, body, syntheticResponseHeaders);\n const {status, statusText} = getStatus(body);\n\n const followRedirect =\n // @ts-expect-error\n !options || options.followRedirect || options.followRedirect === undefined;\n\n if (status >= 300 && status < 400 && headers.has('location') && followRedirect) {\n const redirectUrl = generateRedirectUrl(url, headers.get('location'));\n\n // Redirect\n return await fetchNode(redirectUrl, options);\n }\n return new Response(body, {headers, status, statusText, url});\n } catch (error) {\n // TODO - what error code to use here?\n return new Response(null, {status: 400, statusText: String(error), url});\n }\n}\n\n/** Returns a promise that resolves to a readable stream */\nexport async function createHTTPRequestReadStream(\n url: string,\n options\n): Promise<http.IncomingMessage> {\n // HANDLE HTTP/HTTPS REQUESTS IN NODE\n // TODO: THIS IS BAD SINCE WE RETURN A PROMISE INSTEAD OF A STREAM\n return await new Promise((resolve, reject) => {\n const requestOptions = getRequestOptions(url, options);\n const req = url.startsWith('https:')\n ? https.request(requestOptions, (res) => resolve(res))\n : http.request(requestOptions, (res) => resolve(res));\n req.on('error', (error) => reject(error));\n req.end();\n });\n}\n\n/**\n * Generate redirect url from location without origin and protocol.\n * @param originalUrl\n * @param redirectUrl\n */\nfunction generateRedirectUrl(originalUrl: string, location: string): string {\n if (location.startsWith('http')) {\n return location;\n }\n // If url doesn't have origin and protocol just extend current url origin with location.\n const url = new URL(originalUrl);\n url.pathname = location;\n\n return url.href;\n}\n\n// HELPER FUNCTIONS\n\nfunction getRequestOptions(url: string, options?: {fetch?: typeof fetch; headers?}) {\n // Ensure header keys are lower case so that we can merge without duplicates\n const originalHeaders = options?.headers || {};\n const headers = {};\n for (const key of Object.keys(originalHeaders)) {\n headers[key.toLowerCase()] = originalHeaders[key];\n }\n\n // Add default accept-encoding to headers\n headers['accept-encoding'] = headers['accept-encoding'] || 'gzip,br,deflate';\n\n const urlObject = new URL(url);\n return {\n hostname: urlObject.hostname,\n path: urlObject.pathname,\n method: 'GET',\n // Add options and user provided 'options.fetch' overrides if available\n ...options,\n ...options?.fetch,\n // Override with updated headers with accepted encodings:\n headers,\n port: urlObject.port\n };\n}\n\nfunction getStatus(httpResponse: http.IncomingMessage): {status: number; statusText: string} {\n if (httpResponse.statusCode) {\n return {status: httpResponse.statusCode, statusText: httpResponse.statusMessage || 'NA'};\n }\n return {status: 200, statusText: 'OK'};\n}\n\nfunction getHeaders(url, httpResponse, additionalHeaders = {}) {\n const headers = {};\n\n if (httpResponse && httpResponse.headers) {\n const httpHeaders = httpResponse.headers;\n for (const key in httpHeaders) {\n const header = httpHeaders[key];\n headers[key.toLowerCase()] = String(header);\n }\n }\n\n // Fix up content length if we can for best progress experience\n if (!headers['content-length']) {\n const contentLength = getContentLength(url);\n if (Number.isFinite(contentLength)) {\n headers['content-length'] = contentLength;\n }\n }\n\n Object.assign(headers, additionalHeaders);\n\n return new Headers(headers);\n}\n\n/** Needs to be read from actual headers */\nfunction getContentLength(url: string): number | null {\n // TODO - remove media type etc\n return isDataURL(url) ? url.length - 'data:'.length : null;\n}\n"],"mappings":"AAEA,OAAOA,IAAI,MAAM,MAAM;AACvB,OAAOC,KAAK,MAAM,OAAO;AACzB,SAAQC,QAAQ,QAAO,iBAAiB;AACxC,SAAQC,OAAO,QAAO,gBAAgB;AACtC,SAAQC,aAAa,QAAO,8BAA8B;AAE1D,MAAMC,SAAS,GAAIC,GAAW,IAAcA,GAAG,CAACC,UAAU,CAAC,OAAO,CAAC;AACnE,MAAMC,YAAY,GAAIF,GAAW,IAAcA,GAAG,CAACC,UAAU,CAAC,OAAO,CAAC,IAAID,GAAG,CAACC,UAAU,CAAC,QAAQ,CAAC;AAQlG,OAAO,eAAeE,SAASA,CAACH,GAAW,EAAEI,OAAoB,EAAqB;EACpF,IAAI;IAGF,IAAIC,UAAU,CAACC,KAAK,KAAKH,SAAS,KAAKD,YAAY,CAACF,GAAG,CAAC,IAAID,SAAS,CAACC,GAAG,CAAC,CAAC,EAAE;MAE3E,OAAO,MAAMM,KAAK,CAACN,GAAG,EAAEI,OAAO,CAAC;IAClC;IAIA,IAAIL,SAAS,CAACC,GAAG,CAAC,EAAE;MAClB,MAAM;QAACO,WAAW;QAAEC;MAAQ,CAAC,GAAGV,aAAa,CAACE,GAAG,CAAC;MAClD,MAAMS,QAAQ,GAAG,IAAIb,QAAQ,CAACW,WAAW,EAAE;QACzCG,OAAO,EAAE;UAAC,cAAc,EAAEF;QAAQ,CAAC;QACnCR;MACF,CAAC,CAAC;MACF,OAAOS,QAAQ;IACjB;IAGA,MAAME,wBAAwB,GAAG,CAAC,CAAC;IACnC,MAAMC,WAAW,GA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AM,CAACC,QAAQ,CAACH,aAAa,CAAC,EAAE;MAClCnD,OAAO,CAAC,gBAAgB,CAAC,GAAGmD,aAAa;IAC3C;EACF;EAEAhB,MAAM,CAACoB,MAAM,CAACvD,OAAO,EAAE8C,iBAAiB,CAAC;EAEzC,OAAO,IAAI3D,OAAO,CAACa,OAAO,CAAC;AAC7B;AAGA,SAASoD,gBAAgBA,CAAC9D,GAAW,EAAiB;EAEpD,OAAOD,SAAS,CAACC,GAAG,CAAC,GAAGA,GAAG,CAAC0D,MAAM,GAAG,OAAO,CAACA,MAAM,GAAG,IAAI;AAC5D"}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { ReadableStreamPolyfill } from './readable-stream';
|
|
2
1
|
import { BlobPolyfill } from './blob';
|
|
3
2
|
import { FileReaderPolyfill } from './file-reader';
|
|
4
3
|
import { FilePolyfill } from './file';
|
|
5
4
|
export function installFilePolyfills() {
|
|
6
|
-
if (typeof ReadableStream === 'undefined' && global) {
|
|
7
|
-
global.ReadableStream = ReadableStreamPolyfill;
|
|
8
|
-
}
|
|
5
|
+
if (typeof ReadableStream === 'undefined' && global) {}
|
|
9
6
|
if (typeof Blob === 'undefined' && global) {
|
|
10
7
|
global.Blob = BlobPolyfill;
|
|
11
8
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"install-file-polyfills.js","names":["
|
|
1
|
+
{"version":3,"file":"install-file-polyfills.js","names":["BlobPolyfill","FileReaderPolyfill","FilePolyfill","installFilePolyfills","ReadableStream","global","Blob","FileReader","File"],"sources":["../../../../src/node/file/install-file-polyfills.ts"],"sourcesContent":["// import {ReadableStreamPolyfill} from './readable-stream';\nimport {BlobPolyfill} from './blob';\nimport {FileReaderPolyfill} from './file-reader';\nimport {FilePolyfill} from './file';\n\nexport function installFilePolyfills() {\n if (typeof ReadableStream === 'undefined' && global) {\n // @ts-ignore;\n // global.ReadableStream = ReadableStreamPolyfill;\n }\n\n if (typeof Blob === 'undefined' && global) {\n // @ts-ignore;\n global.Blob = BlobPolyfill;\n }\n\n if (typeof FileReader === 'undefined' && global) {\n // @ts-ignore;\n global.FileReader = FileReaderPolyfill;\n }\n\n // Install minimal Node.js File polyfill\n if (typeof File === 'undefined' && global) {\n // @ts-ignore;\n global.File = FilePolyfill;\n }\n}\n"],"mappings":"AACA,SAAQA,YAAY,QAAO,QAAQ;AACnC,SAAQC,kBAAkB,QAAO,eAAe;AAChD,SAAQC,YAAY,QAAO,QAAQ;AAEnC,OAAO,SAASC,oBAAoBA,CAAA,EAAG;EACrC,IAAI,OAAOC,cAAc,KAAK,WAAW,IAAIC,MAAM,EAAE,CAGrD;EAEA,IAAI,OAAOC,IAAI,KAAK,WAAW,IAAID,MAAM,EAAE;IAEzCA,MAAM,CAACC,IAAI,GAAGN,YAAY;EAC5B;EAEA,IAAI,OAAOO,UAAU,KAAK,WAAW,IAAIF,MAAM,EAAE;IAE/CA,MAAM,CAACE,UAAU,GAAGN,kBAAkB;EACxC;EAGA,IAAI,OAAOO,IAAI,KAAK,WAAW,IAAIH,MAAM,EAAE;IAEzCA,MAAM,CAACG,IAAI,GAAGN,YAAY;EAC5B;AACF"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { FileSystem, RandomAccessReadFileSystem } from '@loaders.gl/loader-utils';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
type Stat = {
|
|
6
|
+
size: number;
|
|
7
|
+
isDirectory: () => boolean;
|
|
8
|
+
info?: fs.Stats;
|
|
9
|
+
};
|
|
10
|
+
type ReadOptions = {
|
|
11
|
+
buffer?: Buffer;
|
|
12
|
+
offset?: number;
|
|
13
|
+
length?: number;
|
|
14
|
+
position?: number;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* FileSystem pass-through for Node.js
|
|
18
|
+
* Compatible with BrowserFileSystem.
|
|
19
|
+
* @param options
|
|
20
|
+
*/
|
|
21
|
+
export declare class NodeFileSystem implements FileSystem, RandomAccessReadFileSystem {
|
|
22
|
+
constructor(options: {
|
|
23
|
+
[key: string]: any;
|
|
24
|
+
});
|
|
25
|
+
readdir(dirname?: string, options?: {}): Promise<any[]>;
|
|
26
|
+
stat(path: string, options?: {}): Promise<Stat>;
|
|
27
|
+
fetch(path: string, options: {
|
|
28
|
+
[key: string]: any;
|
|
29
|
+
}): Promise<any>;
|
|
30
|
+
open(path: string, flags: string | number, mode?: any): Promise<number>;
|
|
31
|
+
close(fd: number): Promise<void>;
|
|
32
|
+
fstat(fd: number): Promise<Stat>;
|
|
33
|
+
read(fd: number, { buffer, offset, length, position }: ReadOptions): Promise<{
|
|
34
|
+
bytesRead: number;
|
|
35
|
+
buffer: Uint8Array;
|
|
36
|
+
}>;
|
|
37
|
+
}
|
|
38
|
+
export {};
|
|
39
|
+
//# sourceMappingURL=node-filesystem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-filesystem.d.ts","sourceRoot":"","sources":["../../src/filesystems/node-filesystem.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAC,UAAU,EAAE,0BAA0B,EAAC,MAAM,0BAA0B,CAAC;AAChF,OAAO,EAAE,MAAM,IAAI,CAAC;AAMpB,KAAK,IAAI,GAAG;IACV,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,OAAO,CAAC;IAC3B,IAAI,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC;CACjB,CAAC;AAEF,KAAK,WAAW,GAAG;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;;GAIG;AACH,qBAAa,cAAe,YAAW,UAAU,EAAE,0BAA0B;gBAE/D,OAAO,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC;IAInC,OAAO,CAAC,OAAO,SAAM,EAAE,OAAO,CAAC,EAAE,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAIpD,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAK/C,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC;IAQjD,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;IAIvE,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIhC,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAMhC,IAAI,CACR,EAAE,EAAE,MAAM,EAEV,EAAC,MAAa,EAAE,MAAU,EAAE,MAA0B,EAAE,QAAe,EAAC,EAAE,WAAW,GACpF,OAAO,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,UAAU,CAAA;KAAC,CAAC;CAoBpD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.browser.d.ts","sourceRoot":"","sources":["../src/index.browser.ts"],"names":[],"mappings":"AAUA,wBAAgB,oBAAoB,SAAK;AAGzC,eAAO,MAAM,cAAc,MAAO,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
export { ReadableStreamPolyfill } from './node/file/readable-stream';
|
|
2
|
-
export { BlobPolyfill } from './node/file/blob';
|
|
3
1
|
export { FileReaderPolyfill } from './node/file/file-reader';
|
|
4
2
|
export { FilePolyfill } from './node/file/file';
|
|
5
3
|
export { installFilePolyfills } from './node/file/install-file-polyfills';
|
|
6
|
-
export {
|
|
7
|
-
export { fetchFileNode as _fetchFileNode } from './node/fetch/fetch-file.node';
|
|
4
|
+
export { NodeFileSystem } from './filesystems/node-filesystem';
|
|
8
5
|
//# sourceMappingURL=index.d.ts.map
|
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":"AAcA,OAAO,EAAC,kBAAkB,EAAC,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAC,YAAY,EAAC,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAC,oBAAoB,EAAC,MAAM,oCAAoC,CAAC;AAqCxE,OAAO,EAAC,cAAc,EAAC,MAAM,+BAA+B,CAAC"}
|
|
@@ -6,7 +6,7 @@ import { Response } from './response.node';
|
|
|
6
6
|
* @param url
|
|
7
7
|
* @param options
|
|
8
8
|
*/
|
|
9
|
-
export declare function fetchNode(url: string, options:
|
|
9
|
+
export declare function fetchNode(url: string, options: RequestInit): Promise<Response>;
|
|
10
10
|
/** Returns a promise that resolves to a readable stream */
|
|
11
11
|
export declare function createHTTPRequestReadStream(url: string, options: any): Promise<http.IncomingMessage>;
|
|
12
12
|
//# sourceMappingURL=fetch.node.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.node.d.ts","sourceRoot":"","sources":["../../../src/node/fetch/fetch.node.ts"],"names":[],"mappings":";AAEA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAC,QAAQ,EAAC,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"fetch.node.d.ts","sourceRoot":"","sources":["../../../src/node/fetch/fetch.node.ts"],"names":[],"mappings":";AAEA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAC,QAAQ,EAAC,MAAM,iBAAiB,CAAC;AAOzC;;;;GAIG;AAEH,wBAAsB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,CAgDpF;AAED,2DAA2D;AAC3D,wBAAsB,2BAA2B,CAC/C,GAAG,EAAE,MAAM,EACX,OAAO,KAAA,GACN,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,CAW/B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/polyfills",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-beta.2",
|
|
4
4
|
"description": "Polyfills for TextEncoder/TextDecoder",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -26,70 +26,10 @@
|
|
|
26
26
|
"README.md"
|
|
27
27
|
],
|
|
28
28
|
"browser": {
|
|
29
|
-
"./src/
|
|
30
|
-
"./
|
|
31
|
-
"./dist/es5/
|
|
32
|
-
"./dist/esm/
|
|
33
|
-
"./src/node/fetch/utils/stream-utils.node.js": false,
|
|
34
|
-
"./src/node/fetch/utils/stream-utils.node.ts": false,
|
|
35
|
-
"./dist/es5/node/fetch/utils/stream-utils.node.js": false,
|
|
36
|
-
"./dist/esm/node/fetch/utils/stream-utils.node.js": false,
|
|
37
|
-
"./src/node/fetch/fetch.node.js": false,
|
|
38
|
-
"./src/node/fetch/fetch.node.ts": false,
|
|
39
|
-
"./dist/es5/node/fetch/fetch.node.js": false,
|
|
40
|
-
"./dist/esm/node/fetch/fetch.node.js": false,
|
|
41
|
-
"./src/node/fetch/headers.node.js": false,
|
|
42
|
-
"./src/node/fetch/headers.node.ts": false,
|
|
43
|
-
"./dist/es5/node/fetch/headers.node.js": false,
|
|
44
|
-
"./dist/esm/node/fetch/headers.node.js": false,
|
|
45
|
-
"./src/node/fetch/response.node.js": false,
|
|
46
|
-
"./src/node/fetch/response.node.ts": false,
|
|
47
|
-
"./dist/es5/node/fetch/response.node.js": false,
|
|
48
|
-
"./dist/esm/node/fetch/response.node.js": false,
|
|
49
|
-
"./src/node/images/encode-image.node.js": false,
|
|
50
|
-
"./src/node/images/encode-image.node.ts": false,
|
|
51
|
-
"./dist/es5/node/images/encode-image.node.js": false,
|
|
52
|
-
"./dist/esm/node/images/encode-image.node.js": false,
|
|
53
|
-
"./src/node/images/parse-image.node.js": false,
|
|
54
|
-
"./src/node/images/parse-image.node.ts": false,
|
|
55
|
-
"./dist/es5/node/images/parse-image.node.js": false,
|
|
56
|
-
"./dist/esm/node/images/parse-image.node.js": false,
|
|
57
|
-
"./src/node/buffer/to-array-buffer.node.js": false,
|
|
58
|
-
"./src/node/buffer/to-array-buffer.node.ts": false,
|
|
59
|
-
"./dist/es5/node/buffer/to-array-buffer.node.js": false,
|
|
60
|
-
"./dist/esm/node/buffer/to-array-buffer.node.js": false,
|
|
61
|
-
"./src/node/buffer/btoa.node.js": false,
|
|
62
|
-
"./src/node/buffer/btoa.node.ts": false,
|
|
63
|
-
"./dist/es5/node/buffer/btoa.node.js": false,
|
|
64
|
-
"./dist/esm/node/buffer/btoa.node.js": false,
|
|
65
|
-
"./src/node/file/blob.js": false,
|
|
66
|
-
"./src/node/file/blob.ts": false,
|
|
67
|
-
"./dist/es5/node/file/blob.js": false,
|
|
68
|
-
"./dist/esm/node/file/blob.js": false,
|
|
69
|
-
"./src/node/file/file.js": false,
|
|
70
|
-
"./src/node/file/file.ts": false,
|
|
71
|
-
"./dist/es5/node/file/file.js": false,
|
|
72
|
-
"./dist/esm/node/file/file.js": false,
|
|
73
|
-
"./src/node/file/readable-stream.js": false,
|
|
74
|
-
"./src/node/file/readable-stream.ts": false,
|
|
75
|
-
"./dist/es5/node/file/readable-stream.js": false,
|
|
76
|
-
"./dist/esm/node/file/readable-stream.js": false,
|
|
77
|
-
"./src/libs/encoding-indices.js": false,
|
|
78
|
-
"./src/libs/encoding-indices.ts": false,
|
|
79
|
-
"./dist/es5/libs/encoding-indices.js": false,
|
|
80
|
-
"./dist/esm/libs/encoding-indices.js": false,
|
|
81
|
-
"fs": false,
|
|
82
|
-
"http": false,
|
|
83
|
-
"https": false,
|
|
84
|
-
"stream": false,
|
|
85
|
-
"get-pixels": false,
|
|
86
|
-
"ndarray": false,
|
|
87
|
-
"save-pixels": false,
|
|
88
|
-
"stream-to-async-iterator": false,
|
|
89
|
-
"through": false,
|
|
90
|
-
"util": false,
|
|
91
|
-
"zlib": false,
|
|
92
|
-
"web-streams-polyfill": false
|
|
29
|
+
"./src/index.ts": "./src/index.browser.ts",
|
|
30
|
+
"./dist/index.js": "./dist/index.browser.js",
|
|
31
|
+
"./dist/es5/index.js": "./dist/es5/index.browser.js",
|
|
32
|
+
"./dist/esm/index.js": "./dist/es5/index.browser.js"
|
|
93
33
|
},
|
|
94
34
|
"scripts": {
|
|
95
35
|
"pre-build": "npm run build-bundle",
|
|
@@ -105,5 +45,5 @@
|
|
|
105
45
|
"through": "^2.3.8",
|
|
106
46
|
"web-streams-polyfill": "^3.0.0"
|
|
107
47
|
},
|
|
108
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "79c2033f755e88e11bc30a04428e3666b177b8fc"
|
|
109
49
|
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import {FileSystem, RandomAccessReadFileSystem} from '@loaders.gl/loader-utils';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import fsPromise from 'fs/promises';
|
|
4
|
+
|
|
5
|
+
// import {fetchFile} from "../fetch/fetch-file"
|
|
6
|
+
// import {selectLoader} from "../api/select-loader";
|
|
7
|
+
|
|
8
|
+
type Stat = {
|
|
9
|
+
size: number;
|
|
10
|
+
isDirectory: () => boolean;
|
|
11
|
+
info?: fs.Stats;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
type ReadOptions = {
|
|
15
|
+
buffer?: Buffer;
|
|
16
|
+
offset?: number;
|
|
17
|
+
length?: number;
|
|
18
|
+
position?: number;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* FileSystem pass-through for Node.js
|
|
23
|
+
* Compatible with BrowserFileSystem.
|
|
24
|
+
* @param options
|
|
25
|
+
*/
|
|
26
|
+
export class NodeFileSystem implements FileSystem, RandomAccessReadFileSystem {
|
|
27
|
+
// implements FileSystem
|
|
28
|
+
constructor(options: {[key: string]: any}) {
|
|
29
|
+
this.fetch = options._fetch;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async readdir(dirname = '.', options?: {}): Promise<any[]> {
|
|
33
|
+
return await fsPromise.readdir(dirname, options);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async stat(path: string, options?: {}): Promise<Stat> {
|
|
37
|
+
const info = await fsPromise.stat(path, options);
|
|
38
|
+
return {size: Number(info.size), isDirectory: () => false, info};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async fetch(path: string, options: {[key: string]: any}) {
|
|
42
|
+
// Falls back to handle https:/http:/data: etc fetches
|
|
43
|
+
// eslint-disable-next-line
|
|
44
|
+
const fallbackFetch = options.fetch || this.fetch;
|
|
45
|
+
return fallbackFetch(path, options);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// implements IRandomAccessFileSystem
|
|
49
|
+
async open(path: string, flags: string | number, mode?: any): Promise<number> {
|
|
50
|
+
return (await fsPromise.open(path, flags)) as unknown as number;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async close(fd: number): Promise<void> {
|
|
54
|
+
fs.close(fd);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async fstat(fd: number): Promise<Stat> {
|
|
58
|
+
return await new Promise((resolve, reject) =>
|
|
59
|
+
fs.fstat(fd, (err, info) => (err ? reject(err) : resolve(info)))
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async read(
|
|
64
|
+
fd: number,
|
|
65
|
+
// @ts-ignore Possibly null
|
|
66
|
+
{buffer = null, offset = 0, length = buffer.byteLength, position = null}: ReadOptions
|
|
67
|
+
): Promise<{bytesRead: number; buffer: Uint8Array}> {
|
|
68
|
+
let totalBytesRead = 0;
|
|
69
|
+
// Read in loop until we get required number of bytes
|
|
70
|
+
while (totalBytesRead < length) {
|
|
71
|
+
const {bytesRead} = await new Promise<{bytesRead: number; buffer: Buffer}>(
|
|
72
|
+
// eslint-disable-next-line no-loop-func
|
|
73
|
+
(resolve, reject) =>
|
|
74
|
+
fs.read(
|
|
75
|
+
fd,
|
|
76
|
+
buffer,
|
|
77
|
+
offset + totalBytesRead,
|
|
78
|
+
length - totalBytesRead,
|
|
79
|
+
position + totalBytesRead,
|
|
80
|
+
(err, bytesRead, buffer) => (err ? reject(err) : resolve({bytesRead, buffer}))
|
|
81
|
+
)
|
|
82
|
+
);
|
|
83
|
+
totalBytesRead += bytesRead;
|
|
84
|
+
}
|
|
85
|
+
return {bytesRead: totalBytesRead, buffer};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// loaders.gl, MIT License
|
|
2
|
+
|
|
3
|
+
import {allSettled} from './promise/all-settled';
|
|
4
|
+
|
|
5
|
+
if (!('allSettled' in Promise)) {
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
Promise.allSettled = allSettled;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
11
|
+
export function installFilePolyfills() {}
|
|
12
|
+
|
|
13
|
+
// Dummy export to avoid import errors in browser tests
|
|
14
|
+
export const NodeFileSystem = null;
|