@loaders.gl/polyfills 4.0.0-beta.6 → 4.0.0-beta.8
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/LICENSE +7 -7
- package/dist/fetch/fetch-polyfill.d.ts.map +1 -1
- package/dist/fetch/fetch-polyfill.js.map +1 -1
- package/dist/fetch/response-polyfill.d.ts.map +1 -1
- package/dist/fetch/response-polyfill.js.map +1 -1
- package/dist/filesystems/fetch-node.d.ts.map +1 -1
- package/dist/filesystems/fetch-node.js.map +1 -1
- package/dist/filesystems/node-filesystem.d.ts.map +1 -1
- package/dist/filesystems/node-filesystem.js.map +1 -1
- package/dist/filesystems/stream-utils.node.d.ts.map +1 -1
- package/dist/filesystems/stream-utils.node.js.map +1 -1
- package/dist/images/parse-image-node.d.ts.map +1 -1
- package/dist/images/parse-image-node.js.map +1 -1
- package/dist/images/parse-image.node.d.ts.map +1 -1
- package/dist/images/parse-image.node.js.map +1 -1
- package/dist/index.cjs +180 -82
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/utils/is-browser.d.ts.map +1 -1
- package/dist/utils/is-browser.js.map +1 -1
- package/package.json +9 -9
- package/src/fetch/fetch-polyfill.ts +1 -0
- package/src/fetch/response-polyfill.ts +1 -0
- package/src/filesystems/fetch-node.ts +1 -0
- package/src/filesystems/node-filesystem.ts +1 -0
- package/src/filesystems/stream-utils.node.ts +1 -0
- package/src/images/parse-image-node.ts +1 -0
- package/src/images/parse-image.node.ts +1 -0
- package/src/index.ts +7 -0
- package/src/utils/is-browser.ts +1 -0
package/LICENSE
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
This software includes parts of PhiloGL (https://github.com/philogb/philogl)
|
|
4
|
-
under MIT license. PhiloGL parts Copyright © 2013 Sencha Labs.
|
|
1
|
+
loaders.gl is licensed under the MIT license
|
|
5
2
|
|
|
6
|
-
|
|
3
|
+
Copyright (c) vis.gl contributors
|
|
7
4
|
|
|
8
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -23,8 +20,12 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
23
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
24
21
|
THE SOFTWARE.
|
|
25
22
|
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
Copyright (c) 2015 Uber Technologies, Inc.
|
|
26
26
|
|
|
27
|
-
loaders.gl includes certain files from Cesium (https://github.com/AnalyticalGraphicsInc/cesium)
|
|
27
|
+
loaders.gl includes certain files from Cesium (https://github.com/AnalyticalGraphicsInc/cesium)
|
|
28
|
+
under the Apache 2 License (found in the submodule: modules/3d-tiles):)
|
|
28
29
|
|
|
29
30
|
Copyright 2011-2018 CesiumJS Contributors
|
|
30
31
|
|
|
@@ -38,4 +39,3 @@ distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
38
39
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
39
40
|
See the License for the specific language governing permissions and limitations under the License.
|
|
40
41
|
|
|
41
|
-
Cesium-derived code can be found in the submodule: modules/3d-tiles
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-polyfill.d.ts","sourceRoot":"","sources":["../../src/fetch/fetch-polyfill.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"fetch-polyfill.d.ts","sourceRoot":"","sources":["../../src/fetch/fetch-polyfill.ts"],"names":[],"mappings":";AAGA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAC,QAAQ,EAAC,MAAM,qBAAqB,CAAC;AAO7C;;;;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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-polyfill.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/fetch/fetch-polyfill.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport http from 'http';\nimport https from 'https';\nimport {Response} from './response-polyfill';\nimport {Headers} from './headers-polyfill';\nimport {decodeDataUri} from './decode-data-uri';\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;AAAC,SAClBC,QAAQ;AAAA,SACRC,OAAO;AAAA,SACPC,aAAa;AAErB,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,CAAC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C,SAAA,MAAG,CAAC,CAAC;EAC3D,MAAM/C,OAAO,GAAG,CAAC,CAAC;EAElB,IAAI2C,YAAY,IAAIA,YAAY,CAAC3C,OAAO,EAAE;IACxC,MAAMiD,WAAW,GAAGN,YAAY,CAAC3C,OAAO;IACxC,KAAK,MAAMkC,GAAG,IAAIe,WAAW,EAAE;MAC7B,MAAMC,MAAM,GAAGD,WAAW,CAACf,GAAG,CAAC;MAC/BlC,OAAO,CAACkC,GAAG,CAACG,WAAW,CAAC,CAAC,CAAC,GAAGnB,MAAM,CAACgC,MAAM,CAAC;IAC7C;EACF;EAGA,IAAI,CAAClD,OAAO,CAAC,gBAAgB,CAAC,EAAE;IAC9B,MAAMmD,aAAa,GAAGC,gBAAgB,CAAC9D,GAAG,CAAC;IAC3C,IAAI+D,MAAM,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
|
+
{"version":3,"file":"fetch-polyfill.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/fetch/fetch-polyfill.ts"],"sourcesContent":["// loaders.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport http from 'http';\nimport https from 'https';\nimport {Response} from './response-polyfill';\nimport {Headers} from './headers-polyfill';\nimport {decodeDataUri} from './decode-data-uri';\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":"AAGA,OAAOA,IAAI,MAAM,MAAM;AACvB,OAAOC,KAAK,MAAM,OAAO;AAAC,SAClBC,QAAQ;AAAA,SACRC,OAAO;AAAA,SACPC,aAAa;AAErB,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,GAAGZ,GAAG;IACvB,IAAIA,GAAG,CAACa,QAAQ,CA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D,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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response-polyfill.d.ts","sourceRoot":"","sources":["../../src/fetch/response-polyfill.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"response-polyfill.d.ts","sourceRoot":"","sources":["../../src/fetch/response-polyfill.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,OAAO,EAAC,MAAM,oBAAoB,CAAC;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;IAuBH,IAAI,IAAI,QAKP;IAIK,WAAW;IAQX,IAAI;IAMJ,IAAI;IAKJ,IAAI;CAMX"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response-polyfill.js","names":["assert","decompressReadStream","concatenateReadStream","Headers","isBoolean","x","isFunction","isObject","isReadableNodeStream","read","pipe","readable","stream","Response","constructor","body","options","ok","status","statusText","headers","url","bodyUsed","_body","Readable","from","TextEncoder","encode","ArrayBuffer","arrayBuffer","data","text","textDecoder","TextDecoder","decode","json","JSON","parse","blob","Blob","Error"],"sources":["../../src/fetch/response-polyfill.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport {assert} from '../utils/assert';\nimport {decompressReadStream, concatenateReadStream} from '../filesystems/stream-utils.node';\nimport {Headers} from './headers-polyfill';\n\nconst isBoolean = (x) => typeof x === 'boolean';\nconst isFunction = (x) => typeof x === 'function';\nconst isObject = (x) => x !== null && typeof x === 'object';\nconst isReadableNodeStream = (x) =>\n isObject(x) && isFunction(x.read) && isFunction(x.pipe) && isBoolean(x.readable);\n\n/**\n * Polyfill for Browser Response\n *\n * Under Node.js we return a mock \"fetch response object\"\n * so that apps can use the same API as in the browser.\n *\n * Note: This is intended to be a \"lightweight\" implementation and will have limitations.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/API/Response\n */\nimport * as stream from 'stream';\n\nexport class Response {\n readonly ok: boolean;\n readonly status: number;\n readonly statusText: string;\n readonly headers: Headers;\n readonly url: string;\n bodyUsed: boolean = false;\n private readonly _body;\n\n // TODO - handle ArrayBuffer, ArrayBufferView, Buffer\n constructor(\n body,\n options: {\n headers?;\n status?: number;\n statusText?: string;\n url: string;\n }\n ) {\n const {headers, status = 200, statusText = 'OK', url} = options || {};\n\n this.url = url;\n this.ok = status === 200;\n this.status = status; // TODO - handle errors and set status\n this.statusText = statusText;\n this.headers = new Headers(options?.headers || {});\n\n // Check for content-encoding and create a decompression stream\n if (isReadableNodeStream(body)) {\n this._body = decompressReadStream(body, headers);\n } else if (typeof body === 'string') {\n this._body = stream.Readable.from([new TextEncoder().encode(body)]);\n } else {\n this._body = stream.Readable.from([body || new ArrayBuffer(0)]);\n }\n }\n\n // Subset of Properties\n\n // Returns a readable stream to the \"body\" of the response (or file)\n get body() {\n assert(!this.bodyUsed);\n assert(isReadableNodeStream(this._body)); // Not implemented: conversion of ArrayBuffer etc to stream\n this.bodyUsed = true;\n return this._body;\n }\n\n // Subset of Methods\n\n async arrayBuffer() {\n if (!isReadableNodeStream(this._body)) {\n return this._body || new ArrayBuffer(0);\n }\n const data = await concatenateReadStream(this._body);\n return data;\n }\n\n async text() {\n const arrayBuffer = await this.arrayBuffer();\n const textDecoder = new TextDecoder();\n return textDecoder.decode(arrayBuffer);\n }\n\n async json() {\n const text = await this.text();\n return JSON.parse(text);\n }\n\n async blob() {\n if (typeof Blob === 'undefined') {\n throw new Error('Blob polyfill not installed');\n }\n return new Blob([await this.arrayBuffer()]);\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"response-polyfill.js","names":["assert","decompressReadStream","concatenateReadStream","Headers","isBoolean","x","isFunction","isObject","isReadableNodeStream","read","pipe","readable","stream","Response","constructor","body","options","ok","status","statusText","headers","url","bodyUsed","_body","Readable","from","TextEncoder","encode","ArrayBuffer","arrayBuffer","data","text","textDecoder","TextDecoder","decode","json","JSON","parse","blob","Blob","Error"],"sources":["../../src/fetch/response-polyfill.ts"],"sourcesContent":["// loaders.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport {assert} from '../utils/assert';\nimport {decompressReadStream, concatenateReadStream} from '../filesystems/stream-utils.node';\nimport {Headers} from './headers-polyfill';\n\nconst isBoolean = (x) => typeof x === 'boolean';\nconst isFunction = (x) => typeof x === 'function';\nconst isObject = (x) => x !== null && typeof x === 'object';\nconst isReadableNodeStream = (x) =>\n isObject(x) && isFunction(x.read) && isFunction(x.pipe) && isBoolean(x.readable);\n\n/**\n * Polyfill for Browser Response\n *\n * Under Node.js we return a mock \"fetch response object\"\n * so that apps can use the same API as in the browser.\n *\n * Note: This is intended to be a \"lightweight\" implementation and will have limitations.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/API/Response\n */\nimport * as stream from 'stream';\n\nexport class Response {\n readonly ok: boolean;\n readonly status: number;\n readonly statusText: string;\n readonly headers: Headers;\n readonly url: string;\n bodyUsed: boolean = false;\n private readonly _body;\n\n // TODO - handle ArrayBuffer, ArrayBufferView, Buffer\n constructor(\n body,\n options: {\n headers?;\n status?: number;\n statusText?: string;\n url: string;\n }\n ) {\n const {headers, status = 200, statusText = 'OK', url} = options || {};\n\n this.url = url;\n this.ok = status === 200;\n this.status = status; // TODO - handle errors and set status\n this.statusText = statusText;\n this.headers = new Headers(options?.headers || {});\n\n // Check for content-encoding and create a decompression stream\n if (isReadableNodeStream(body)) {\n this._body = decompressReadStream(body, headers);\n } else if (typeof body === 'string') {\n this._body = stream.Readable.from([new TextEncoder().encode(body)]);\n } else {\n this._body = stream.Readable.from([body || new ArrayBuffer(0)]);\n }\n }\n\n // Subset of Properties\n\n // Returns a readable stream to the \"body\" of the response (or file)\n get body() {\n assert(!this.bodyUsed);\n assert(isReadableNodeStream(this._body)); // Not implemented: conversion of ArrayBuffer etc to stream\n this.bodyUsed = true;\n return this._body;\n }\n\n // Subset of Methods\n\n async arrayBuffer() {\n if (!isReadableNodeStream(this._body)) {\n return this._body || new ArrayBuffer(0);\n }\n const data = await concatenateReadStream(this._body);\n return data;\n }\n\n async text() {\n const arrayBuffer = await this.arrayBuffer();\n const textDecoder = new TextDecoder();\n return textDecoder.decode(arrayBuffer);\n }\n\n async json() {\n const text = await this.text();\n return JSON.parse(text);\n }\n\n async blob() {\n if (typeof Blob === 'undefined') {\n throw new Error('Blob polyfill not installed');\n }\n return new Blob([await this.arrayBuffer()]);\n }\n}\n"],"mappings":"SAGQA,MAAM;AAAA,SACNC,oBAAoB,EAAEC,qBAAqB;AAAA,SAC3CC,OAAO;AAEf,MAAMC,SAAS,GAAIC,CAAC,IAAK,OAAOA,CAAC,KAAK,SAAS;AAC/C,MAAMC,UAAU,GAAID,CAAC,IAAK,OAAOA,CAAC,KAAK,UAAU;AACjD,MAAME,QAAQ,GAAIF,CAAC,IAAKA,CAAC,KAAK,IAAI,IAAI,OAAOA,C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
|
1
|
-
{"version":3,"file":"fetch-node.d.ts","sourceRoot":"","sources":["../../src/filesystems/fetch-node.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fetch-node.d.ts","sourceRoot":"","sources":["../../src/filesystems/fetch-node.ts"],"names":[],"mappings":"AAcA;;;;;GAKG;AAEH,wBAAsB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,CAyDrF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-node.js","names":["fs","Readable","resolvePath","decompressReadStream","isBoolean","x","isFunction","isObject","isReadableNodeStream","read","pipe","readable","fetchNode","url","options","FILE_PROTOCOL_REGEX","replace","noqueryUrl","split","responseHeaders","Headers","endsWith","body","Promise","resolve","reject","stream","createReadStream","encoding","once","on","error","bodyStream","from","TextEncoder","encode","ArrayBuffer","status","statusText","headers","getHeadersForFile","response","Response","Object","defineProperty","value","errorMessage","message","stats","statSync","size","slice"],"sources":["../../src/filesystems/fetch-node.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport fs from 'fs';\nimport {Readable} from 'stream';\nimport {resolvePath} from '@loaders.gl/loader-utils';\nimport {decompressReadStream} from './stream-utils.node';\n\nconst isBoolean = (x) => typeof x === 'boolean';\nconst isFunction = (x) => typeof x === 'function';\nconst isObject = (x) => x !== null && typeof x === 'object';\nconst isReadableNodeStream = (x) =>\n isObject(x) && isFunction(x.read) && isFunction(x.pipe) && isBoolean(x.readable);\n\n/**\n * Enables\n * @param url\n * @param options\n * @returns\n */\n// eslint-disable-next-line max-statements\nexport async function fetchNode(url: string, options?: RequestInit): Promise<Response> {\n // Support `file://` protocol\n const FILE_PROTOCOL_REGEX = /^file:\\/\\//;\n url.replace(FILE_PROTOCOL_REGEX, '/');\n\n // Remove any query parameters, as they have no meaning\n let noqueryUrl = url.split('?')[0];\n noqueryUrl = resolvePath(noqueryUrl);\n\n const responseHeaders = new Headers();\n // Automatically decompress gzipped files with .gz extension\n if (url.endsWith('.gz')) {\n // url = url.slice(0, -3);\n responseHeaders['content-encoding'] = 'gzip';\n }\n if (url.endsWith('.br')) {\n // url = url.slice(0, -3);\n responseHeaders['content-encoding'] = 'br';\n }\n\n try {\n // Now open the stream\n const body = await new Promise<fs.ReadStream>((resolve, reject) => {\n // @ts-ignore\n const stream = fs.createReadStream(noqueryUrl, {encoding: null});\n stream.once('readable', () => resolve(stream));\n stream.on('error', (error) => reject(error));\n });\n\n let bodyStream: Readable = body;\n\n // Check for content-encoding and create a decompression stream\n if (isReadableNodeStream(body)) {\n bodyStream = decompressReadStream(body, responseHeaders);\n } else if (typeof body === 'string') {\n bodyStream = Readable.from([new TextEncoder().encode(body)]);\n } else {\n bodyStream = Readable.from([body || new ArrayBuffer(0)]);\n }\n\n const status = 200;\n const statusText = 'OK';\n const headers = getHeadersForFile(noqueryUrl);\n // @ts-expect-error\n const response = new Response(bodyStream, {headers, status, statusText});\n Object.defineProperty(response, 'url', {value: url});\n return response;\n } catch (error) {\n // console.error(error);\n const errorMessage = (error as Error).message;\n const status = 400;\n const statusText = errorMessage;\n const headers = {};\n const response = new Response(errorMessage, {headers, status, statusText});\n Object.defineProperty(response, 'url', {value: url});\n return response;\n }\n}\n\nfunction getHeadersForFile(noqueryUrl: string): Headers {\n const headers = {};\n\n // Fix up content length if we can for best progress experience\n if (!headers['content-length']) {\n const stats = fs.statSync(noqueryUrl);\n headers['content-length'] = stats.size;\n }\n\n // Automatically decompress gzipped files with .gz extension\n if (noqueryUrl.endsWith('.gz')) {\n noqueryUrl = noqueryUrl.slice(0, -3);\n headers['content-encoding'] = 'gzip';\n }\n\n return new Headers(headers);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"fetch-node.js","names":["fs","Readable","resolvePath","decompressReadStream","isBoolean","x","isFunction","isObject","isReadableNodeStream","read","pipe","readable","fetchNode","url","options","FILE_PROTOCOL_REGEX","replace","noqueryUrl","split","responseHeaders","Headers","endsWith","body","Promise","resolve","reject","stream","createReadStream","encoding","once","on","error","bodyStream","from","TextEncoder","encode","ArrayBuffer","status","statusText","headers","getHeadersForFile","response","Response","Object","defineProperty","value","errorMessage","message","stats","statSync","size","slice"],"sources":["../../src/filesystems/fetch-node.ts"],"sourcesContent":["// loaders.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport fs from 'fs';\nimport {Readable} from 'stream';\nimport {resolvePath} from '@loaders.gl/loader-utils';\nimport {decompressReadStream} from './stream-utils.node';\n\nconst isBoolean = (x) => typeof x === 'boolean';\nconst isFunction = (x) => typeof x === 'function';\nconst isObject = (x) => x !== null && typeof x === 'object';\nconst isReadableNodeStream = (x) =>\n isObject(x) && isFunction(x.read) && isFunction(x.pipe) && isBoolean(x.readable);\n\n/**\n * Enables\n * @param url\n * @param options\n * @returns\n */\n// eslint-disable-next-line max-statements\nexport async function fetchNode(url: string, options?: RequestInit): Promise<Response> {\n // Support `file://` protocol\n const FILE_PROTOCOL_REGEX = /^file:\\/\\//;\n url.replace(FILE_PROTOCOL_REGEX, '/');\n\n // Remove any query parameters, as they have no meaning\n let noqueryUrl = url.split('?')[0];\n noqueryUrl = resolvePath(noqueryUrl);\n\n const responseHeaders = new Headers();\n // Automatically decompress gzipped files with .gz extension\n if (url.endsWith('.gz')) {\n // url = url.slice(0, -3);\n responseHeaders['content-encoding'] = 'gzip';\n }\n if (url.endsWith('.br')) {\n // url = url.slice(0, -3);\n responseHeaders['content-encoding'] = 'br';\n }\n\n try {\n // Now open the stream\n const body = await new Promise<fs.ReadStream>((resolve, reject) => {\n // @ts-ignore\n const stream = fs.createReadStream(noqueryUrl, {encoding: null});\n stream.once('readable', () => resolve(stream));\n stream.on('error', (error) => reject(error));\n });\n\n let bodyStream: Readable = body;\n\n // Check for content-encoding and create a decompression stream\n if (isReadableNodeStream(body)) {\n bodyStream = decompressReadStream(body, responseHeaders);\n } else if (typeof body === 'string') {\n bodyStream = Readable.from([new TextEncoder().encode(body)]);\n } else {\n bodyStream = Readable.from([body || new ArrayBuffer(0)]);\n }\n\n const status = 200;\n const statusText = 'OK';\n const headers = getHeadersForFile(noqueryUrl);\n // @ts-expect-error\n const response = new Response(bodyStream, {headers, status, statusText});\n Object.defineProperty(response, 'url', {value: url});\n return response;\n } catch (error) {\n // console.error(error);\n const errorMessage = (error as Error).message;\n const status = 400;\n const statusText = errorMessage;\n const headers = {};\n const response = new Response(errorMessage, {headers, status, statusText});\n Object.defineProperty(response, 'url', {value: url});\n return response;\n }\n}\n\nfunction getHeadersForFile(noqueryUrl: string): Headers {\n const headers = {};\n\n // Fix up content length if we can for best progress experience\n if (!headers['content-length']) {\n const stats = fs.statSync(noqueryUrl);\n headers['content-length'] = stats.size;\n }\n\n // Automatically decompress gzipped files with .gz extension\n if (noqueryUrl.endsWith('.gz')) {\n noqueryUrl = noqueryUrl.slice(0, -3);\n headers['content-encoding'] = 'gzip';\n }\n\n return new Headers(headers);\n}\n"],"mappings":"AAGA,OAAOA,EAAE,MAAM,IAAI;AACnB,SAAQC,QAAQ,QAAO,QAAQ;AAC/B,SAAQC,WAAW,QAAO,0BAA0B;AAAC,SAC7CC,oBAAoB;AAE5B,MAAMC,SAAS,GAAIC,CAAC,IAAK,OAAOA,CAAC,KAAK,SAAS;AAC/C,MAAMC,UAAU,GAAID,CAAC,IAAK,OAAOA,CAAC,KAAK,UAAU;AACjD,MAAME,QAAQ,GAAIF,CAAC,IAAKA,CAAC,KAAK,IAAI,IAAI,OAAOA,CAAC,KAAK,QAAQ;AAC3D,MAAMG,oBAAoB,GAAIH,CAAC,IAC7BE,QAAQ,CAACF,CAAC,CAAC,IAAIC,UAAU,CAACD,CAAC,CAACI,IAAI,CAAC,IAAIH,UAAU,CAACD,CAAC,CAACK,IAAI,CAAC,IAAIN,SAAS,CAACC,CAAC,CAACM,QAAQ,CAAC;AASlF,OAAO,eAAeC,SAASA,CAACC,GAAW,EAAEC,OAAqB,EAAqB;EAErF,MAAMC,mBAAmB,GAAG,Y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E,CAAC,CAAC,CAAC;IACpCZ,OAAO,CAAC,kBAAkB,CAAC,GAAG,MAAM;EACtC;EAEA,OAAO,IAAInB,OAAO,CAACmB,OAAO,CAAC;AAC7B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-filesystem.d.ts","sourceRoot":"","sources":["../../src/filesystems/node-filesystem.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"node-filesystem.d.ts","sourceRoot":"","sources":["../../src/filesystems/node-filesystem.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,IAAI,EAAE,sBAAsB,EAAC,MAAM,0BAA0B,CAAC;AAEtE,OAAO,EAAC,QAAQ,EAAC,MAAM,aAAa,CAAC;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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-filesystem.js","names":["fsPromise","NodeFile","fetchNode","NodeFileSystem","constructor","readable","writable","readdir","dirname","arguments","length","undefined","options","stat","path","info","bigint","size","Number","bigsize","isDirectory","unlink","fetch","openReadableFile","flags","openWritableFile","mode"],"sources":["../../src/filesystems/node-filesystem.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport {Stat, RandomAccessFileSystem} from '@loaders.gl/loader-utils';\nimport fsPromise from 'fs/promises';\nimport {NodeFile} from './node-file';\nimport {fetchNode} from './fetch-node';\n\n// import {fetchFile} from \"../fetch/fetch-file\"\n// import {selectLoader} from \"../api/select-loader\";\n\n/**\n * FileSystem pass-through for Node.js\n * Compatible with BrowserFileSystem.\n * @param options\n */\nexport class NodeFileSystem implements RandomAccessFileSystem {\n readable: boolean = true;\n writable: boolean = true;\n\n // implements FileSystem\n constructor() {}\n\n async readdir(dirname = '.', options?: {}): Promise<any[]> {\n return await fsPromise.readdir(dirname, options);\n }\n\n async stat(path: string): Promise<Stat> {\n const info = await fsPromise.stat(path, {bigint: true});\n return {\n size: Number(info.size),\n bigsize: info.size,\n isDirectory: info.isDirectory()\n };\n }\n\n async unlink(path: string): Promise<void> {\n return await fsPromise.unlink(path);\n }\n\n async fetch(path: string, options: RequestInit): Promise<Response> {\n return await fetchNode(path, options);\n }\n\n // implements IRandomAccessFileSystem\n async openReadableFile(path: string, flags: 'r' = 'r'): Promise<NodeFile> {\n return new NodeFile(path, flags);\n }\n\n async openWritableFile(path: string, flags: 'w' | 'wx' = 'w', mode?: any): Promise<NodeFile> {\n return new NodeFile(path, flags, mode);\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"node-filesystem.js","names":["fsPromise","NodeFile","fetchNode","NodeFileSystem","constructor","readable","writable","readdir","dirname","arguments","length","undefined","options","stat","path","info","bigint","size","Number","bigsize","isDirectory","unlink","fetch","openReadableFile","flags","openWritableFile","mode"],"sources":["../../src/filesystems/node-filesystem.ts"],"sourcesContent":["// loaders.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport {Stat, RandomAccessFileSystem} from '@loaders.gl/loader-utils';\nimport fsPromise from 'fs/promises';\nimport {NodeFile} from './node-file';\nimport {fetchNode} from './fetch-node';\n\n// import {fetchFile} from \"../fetch/fetch-file\"\n// import {selectLoader} from \"../api/select-loader\";\n\n/**\n * FileSystem pass-through for Node.js\n * Compatible with BrowserFileSystem.\n * @param options\n */\nexport class NodeFileSystem implements RandomAccessFileSystem {\n readable: boolean = true;\n writable: boolean = true;\n\n // implements FileSystem\n constructor() {}\n\n async readdir(dirname = '.', options?: {}): Promise<any[]> {\n return await fsPromise.readdir(dirname, options);\n }\n\n async stat(path: string): Promise<Stat> {\n const info = await fsPromise.stat(path, {bigint: true});\n return {\n size: Number(info.size),\n bigsize: info.size,\n isDirectory: info.isDirectory()\n };\n }\n\n async unlink(path: string): Promise<void> {\n return await fsPromise.unlink(path);\n }\n\n async fetch(path: string, options: RequestInit): Promise<Response> {\n return await fetchNode(path, options);\n }\n\n // implements IRandomAccessFileSystem\n async openReadableFile(path: string, flags: 'r' = 'r'): Promise<NodeFile> {\n return new NodeFile(path, flags);\n }\n\n async openWritableFile(path: string, flags: 'w' | 'wx' = 'w', mode?: any): Promise<NodeFile> {\n return new NodeFile(path, flags, mode);\n }\n}\n"],"mappings":"AAIA,OAAOA,SAAS,MAAM,aAAa;AAAC,SAC5BC,QAAQ;AAAA,SACRC,SAAS;AAUjB,OAAO,MAAMC,cAAc,CAAmC;EAK5DC,WAAWA,CAAA,EAAG;IAAA,KAJdC,QAAQ,GAAY,IAAI;IAAA,KACxBC,QAAQ,GAAY,IAAI;EAGT;EAEf,MAAMC,OAAOA,CAAA,EAA8C;IAAA,IAA7CC,OAAO,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,GAAG;IAAA,IAAEG,OAAY,GAAAH,SAAA,CAAAC,MAAA,OAAAD,SAAA,MAAAE,SAAA;IACvC,OAAO,MAAMX,SAAS,CAACO,OAAO,CAACC,OAAO,EAAEI,OAAO,CAAC;EAClD;EAEA,MAAMC,IAAIA,CAACC,IAAY,EAAiB;IACtC,MAAMC,IAAI,GAAG,MAAMf,SAAS,CAACa,IAAI,CAACC,IAAI,EAAE;MAACE,MAAM,EAAE;IAAI,CAAC,CAAC;IACvD,OAAO;MACLC,IAAI,EAAEC,MAAM,CAACH,IAAI,CAACE,IAAI,CAAC;MACvBE,OAAO,EAAEJ,IAAI,CAACE,IAAI;MAClBG,WAAW,EAAEL,IAAI,CAACK,WAAW,CAAC;IAChC,CAAC;EACH;EAEA,MAAMC,MAAMA,CAACP,IAAY,EAAiB;IACxC,OAAO,MAAMd,SAAS,CAACqB,MAAM,CAACP,IAAI,CAAC;EACrC;EAEA,MAAMQ,KAAKA,CAACR,IAAY,EAAEF,OAAoB,EAAqB;IACjE,OAAO,MAAMV,SAAS,CAACY,IAAI,EAAEF,OAAO,CAAC;EACvC;EAGA,MAAMW,gBAAgBA,CAACT,IAAY,EAAuC;IAAA,IAArCU,KAAU,GAAAf,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,GAAG;IACnD,OAAO,IAAIR,QAAQ,CAACa,IAAI,EAAEU,KAAK,CAAC;EAClC;EAEA,MAAMC,gBAAgBA,CAACX,IAAY,EAA0D;IAAA,IAAxDU,KAAiB,GAAAf,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,GAAG;IAAA,IAAEiB,IAAU,GAAAjB,SAAA,CAAAC,MAAA,OAAAD,SAAA,MAAAE,SAAA;IACtE,OAAO,IAAIV,QAAQ,CAACa,IAAI,EAAEU,KAAK,EAAEE,IAAI,CAAC;EACxC;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-utils.node.d.ts","sourceRoot":"","sources":["../../src/filesystems/stream-utils.node.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"stream-utils.node.d.ts","sourceRoot":"","sources":["../../src/filesystems/stream-utils.node.ts"],"names":[],"mappings":";AAIA,OAAO,EAAC,QAAQ,EAAC,MAAM,QAAQ,CAAC;AAKhC;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,OAAO,YAY3E;AAED;;;;GAIG;AACH,wBAAsB,qBAAqB,CAAC,UAAU,KAAA,GAAG,OAAO,CAAC,WAAW,CAAC,CAsB5E;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,CAAC,WAAW,GAAG,UAAU,CAAC,EAAE,GAAG,WAAW,CAqB1F;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,OAAO,GAAG,WAAW,CA+BxD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-utils.node.js","names":["zlib","isArrayBuffer","x","ArrayBuffer","isBuffer","Buffer","decompressReadStream","readStream","headers","get","pipe","createBrotliDecompress","createGunzip","createDeflate","concatenateReadStream","arrayBufferChunks","Promise","resolve","reject","on","error","read","chunk","Error","push","toArrayBuffer","arrayBuffer","concatenateArrayBuffers","sources","sourceArrays","map","source2","Uint8Array","byteLength","reduce","length","typedArray","result","offset","sourceArray","set","buffer","data","isView","text","uint8Array","TextEncoder","encode","_toArrayBuffer","JSON","stringify","slice"],"sources":["../../src/filesystems/stream-utils.node.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport zlib from 'zlib';\nimport {Readable} from 'stream';\n\nconst isArrayBuffer = (x) => x && x instanceof ArrayBuffer;\nconst isBuffer = (x) => x && x instanceof Buffer;\n\n/**\n *\n */\nexport function decompressReadStream(readStream: Readable, headers?: Headers) {\n switch (headers?.get('content-encoding')) {\n case 'br':\n return readStream.pipe(zlib.createBrotliDecompress());\n case 'gzip':\n return readStream.pipe(zlib.createGunzip());\n case 'deflate':\n return readStream.pipe(zlib.createDeflate());\n default:\n // No compression or an unknown one, just return it as is\n return readStream;\n }\n}\n\n/**\n *\n * @param readStream\n * @returns\n */\nexport async function concatenateReadStream(readStream): Promise<ArrayBuffer> {\n const arrayBufferChunks: ArrayBuffer[] = [];\n\n return await new Promise((resolve, reject) => {\n readStream.on('error', (error) => reject(error));\n\n // Once the readable callback has been added, stream switches to \"flowing mode\"\n // In Node 10 (but not 12 and 14) this causes `data` and `end` to never be called unless we read data here\n readStream.on('readable', () => readStream.read());\n\n readStream.on('data', (chunk) => {\n if (typeof chunk === 'string') {\n reject(new Error('Read stream not binary'));\n }\n arrayBufferChunks.push(toArrayBuffer(chunk));\n });\n\n readStream.on('end', () => {\n const arrayBuffer = concatenateArrayBuffers(arrayBufferChunks);\n resolve(arrayBuffer);\n });\n });\n}\n\n/**\n * Concatenate a sequence of ArrayBuffers\n * @return A concatenated ArrayBuffer\n * @note duplicates loader-utils since polyfills should be independent\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 * @param data\n * @todo Duplicate of core\n */\nexport function toArrayBuffer(data: unknown): ArrayBuffer {\n if (isArrayBuffer(data)) {\n return data as ArrayBuffer;\n }\n\n // TODO - per docs we should just be able to call buffer.buffer, but there are issues\n if (isBuffer(data)) {\n // @ts-expect-error\n const typedArray = new Uint8Array(data);\n return typedArray.buffer;\n }\n\n // Careful - Node Buffers will look like ArrayBuffers (keep after isBuffer)\n if (ArrayBuffer.isView(data)) {\n return data.buffer;\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 // @ts-expect-error\n if (data && typeof data === 'object' && data._toArrayBuffer) {\n // @ts-expect-error\n return data._toArrayBuffer();\n }\n\n throw new Error(`toArrayBuffer(${JSON.stringify(data, null, 2).slice(10)})`);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"stream-utils.node.js","names":["zlib","isArrayBuffer","x","ArrayBuffer","isBuffer","Buffer","decompressReadStream","readStream","headers","get","pipe","createBrotliDecompress","createGunzip","createDeflate","concatenateReadStream","arrayBufferChunks","Promise","resolve","reject","on","error","read","chunk","Error","push","toArrayBuffer","arrayBuffer","concatenateArrayBuffers","sources","sourceArrays","map","source2","Uint8Array","byteLength","reduce","length","typedArray","result","offset","sourceArray","set","buffer","data","isView","text","uint8Array","TextEncoder","encode","_toArrayBuffer","JSON","stringify","slice"],"sources":["../../src/filesystems/stream-utils.node.ts"],"sourcesContent":["// loaders.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport zlib from 'zlib';\nimport {Readable} from 'stream';\n\nconst isArrayBuffer = (x) => x && x instanceof ArrayBuffer;\nconst isBuffer = (x) => x && x instanceof Buffer;\n\n/**\n *\n */\nexport function decompressReadStream(readStream: Readable, headers?: Headers) {\n switch (headers?.get('content-encoding')) {\n case 'br':\n return readStream.pipe(zlib.createBrotliDecompress());\n case 'gzip':\n return readStream.pipe(zlib.createGunzip());\n case 'deflate':\n return readStream.pipe(zlib.createDeflate());\n default:\n // No compression or an unknown one, just return it as is\n return readStream;\n }\n}\n\n/**\n *\n * @param readStream\n * @returns\n */\nexport async function concatenateReadStream(readStream): Promise<ArrayBuffer> {\n const arrayBufferChunks: ArrayBuffer[] = [];\n\n return await new Promise((resolve, reject) => {\n readStream.on('error', (error) => reject(error));\n\n // Once the readable callback has been added, stream switches to \"flowing mode\"\n // In Node 10 (but not 12 and 14) this causes `data` and `end` to never be called unless we read data here\n readStream.on('readable', () => readStream.read());\n\n readStream.on('data', (chunk) => {\n if (typeof chunk === 'string') {\n reject(new Error('Read stream not binary'));\n }\n arrayBufferChunks.push(toArrayBuffer(chunk));\n });\n\n readStream.on('end', () => {\n const arrayBuffer = concatenateArrayBuffers(arrayBufferChunks);\n resolve(arrayBuffer);\n });\n });\n}\n\n/**\n * Concatenate a sequence of ArrayBuffers\n * @return A concatenated ArrayBuffer\n * @note duplicates loader-utils since polyfills should be independent\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 * @param data\n * @todo Duplicate of core\n */\nexport function toArrayBuffer(data: unknown): ArrayBuffer {\n if (isArrayBuffer(data)) {\n return data as ArrayBuffer;\n }\n\n // TODO - per docs we should just be able to call buffer.buffer, but there are issues\n if (isBuffer(data)) {\n // @ts-expect-error\n const typedArray = new Uint8Array(data);\n return typedArray.buffer;\n }\n\n // Careful - Node Buffers will look like ArrayBuffers (keep after isBuffer)\n if (ArrayBuffer.isView(data)) {\n return data.buffer;\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 // @ts-expect-error\n if (data && typeof data === 'object' && data._toArrayBuffer) {\n // @ts-expect-error\n return data._toArrayBuffer();\n }\n\n throw new Error(`toArrayBuffer(${JSON.stringify(data, null, 2).slice(10)})`);\n}\n"],"mappings":"AAGA,OAAOA,IAAI,MAAM,MA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AACH,IAAI,CAAC;IACjD,OAAOC,UAAU,CAACJ,MAAM;EAC1B;EAIA,IAAIC,IAAI,IAAI,OAAOA,IAAI,KAAK,QAAQ,IAAIA,IAAI,CAACM,cAAc,EAAE;IAE3D,OAAON,IAAI,CAACM,cAAc,CAAC,CAAC;EAC9B;EAEA,MAAM,IAAIzB,KAAK,CAAE,iBAAgB0B,IAAI,CAACC,SAAS,CAACR,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAACS,KAAK,CAAC,EAAE,CAAE,GAAE,CAAC;AAC9E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-image-node.d.ts","sourceRoot":"","sources":["../../src/images/parse-image-node.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parse-image-node.d.ts","sourceRoot":"","sources":["../../src/images/parse-image-node.ts"],"names":[],"mappings":"AAKA,2EAA2E;AAC3E,eAAO,MAAM,mBAAmB,UAA2C,CAAC;AAG5E,KAAK,OAAO,GAAG;IACb,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAAC;AAEF,wBAAsB,cAAc,CAAC,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAQjG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-image-node.js","names":["getPixels","NODE_FORMAT_SUPPORT","parseImageNode","arrayBuffer","mimeType","Error","buffer","Buffer","from","ndarray","getPixelsAsync","Promise","resolve","err","shape","layers","length","shift","data","Uint8Array","width","height","components"],"sources":["../../src/images/parse-image-node.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport getPixels from 'get-pixels';\n\n/** Declares which image format mime types this loader polyfill supports */\nexport const NODE_FORMAT_SUPPORT = ['image/png', 'image/jpeg', 'image/gif'];\n\n// Note: These types are also defined in @loaders.gl/images and need to be kept in sync\ntype NDArray = {\n shape: number[];\n data: Uint8Array;\n width: number;\n height: number;\n components: number;\n layers: number[];\n};\n\nexport async function parseImageNode(arrayBuffer: ArrayBuffer, mimeType: string): Promise<NDArray> {\n if (!mimeType) {\n throw new Error('MIMEType is required to parse image under Node.js');\n }\n\n const buffer = arrayBuffer instanceof Buffer ? arrayBuffer : Buffer.from(arrayBuffer);\n const ndarray = await getPixelsAsync(buffer, mimeType);\n return ndarray;\n}\n\n// TODO - check if getPixels callback is asynchronous if provided with buffer input\n// if not, parseImage can be a sync function\nfunction getPixelsAsync(buffer: Buffer, mimeType: string): Promise<NDArray> {\n return new Promise<NDArray>((resolve) =>\n getPixels(buffer, mimeType, (err, ndarray) => {\n if (err) {\n throw err;\n }\n\n const shape = [...ndarray.shape];\n const layers = ndarray.shape.length === 4 ? ndarray.shape.shift() : 1;\n const data = ndarray.data instanceof Buffer ? new Uint8Array(ndarray.data) : ndarray.data;\n\n // extract width/height etc\n resolve({\n shape,\n data,\n width: ndarray.shape[0],\n height: ndarray.shape[1],\n components: ndarray.shape[2],\n // TODO - error\n layers: layers ? [layers] : []\n });\n })\n );\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"parse-image-node.js","names":["getPixels","NODE_FORMAT_SUPPORT","parseImageNode","arrayBuffer","mimeType","Error","buffer","Buffer","from","ndarray","getPixelsAsync","Promise","resolve","err","shape","layers","length","shift","data","Uint8Array","width","height","components"],"sources":["../../src/images/parse-image-node.ts"],"sourcesContent":["// loaders.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport getPixels from 'get-pixels';\n\n/** Declares which image format mime types this loader polyfill supports */\nexport const NODE_FORMAT_SUPPORT = ['image/png', 'image/jpeg', 'image/gif'];\n\n// Note: These types are also defined in @loaders.gl/images and need to be kept in sync\ntype NDArray = {\n shape: number[];\n data: Uint8Array;\n width: number;\n height: number;\n components: number;\n layers: number[];\n};\n\nexport async function parseImageNode(arrayBuffer: ArrayBuffer, mimeType: string): Promise<NDArray> {\n if (!mimeType) {\n throw new Error('MIMEType is required to parse image under Node.js');\n }\n\n const buffer = arrayBuffer instanceof Buffer ? arrayBuffer : Buffer.from(arrayBuffer);\n const ndarray = await getPixelsAsync(buffer, mimeType);\n return ndarray;\n}\n\n// TODO - check if getPixels callback is asynchronous if provided with buffer input\n// if not, parseImage can be a sync function\nfunction getPixelsAsync(buffer: Buffer, mimeType: string): Promise<NDArray> {\n return new Promise<NDArray>((resolve) =>\n getPixels(buffer, mimeType, (err, ndarray) => {\n if (err) {\n throw err;\n }\n\n const shape = [...ndarray.shape];\n const layers = ndarray.shape.length === 4 ? ndarray.shape.shift() : 1;\n const data = ndarray.data instanceof Buffer ? new Uint8Array(ndarray.data) : ndarray.data;\n\n // extract width/height etc\n resolve({\n shape,\n data,\n width: ndarray.shape[0],\n height: ndarray.shape[1],\n components: ndarray.shape[2],\n // TODO - error\n layers: layers ? [layers] : []\n });\n })\n );\n}\n"],"mappings":"AAGA,OAAOA,SAAS,MAAM,YAAY;AAGlC,OAAO,MAAMC,mBAAmB,GAAG,CAAC,WAAW,EAAE,YAAY,EAAE,WAAW,CAAC;AAY3E,OAAO,eAAeC,cAAcA,CAACC,WAAwB,EAAEC,QAAgB,EAAoB;EACjG,IAAI,CAACA,QAAQ,EAAE;IACb,MAAM,IAAIC,KAAK,CAAC,mDAAmD,CAAC;EACtE;EAEA,MAAMC,MAAM,GAAGH,WAAW,YAAYI,MAAM,GAAGJ,WAAW,GAAGI,MAAM,CAACC,IAAI,CAACL,WAAW,CAAC;EACrF,MAAMM,OAAO,GAAG,MAAMC,cAAc,CAACJ,MAAM,EAAEF,QAAQ,CAAC;EACtD,OAAOK,OAAO;AAChB;AAIA,SAASC,cAAcA,CAACJ,MAAc,EAAEF,QAAgB,EAAoB;EAC1E,OAAO,IAAIO,OAAO,CAAWC,OAAO,IAClCZ,SAAS,CAACM,MAAM,EAAEF,QAAQ,EAAE,CAACS,GAAG,EAAEJ,OAAO,KAAK;IAC5C,IAAII,GAAG,EAAE;MACP,MAAMA,GAAG;IACX;IAEA,MAAMC,KAAK,GAAG,CAAC,GAAGL,OAAO,CAACK,KAAK,CAAC;IAChC,MAAMC,MAAM,GAAGN,OAAO,CAACK,KAAK,CAACE,MAAM,KAAK,CAAC,GAAGP,OAAO,CAACK,KAAK,CAACG,KAAK,CAAC,CAAC,GAAG,CAAC;IACrE,MAAMC,IAAI,GAAGT,OAAO,CAACS,IAAI,YAAYX,MAAM,GAAG,IAAIY,UAAU,CAACV,OAAO,CAACS,IAAI,CAAC,GAAGT,OAAO,CAACS,IAAI;IAGzFN,OAAO,CAAC;MACNE,KAAK;MACLI,IAAI;MACJE,KAAK,EAAEX,OAAO,CAACK,KAAK,CAAC,CAAC,CAAC;MACvBO,MAAM,EAAEZ,OAAO,CAACK,KAAK,CAAC,CAAC,CAAC;MACxBQ,UAAU,EAAEb,OAAO,CAACK,KAAK,CAAC,CAAC,CAAC;MAE5BC,MAAM,EAAEA,MAAM,GAAG,CAACA,MAAM,CAAC,GAAG;IAC9B,CAAC,CAAC;EACJ,CAAC,CACH,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-image.node.d.ts","sourceRoot":"","sources":["../../src/images/parse-image.node.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parse-image.node.d.ts","sourceRoot":"","sources":["../../src/images/parse-image.node.ts"],"names":[],"mappings":"AAKA,2EAA2E;AAC3E,eAAO,MAAM,mBAAmB,UAA2C,CAAC;AAG5E,KAAK,OAAO,GAAG;IACb,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAAC;AAEF,wBAAsB,cAAc,CAAC,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAQjG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-image.node.js","names":["getPixels","NODE_FORMAT_SUPPORT","parseImageNode","arrayBuffer","mimeType","Error","buffer","Buffer","from","ndarray","getPixelsAsync","Promise","resolve","err","shape","layers","length","shift","data","Uint8Array","width","height","components"],"sources":["../../src/images/parse-image.node.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport getPixels from 'get-pixels';\n\n/** Declares which image format mime types this loader polyfill supports */\nexport const NODE_FORMAT_SUPPORT = ['image/png', 'image/jpeg', 'image/gif'];\n\n// Note: These types are also defined in @loaders.gl/images and need to be kept in sync\ntype NDArray = {\n shape: number[];\n data: Uint8Array;\n width: number;\n height: number;\n components: number;\n layers: number[];\n};\n\nexport async function parseImageNode(arrayBuffer: ArrayBuffer, mimeType: string): Promise<NDArray> {\n if (!mimeType) {\n throw new Error('MIMEType is required to parse image under Node.js');\n }\n\n const buffer = arrayBuffer instanceof Buffer ? arrayBuffer : Buffer.from(arrayBuffer);\n const ndarray = await getPixelsAsync(buffer, mimeType);\n return ndarray;\n}\n\n// TODO - check if getPixels callback is asynchronous if provided with buffer input\n// if not, parseImage can be a sync function\nfunction getPixelsAsync(buffer: Buffer, mimeType: string): Promise<NDArray> {\n return new Promise<NDArray>((resolve) =>\n getPixels(buffer, mimeType, (err, ndarray) => {\n if (err) {\n throw err;\n }\n\n const shape = [...ndarray.shape];\n const layers = ndarray.shape.length === 4 ? ndarray.shape.shift() : 1;\n const data = ndarray.data instanceof Buffer ? new Uint8Array(ndarray.data) : ndarray.data;\n\n // extract width/height etc\n resolve({\n shape,\n data,\n width: ndarray.shape[0],\n height: ndarray.shape[1],\n components: ndarray.shape[2],\n // TODO - error\n layers: layers ? [layers] : []\n });\n })\n );\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"parse-image.node.js","names":["getPixels","NODE_FORMAT_SUPPORT","parseImageNode","arrayBuffer","mimeType","Error","buffer","Buffer","from","ndarray","getPixelsAsync","Promise","resolve","err","shape","layers","length","shift","data","Uint8Array","width","height","components"],"sources":["../../src/images/parse-image.node.ts"],"sourcesContent":["// loaders.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport getPixels from 'get-pixels';\n\n/** Declares which image format mime types this loader polyfill supports */\nexport const NODE_FORMAT_SUPPORT = ['image/png', 'image/jpeg', 'image/gif'];\n\n// Note: These types are also defined in @loaders.gl/images and need to be kept in sync\ntype NDArray = {\n shape: number[];\n data: Uint8Array;\n width: number;\n height: number;\n components: number;\n layers: number[];\n};\n\nexport async function parseImageNode(arrayBuffer: ArrayBuffer, mimeType: string): Promise<NDArray> {\n if (!mimeType) {\n throw new Error('MIMEType is required to parse image under Node.js');\n }\n\n const buffer = arrayBuffer instanceof Buffer ? arrayBuffer : Buffer.from(arrayBuffer);\n const ndarray = await getPixelsAsync(buffer, mimeType);\n return ndarray;\n}\n\n// TODO - check if getPixels callback is asynchronous if provided with buffer input\n// if not, parseImage can be a sync function\nfunction getPixelsAsync(buffer: Buffer, mimeType: string): Promise<NDArray> {\n return new Promise<NDArray>((resolve) =>\n getPixels(buffer, mimeType, (err, ndarray) => {\n if (err) {\n throw err;\n }\n\n const shape = [...ndarray.shape];\n const layers = ndarray.shape.length === 4 ? ndarray.shape.shift() : 1;\n const data = ndarray.data instanceof Buffer ? new Uint8Array(ndarray.data) : ndarray.data;\n\n // extract width/height etc\n resolve({\n shape,\n data,\n width: ndarray.shape[0],\n height: ndarray.shape[1],\n components: ndarray.shape[2],\n // TODO - error\n layers: layers ? [layers] : []\n });\n })\n );\n}\n"],"mappings":"AAGA,OAAOA,SAAS,MAAM,YAAY;AAGlC,OAAO,MAAMC,mBAAmB,GAAG,CAAC,WAAW,EAAE,YAAY,EAAE,WAAW,CAAC;AAY3E,OAAO,eAAeC,cAAcA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