@loaders.gl/loader-utils 3.0.10 → 3.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es5/index.js +25 -7
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/json-loader.js +1 -1
- package/dist/es5/lib/binary-utils/array-buffer-utils.js +8 -4
- package/dist/es5/lib/binary-utils/array-buffer-utils.js.map +1 -1
- package/dist/es5/lib/binary-utils/buffer-utils.js +1 -1
- package/dist/es5/lib/binary-utils/buffer-utils.js.map +1 -1
- package/dist/es5/lib/filesystems/node-filesystem.js +267 -0
- package/dist/es5/lib/filesystems/node-filesystem.js.map +1 -0
- package/dist/es5/lib/node/{buffer-utils.node.js → buffer.js} +1 -1
- package/dist/es5/lib/node/buffer.js.map +1 -0
- package/dist/es5/lib/node/fs.js +22 -22
- package/dist/es5/lib/node/fs.js.map +1 -1
- package/dist/es5/lib/node/util.js +18 -0
- package/dist/es5/lib/node/util.js.map +1 -0
- package/dist/esm/index.js +8 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/json-loader.js +1 -1
- package/dist/esm/lib/binary-utils/array-buffer-utils.js +8 -4
- package/dist/esm/lib/binary-utils/array-buffer-utils.js.map +1 -1
- package/dist/esm/lib/binary-utils/buffer-utils.js +1 -1
- package/dist/esm/lib/binary-utils/buffer-utils.js.map +1 -1
- package/dist/esm/lib/filesystems/node-filesystem.js +60 -0
- package/dist/esm/lib/filesystems/node-filesystem.js.map +1 -0
- package/dist/esm/lib/node/{buffer-utils.node.js → buffer.js} +1 -1
- package/dist/esm/lib/node/buffer.js.map +1 -0
- package/dist/esm/lib/node/fs.js +12 -14
- package/dist/esm/lib/node/fs.js.map +1 -1
- package/dist/esm/lib/node/util.js +3 -0
- package/dist/esm/lib/node/util.js.map +1 -0
- package/dist/esm/lib/parser-utils/parse-json.js +1 -1
- package/dist/esm/lib/parser-utils/parse-json.js.map +1 -1
- package/dist/esm/lib/path-utils/file-aliases.js +1 -1
- package/dist/esm/lib/path-utils/file-aliases.js.map +1 -1
- package/dist/esm/lib/path-utils/path.js +2 -2
- package/dist/esm/lib/path-utils/path.js.map +1 -1
- package/dist/esm/lib/worker-loader-utils/create-loader-worker.js +1 -1
- package/dist/esm/lib/worker-loader-utils/create-loader-worker.js.map +1 -1
- package/dist/esm/lib/worker-loader-utils/parse-with-worker.js +1 -1
- package/dist/esm/lib/worker-loader-utils/parse-with-worker.js.map +1 -1
- package/package.json +11 -7
- package/src/index.ts +26 -8
- package/src/lib/binary-utils/array-buffer-utils.ts +8 -5
- package/src/lib/binary-utils/buffer-utils.ts +1 -1
- package/src/lib/filesystems/node-filesystem.ts +79 -0
- package/src/lib/node/{buffer-utils.node.ts → buffer.ts} +0 -0
- package/src/lib/node/fs.ts +29 -13
- package/src/lib/node/util.ts +4 -0
- package/dist/es5/lib/node/buffer-utils.node.js.map +0 -1
- package/dist/esm/lib/node/buffer-utils.node.js.map +0 -1
package/dist/es5/index.js
CHANGED
|
@@ -235,6 +235,12 @@ Object.defineProperty(exports, "_addAliases", {
|
|
|
235
235
|
return _fileAliases.addAliases;
|
|
236
236
|
}
|
|
237
237
|
});
|
|
238
|
+
Object.defineProperty(exports, "JSONLoader", {
|
|
239
|
+
enumerable: true,
|
|
240
|
+
get: function get() {
|
|
241
|
+
return _jsonLoader.JSONLoader;
|
|
242
|
+
}
|
|
243
|
+
});
|
|
238
244
|
Object.defineProperty(exports, "isBuffer", {
|
|
239
245
|
enumerable: true,
|
|
240
246
|
get: function get() {
|
|
@@ -253,13 +259,19 @@ Object.defineProperty(exports, "bufferToArrayBuffer", {
|
|
|
253
259
|
return _bufferUtils.bufferToArrayBuffer;
|
|
254
260
|
}
|
|
255
261
|
});
|
|
256
|
-
Object.defineProperty(exports, "
|
|
262
|
+
Object.defineProperty(exports, "promisify", {
|
|
257
263
|
enumerable: true,
|
|
258
264
|
get: function get() {
|
|
259
|
-
return
|
|
265
|
+
return util.promisify;
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
Object.defineProperty(exports, "_NodeFileSystem", {
|
|
269
|
+
enumerable: true,
|
|
270
|
+
get: function get() {
|
|
271
|
+
return _nodeFilesystem.default;
|
|
260
272
|
}
|
|
261
273
|
});
|
|
262
|
-
exports.fs = exports.path = void 0;
|
|
274
|
+
exports.fs = exports.util = exports.path = void 0;
|
|
263
275
|
|
|
264
276
|
var _assert = require("./lib/env-utils/assert");
|
|
265
277
|
|
|
@@ -287,19 +299,25 @@ var _asyncIteration = require("./lib/iterators/async-iteration");
|
|
|
287
299
|
|
|
288
300
|
var _requestScheduler = _interopRequireDefault(require("./lib/request-utils/request-scheduler"));
|
|
289
301
|
|
|
302
|
+
var _fileAliases = require("./lib/path-utils/file-aliases");
|
|
303
|
+
|
|
304
|
+
var _jsonLoader = require("./json-loader");
|
|
305
|
+
|
|
290
306
|
var path = _interopRequireWildcard(require("./lib/path-utils/path"));
|
|
291
307
|
|
|
292
308
|
exports.path = path;
|
|
293
309
|
|
|
294
|
-
var
|
|
310
|
+
var _bufferUtils = require("./lib/binary-utils/buffer-utils");
|
|
311
|
+
|
|
312
|
+
var util = _interopRequireWildcard(require("./lib/node/util"));
|
|
313
|
+
|
|
314
|
+
exports.util = util;
|
|
295
315
|
|
|
296
316
|
var fs = _interopRequireWildcard(require("./lib/node/fs"));
|
|
297
317
|
|
|
298
318
|
exports.fs = fs;
|
|
299
319
|
|
|
300
|
-
var
|
|
301
|
-
|
|
302
|
-
var _jsonLoader = require("./json-loader");
|
|
320
|
+
var _nodeFilesystem = _interopRequireDefault(require("./lib/filesystems/node-filesystem"));
|
|
303
321
|
|
|
304
322
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
305
323
|
|
package/dist/es5/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA;;AACA;;AAWA;;AACA;;AAGA;;AAGA;;AAOA;;AACA;;AAIA;;AAKA;;AAGA;;AAMA;;AAGA;;AAGA;;AAIA;;AAOA;;;;AAIA;;AAKA;;;;AAMA;;;;AAIA","sourcesContent":["// TYPES\nexport type {\n Loader,\n LoaderWithParser,\n LoaderContext,\n LoaderOptions,\n Writer,\n WriterOptions,\n DataType,\n SyncDataType,\n BatchableDataType,\n IFileSystem,\n IRandomAccessReadFileSystem\n} from './types';\n\n// GENERAL UTILS\nexport {assert} from './lib/env-utils/assert';\nexport {\n isBrowser,\n isWorker,\n nodeVersion,\n self,\n window,\n global,\n document\n} from './lib/env-utils/globals';\n\n// LOADERS.GL-SPECIFIC WORKER UTILS\nexport {createLoaderWorker} from './lib/worker-loader-utils/create-loader-worker';\nexport {parseWithWorker, canParseWithWorker} from './lib/worker-loader-utils/parse-with-worker';\n\n// PARSER UTILS\nexport {parseJSON} from './lib/parser-utils/parse-json';\n\n// MEMORY COPY UTILS\nexport {\n toArrayBuffer,\n sliceArrayBuffer,\n concatenateArrayBuffers,\n concatenateTypedArrays,\n compareArrayBuffers\n} from './lib/binary-utils/array-buffer-utils';\nexport {padToNBytes, copyToArray, copyArrayBuffer} from './lib/binary-utils/memory-copy-utils';\nexport {\n copyPaddedArrayBufferToDataView,\n copyPaddedStringToDataView\n} from './lib/binary-utils/binary-copy-utils';\nexport {\n padStringToByteAlignment,\n copyStringToDataView,\n copyBinaryToDataView\n} from './lib/binary-utils/encode-utils';\nexport {getFirstCharacters, getMagicString} from './lib/binary-utils/get-first-characters';\n\n// ITERATOR UTILS\nexport {\n makeTextEncoderIterator,\n makeTextDecoderIterator,\n makeLineIterator,\n makeNumberedLineIterator\n} from './lib/iterators/text-iterators';\nexport {forEach, concatenateArrayBuffersAsync} from './lib/iterators/async-iteration';\n\n// REQUEST UTILS\nexport {default as RequestScheduler} from './lib/request-utils/request-scheduler';\n\n// PATH HELPERS\nexport {setPathPrefix, getPathPrefix, resolvePath} from './lib/path-utils/file-aliases';\nexport {addAliases as _addAliases} from './lib/path-utils/file-aliases';\n\n// MICRO LOADERS\nexport {JSONLoader} from './json-loader';\n\n// NODE support\n\n// Node.js emulation (can be used in browser)\n\n// `path` replacement (avoids bundling big path polyfill)\nimport * as path from './lib/path-utils/path';\nexport {path};\n\n// Avoid direct use of `Buffer` which pulls in 50KB polyfill\nexport {isBuffer, toBuffer, bufferToArrayBuffer} from './lib/binary-utils/buffer-utils';\n\n// Note.js wrappers (can be safely imported, but not used in browser)\n\n// Use instead of importing 'util'\nimport * as util from './lib/node/util';\nexport {util};\n// TODO - remove\nexport {promisify} from './lib/node/util';\n\n// Use instead of importing 'fs';`\nimport * as fs from './lib/node/fs';\nexport {fs};\n\n// EXPERIMENTAL\nexport {default as _NodeFileSystem} from './lib/filesystems/node-filesystem';\n"],"file":"index.js"}
|
package/dist/es5/json-loader.js
CHANGED
|
@@ -11,7 +11,7 @@ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"))
|
|
|
11
11
|
|
|
12
12
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
13
|
|
|
14
|
-
var VERSION = typeof "3.0.
|
|
14
|
+
var VERSION = typeof "3.0.14" !== 'undefined' ? "3.0.14" : 'latest';
|
|
15
15
|
var JSONLoader = {
|
|
16
16
|
name: 'JSON',
|
|
17
17
|
id: 'json',
|
|
@@ -15,7 +15,7 @@ exports.sliceArrayBuffer = sliceArrayBuffer;
|
|
|
15
15
|
|
|
16
16
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
17
17
|
|
|
18
|
-
var node = _interopRequireWildcard(require("
|
|
18
|
+
var node = _interopRequireWildcard(require("./buffer-utils"));
|
|
19
19
|
|
|
20
20
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
21
21
|
|
|
@@ -28,8 +28,8 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
28
28
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
29
29
|
|
|
30
30
|
function toArrayBuffer(data) {
|
|
31
|
-
if (node.
|
|
32
|
-
data = node.
|
|
31
|
+
if (node.isBuffer(data)) {
|
|
32
|
+
data = node.bufferToArrayBuffer(data);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
if (data instanceof ArrayBuffer) {
|
|
@@ -37,7 +37,11 @@ function toArrayBuffer(data) {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
if (ArrayBuffer.isView(data)) {
|
|
40
|
-
|
|
40
|
+
if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) {
|
|
41
|
+
return data.buffer;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
if (typeof data === 'string') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/binary-utils/array-buffer-utils.ts"],"names":["toArrayBuffer","data","node","ArrayBuffer","isView","buffer","text","uint8Array","TextEncoder","encode","_toArrayBuffer","Error","compareArrayBuffers","arrayBuffer1","arrayBuffer2","
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/binary-utils/array-buffer-utils.ts"],"names":["toArrayBuffer","data","node","isBuffer","bufferToArrayBuffer","ArrayBuffer","isView","byteOffset","byteLength","buffer","slice","text","uint8Array","TextEncoder","encode","_toArrayBuffer","Error","compareArrayBuffers","arrayBuffer1","arrayBuffer2","array1","Uint8Array","array2","i","length","concatenateArrayBuffers","sources","sourceArrays","map","source2","reduce","typedArray","result","offset","sourceArray","set","concatenateTypedArrays","typedArrays","arrays","TypedArrayConstructor","constructor","sumLength","acc","value","array","sliceArrayBuffer","arrayBuffer","subArray","undefined","subarray","arrayCopy"],"mappings":";;;;;;;;;;;;;;;;;AACA;;;;;;;;;;;;AAKO,SAASA,aAAT,CAAuBC,IAAvB,EAA+C;AAEpD,MAAIC,IAAI,CAACC,QAAL,CAAcF,IAAd,CAAJ,EAAyB;AAEvBA,IAAAA,IAAI,GAAGC,IAAI,CAACE,mBAAL,CAAyBH,IAAzB,CAAP;AACD;;AAED,MAAIA,IAAI,YAAYI,WAApB,EAAiC;AAC/B,WAAOJ,IAAP;AACD;;AAGD,MAAII,WAAW,CAACC,MAAZ,CAAmBL,IAAnB,CAAJ,EAA8B;AAC5B,QAAIA,IAAI,CAACM,UAAL,KAAoB,CAApB,IAAyBN,IAAI,CAACO,UAAL,KAAoBP,IAAI,CAACQ,MAAL,CAAYD,UAA7D,EAAyE;AACvE,aAAOP,IAAI,CAACQ,MAAZ;AACD;;AACD,WAAOR,IAAI,CAACQ,MAAL,CAAYC,KAAZ,CAAkBT,IAAI,CAACM,UAAvB,EAAmCN,IAAI,CAACM,UAAL,GAAkBN,IAAI,CAAC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ACAA,IAAAA,MAAM,IAAIW,KAAK,CAACpB,MAAhB;AACD;;AACD,SAAOQ,MAAP;AACD;;AAQM,SAASa,gBAAT,CACLC,WADK,EAELvC,UAFK,EAGLC,UAHK,EAIQ;AACb,MAAMuC,QAAQ,GACZvC,UAAU,KAAKwC,SAAf,GACI,IAAI3B,UAAJ,CAAeyB,WAAf,EAA4BG,QAA5B,CAAqC1C,UAArC,EAAiDA,UAAU,GAAGC,UAA9D,CADJ,GAEI,IAAIa,UAAJ,CAAeyB,WAAf,EAA4BG,QAA5B,CAAqC1C,UAArC,CAHN;AAIA,MAAM2C,SAAS,GAAG,IAAI7B,UAAJ,CAAe0B,QAAf,CAAlB;AACA,SAAOG,SAAS,CAACzC,MAAjB;AACD","sourcesContent":["import {TypedArray} from '../../types';\nimport * as node from './buffer-utils';\n\n/**\n * Convert an object to an array buffer\n */\nexport function toArrayBuffer(data: any): ArrayBuffer {\n // Note: Should be called first, Buffers can trigger other detections below\n if (node.isBuffer(data)) {\n // TODO - per docs we should just be able to call buffer.buffer, but there are issues\n data = node.bufferToArrayBuffer(data);\n }\n\n if (data instanceof ArrayBuffer) {\n return data;\n }\n\n // Careful - Node Buffers look like Uint8Arrays (keep after isBuffer)\n if (ArrayBuffer.isView(data)) {\n if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) {\n return data.buffer;\n }\n return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);\n }\n\n if (typeof data === 'string') {\n const text = data;\n const uint8Array = new TextEncoder().encode(text);\n return uint8Array.buffer;\n }\n\n // HACK to support Blob polyfill\n if (data && typeof data === 'object' && data._toArrayBuffer) {\n return data._toArrayBuffer();\n }\n\n throw new Error('toArrayBuffer');\n}\n\n/**\n * compare two binary arrays for equality\n * @param {ArrayBuffer} a\n * @param {ArrayBuffer} b\n * @param {number} byteLength\n */\nexport function compareArrayBuffers(\n arrayBuffer1: ArrayBuffer,\n arrayBuffer2: ArrayBuffer,\n byteLength?: number\n): boolean {\n byteLength = byteLength || arrayBuffer1.byteLength;\n if (arrayBuffer1.byteLength < byteLength || arrayBuffer2.byteLength < byteLength) {\n return false;\n }\n const array1 = new Uint8Array(arrayBuffer1);\n const array2 = new Uint8Array(arrayBuffer2);\n for (let i = 0; i < array1.length; ++i) {\n if (array1[i] !== array2[i]) {\n return false;\n }\n }\n return true;\n}\n\n/**\n * Concatenate a sequence of ArrayBuffers\n * @return A concatenated ArrayBuffer\n */\nexport function concatenateArrayBuffers(...sources: (ArrayBuffer | Uint8Array)[]): ArrayBuffer {\n // Make sure all inputs are wrapped in typed arrays\n const sourceArrays = sources.map((source2) =>\n source2 instanceof ArrayBuffer ? new Uint8Array(source2) : source2\n );\n\n // Get length of all inputs\n const byteLength = sourceArrays.reduce((length, typedArray) => length + typedArray.byteLength, 0);\n\n // Allocate array with space for all inputs\n const result = new Uint8Array(byteLength);\n\n // Copy the subarrays\n let offset = 0;\n for (const sourceArray of sourceArrays) {\n result.set(sourceArray, offset);\n offset += sourceArray.byteLength;\n }\n\n // We work with ArrayBuffers, discard the typed array wrapper\n return result.buffer;\n}\n\n/**\n * Concatenate arbitrary count of typed arrays\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays\n * @param {...*} arrays - list of arrays. All arrays should be the same type\n * @return A concatenated TypedArray\n */\nexport function concatenateTypedArrays<T>(...typedArrays: T[]): T {\n // @ts-ignore\n const arrays = typedArrays as TypedArray[];\n // @ts-ignore\n const TypedArrayConstructor = (arrays && arrays.length > 1 && arrays[0].constructor) || null;\n if (!TypedArrayConstructor) {\n throw new Error(\n '\"concatenateTypedArrays\" - incorrect quantity of arguments or arguments have incompatible data types'\n );\n }\n\n const sumLength = arrays.reduce((acc, value) => acc + value.length, 0);\n // @ts-ignore typescript does not like dynamic constructors\n const result = new TypedArrayConstructor(sumLength);\n let offset = 0;\n for (const array of arrays) {\n result.set(array, offset);\n offset += array.length;\n }\n return result;\n}\n\n/**\n * Copy a view of an ArrayBuffer into new ArrayBuffer with byteOffset = 0\n * @param arrayBuffer\n * @param byteOffset\n * @param byteLength\n */\nexport function sliceArrayBuffer(\n arrayBuffer: ArrayBuffer,\n byteOffset: number,\n byteLength?: number\n): ArrayBuffer {\n const subArray =\n byteLength !== undefined\n ? new Uint8Array(arrayBuffer).subarray(byteOffset, byteOffset + byteLength)\n : new Uint8Array(arrayBuffer).subarray(byteOffset);\n const arrayCopy = new Uint8Array(subArray);\n return arrayCopy.buffer;\n}\n"],"file":"array-buffer-utils.js"}
|
|
@@ -13,7 +13,7 @@ exports.bufferToArrayBuffer = bufferToArrayBuffer;
|
|
|
13
13
|
|
|
14
14
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
15
15
|
|
|
16
|
-
var node = _interopRequireWildcard(require("../node/buffer
|
|
16
|
+
var node = _interopRequireWildcard(require("../node/buffer"));
|
|
17
17
|
|
|
18
18
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
19
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/binary-utils/buffer-utils.ts"],"names":["isBuffer","value","toBuffer","data","node","bufferToArrayBuffer","toArrayBuffer"],"mappings":";;;;;;;;;;;;;;;AAAA;;;;;;AAKO,SAASA,QAAT,CAAkBC,KAAlB,EAAuC;AAC5C,SAAOA,KAAK,IAAI,sBAAOA,KAAP,MAAiB,QAA1B,IAAsCA,KAAK,CAACD,QAAnD;AACD;;AAMM,SAASE,QAAT,CAAkBC,IAAlB,EAAqC;AAC1C,SAAOC,IAAI,CAACF,QAAL,GAAgBE,IAAI,CAACF,QAAL,CAAcC,IAAd,CAAhB,GAAsCA,IAA7C;AACD;;AAMM,SAASE,mBAAT,CAA6BF,IAA7B,EAAqD;AAC1D,MAAIC,IAAI,CAACE,aAAT,EAAwB;AAEtB,WAAOF,IAAI,CAACE,aAAL,CAAmBH,IAAnB,CAAP;AACD;;AACD,SAAOA,IAAP;AACD","sourcesContent":["import * as node from '../node/buffer
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/binary-utils/buffer-utils.ts"],"names":["isBuffer","value","toBuffer","data","node","bufferToArrayBuffer","toArrayBuffer"],"mappings":";;;;;;;;;;;;;;;AAAA;;;;;;AAKO,SAASA,QAAT,CAAkBC,KAAlB,EAAuC;AAC5C,SAAOA,KAAK,IAAI,sBAAOA,KAAP,MAAiB,QAA1B,IAAsCA,KAAK,CAACD,QAAnD;AACD;;AAMM,SAASE,QAAT,CAAkBC,IAAlB,EAAqC;AAC1C,SAAOC,IAAI,CAACF,QAAL,GAAgBE,IAAI,CAACF,QAAL,CAAcC,IAAd,CAAhB,GAAsCA,IAA7C;AACD;;AAMM,SAASE,mBAAT,CAA6BF,IAA7B,EAAqD;AAC1D,MAAIC,IAAI,CAACE,aAAT,EAAwB;AAEtB,WAAOF,IAAI,CAACE,aAAL,CAAmBH,IAAnB,CAAP;AACD;;AACD,SAAOA,IAAP;AACD","sourcesContent":["import * as node from '../node/buffer';\n\n/**\n * Check for Node.js `Buffer` (without triggering bundler to include Buffer polyfill on browser)\n */\nexport function isBuffer(value: any): boolean {\n return value && typeof value === 'object' && value.isBuffer;\n}\n\n/**\n * Converts to Node.js `Buffer` (without triggering bundler to include Buffer polyfill on browser)\n * @todo better data type\n */\nexport function toBuffer(data: any): Buffer {\n return node.toBuffer ? node.toBuffer(data) : data;\n}\n\n/**\n * Converts Node.js `Buffer` to `ArrayBuffer` (without triggering bundler to include Buffer polyfill on browser)\n * @todo better data type\n */\nexport function bufferToArrayBuffer(data: any): ArrayBuffer {\n if (node.toArrayBuffer) {\n // TODO - per docs we should just be able to call buffer.buffer, but there are issues\n return node.toArrayBuffer(data);\n }\n return data;\n}\n"],"file":"buffer-utils.js"}
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
exports.default = void 0;
|
|
11
|
+
|
|
12
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
13
|
+
|
|
14
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
15
|
+
|
|
16
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
17
|
+
|
|
18
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
19
|
+
|
|
20
|
+
var fs = _interopRequireWildcard(require("../node/fs"));
|
|
21
|
+
|
|
22
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
23
|
+
|
|
24
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
25
|
+
|
|
26
|
+
var NodeFileSystem = function () {
|
|
27
|
+
function NodeFileSystem(options) {
|
|
28
|
+
(0, _classCallCheck2.default)(this, NodeFileSystem);
|
|
29
|
+
this.fetch = options._fetch;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
(0, _createClass2.default)(NodeFileSystem, [{
|
|
33
|
+
key: "readdir",
|
|
34
|
+
value: function () {
|
|
35
|
+
var _readdir = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee() {
|
|
36
|
+
var dirname,
|
|
37
|
+
options,
|
|
38
|
+
_args = arguments;
|
|
39
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
40
|
+
while (1) {
|
|
41
|
+
switch (_context.prev = _context.next) {
|
|
42
|
+
case 0:
|
|
43
|
+
dirname = _args.length > 0 && _args[0] !== undefined ? _args[0] : '.';
|
|
44
|
+
options = _args.length > 1 ? _args[1] : undefined;
|
|
45
|
+
_context.next = 4;
|
|
46
|
+
return fs.readdir(dirname, options);
|
|
47
|
+
|
|
48
|
+
case 4:
|
|
49
|
+
return _context.abrupt("return", _context.sent);
|
|
50
|
+
|
|
51
|
+
case 5:
|
|
52
|
+
case "end":
|
|
53
|
+
return _context.stop();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}, _callee);
|
|
57
|
+
}));
|
|
58
|
+
|
|
59
|
+
function readdir() {
|
|
60
|
+
return _readdir.apply(this, arguments);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return readdir;
|
|
64
|
+
}()
|
|
65
|
+
}, {
|
|
66
|
+
key: "stat",
|
|
67
|
+
value: function () {
|
|
68
|
+
var _stat = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee2(path, options) {
|
|
69
|
+
var info;
|
|
70
|
+
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
71
|
+
while (1) {
|
|
72
|
+
switch (_context2.prev = _context2.next) {
|
|
73
|
+
case 0:
|
|
74
|
+
_context2.next = 2;
|
|
75
|
+
return fs.stat(path, options);
|
|
76
|
+
|
|
77
|
+
case 2:
|
|
78
|
+
info = _context2.sent;
|
|
79
|
+
return _context2.abrupt("return", {
|
|
80
|
+
size: Number(info.size),
|
|
81
|
+
isDirectory: function isDirectory() {
|
|
82
|
+
return false;
|
|
83
|
+
},
|
|
84
|
+
info: info
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
case 4:
|
|
88
|
+
case "end":
|
|
89
|
+
return _context2.stop();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}, _callee2);
|
|
93
|
+
}));
|
|
94
|
+
|
|
95
|
+
function stat(_x, _x2) {
|
|
96
|
+
return _stat.apply(this, arguments);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return stat;
|
|
100
|
+
}()
|
|
101
|
+
}, {
|
|
102
|
+
key: "fetch",
|
|
103
|
+
value: function () {
|
|
104
|
+
var _fetch = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee3(path, options) {
|
|
105
|
+
var fallbackFetch;
|
|
106
|
+
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
107
|
+
while (1) {
|
|
108
|
+
switch (_context3.prev = _context3.next) {
|
|
109
|
+
case 0:
|
|
110
|
+
fallbackFetch = options.fetch || this.fetch;
|
|
111
|
+
return _context3.abrupt("return", fallbackFetch(path, options));
|
|
112
|
+
|
|
113
|
+
case 2:
|
|
114
|
+
case "end":
|
|
115
|
+
return _context3.stop();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}, _callee3, this);
|
|
119
|
+
}));
|
|
120
|
+
|
|
121
|
+
function fetch(_x3, _x4) {
|
|
122
|
+
return _fetch.apply(this, arguments);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return fetch;
|
|
126
|
+
}()
|
|
127
|
+
}, {
|
|
128
|
+
key: "open",
|
|
129
|
+
value: function () {
|
|
130
|
+
var _open = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee4(path, flags, mode) {
|
|
131
|
+
return _regenerator.default.wrap(function _callee4$(_context4) {
|
|
132
|
+
while (1) {
|
|
133
|
+
switch (_context4.prev = _context4.next) {
|
|
134
|
+
case 0:
|
|
135
|
+
_context4.next = 2;
|
|
136
|
+
return fs.open(path, flags);
|
|
137
|
+
|
|
138
|
+
case 2:
|
|
139
|
+
return _context4.abrupt("return", _context4.sent);
|
|
140
|
+
|
|
141
|
+
case 3:
|
|
142
|
+
case "end":
|
|
143
|
+
return _context4.stop();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}, _callee4);
|
|
147
|
+
}));
|
|
148
|
+
|
|
149
|
+
function open(_x5, _x6, _x7) {
|
|
150
|
+
return _open.apply(this, arguments);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return open;
|
|
154
|
+
}()
|
|
155
|
+
}, {
|
|
156
|
+
key: "close",
|
|
157
|
+
value: function () {
|
|
158
|
+
var _close = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee5(fd) {
|
|
159
|
+
return _regenerator.default.wrap(function _callee5$(_context5) {
|
|
160
|
+
while (1) {
|
|
161
|
+
switch (_context5.prev = _context5.next) {
|
|
162
|
+
case 0:
|
|
163
|
+
_context5.next = 2;
|
|
164
|
+
return fs.close(fd);
|
|
165
|
+
|
|
166
|
+
case 2:
|
|
167
|
+
return _context5.abrupt("return", _context5.sent);
|
|
168
|
+
|
|
169
|
+
case 3:
|
|
170
|
+
case "end":
|
|
171
|
+
return _context5.stop();
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}, _callee5);
|
|
175
|
+
}));
|
|
176
|
+
|
|
177
|
+
function close(_x8) {
|
|
178
|
+
return _close.apply(this, arguments);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return close;
|
|
182
|
+
}()
|
|
183
|
+
}, {
|
|
184
|
+
key: "fstat",
|
|
185
|
+
value: function () {
|
|
186
|
+
var _fstat = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee6(fd) {
|
|
187
|
+
var info;
|
|
188
|
+
return _regenerator.default.wrap(function _callee6$(_context6) {
|
|
189
|
+
while (1) {
|
|
190
|
+
switch (_context6.prev = _context6.next) {
|
|
191
|
+
case 0:
|
|
192
|
+
_context6.next = 2;
|
|
193
|
+
return fs.fstat(fd);
|
|
194
|
+
|
|
195
|
+
case 2:
|
|
196
|
+
info = _context6.sent;
|
|
197
|
+
return _context6.abrupt("return", info);
|
|
198
|
+
|
|
199
|
+
case 4:
|
|
200
|
+
case "end":
|
|
201
|
+
return _context6.stop();
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}, _callee6);
|
|
205
|
+
}));
|
|
206
|
+
|
|
207
|
+
function fstat(_x9) {
|
|
208
|
+
return _fstat.apply(this, arguments);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return fstat;
|
|
212
|
+
}()
|
|
213
|
+
}, {
|
|
214
|
+
key: "read",
|
|
215
|
+
value: function () {
|
|
216
|
+
var _read = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee7(fd, _ref) {
|
|
217
|
+
var _ref$buffer, buffer, _ref$offset, offset, _ref$length, length, _ref$position, position, totalBytesRead, _yield$fs$read, bytesRead;
|
|
218
|
+
|
|
219
|
+
return _regenerator.default.wrap(function _callee7$(_context7) {
|
|
220
|
+
while (1) {
|
|
221
|
+
switch (_context7.prev = _context7.next) {
|
|
222
|
+
case 0:
|
|
223
|
+
_ref$buffer = _ref.buffer, buffer = _ref$buffer === void 0 ? null : _ref$buffer, _ref$offset = _ref.offset, offset = _ref$offset === void 0 ? 0 : _ref$offset, _ref$length = _ref.length, length = _ref$length === void 0 ? buffer.byteLength : _ref$length, _ref$position = _ref.position, position = _ref$position === void 0 ? null : _ref$position;
|
|
224
|
+
totalBytesRead = 0;
|
|
225
|
+
|
|
226
|
+
case 2:
|
|
227
|
+
if (!(totalBytesRead < length)) {
|
|
228
|
+
_context7.next = 10;
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
_context7.next = 5;
|
|
233
|
+
return fs.read(fd, buffer, offset + totalBytesRead, length - totalBytesRead, position + totalBytesRead);
|
|
234
|
+
|
|
235
|
+
case 5:
|
|
236
|
+
_yield$fs$read = _context7.sent;
|
|
237
|
+
bytesRead = _yield$fs$read.bytesRead;
|
|
238
|
+
totalBytesRead += bytesRead;
|
|
239
|
+
_context7.next = 2;
|
|
240
|
+
break;
|
|
241
|
+
|
|
242
|
+
case 10:
|
|
243
|
+
return _context7.abrupt("return", {
|
|
244
|
+
bytesRead: totalBytesRead,
|
|
245
|
+
buffer: buffer
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
case 11:
|
|
249
|
+
case "end":
|
|
250
|
+
return _context7.stop();
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}, _callee7);
|
|
254
|
+
}));
|
|
255
|
+
|
|
256
|
+
function read(_x10, _x11) {
|
|
257
|
+
return _read.apply(this, arguments);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
return read;
|
|
261
|
+
}()
|
|
262
|
+
}]);
|
|
263
|
+
return NodeFileSystem;
|
|
264
|
+
}();
|
|
265
|
+
|
|
266
|
+
exports.default = NodeFileSystem;
|
|
267
|
+
//# sourceMappingURL=node-filesystem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/filesystems/node-filesystem.ts"],"names":["NodeFileSystem","options","fetch","_fetch","dirname","fs","readdir","path","stat","info","size","Number","isDirectory","fallbackFetch","flags","mode","open","fd","close","fstat","buffer","offset","length","byteLength","position","totalBytesRead","read","bytesRead"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;;;;;;IAuBqBA,c;AAEnB,0BAAYC,OAAZ,EAA2C;AAAA;AACzC,SAAKC,KAAL,GAAaD,OAAO,CAACE,MAArB;AACD;;;;;+EAED;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAcC,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;;;;;6EAIA,kBAAYA,EAAZ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBACqBZ,EAAE,CAACc,KAAH,CAASF,EAAT,CADrB;;AAAA;AACQR,gBAAAA,IADR;AAAA,kDAESA,IAFT;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,O;;;;;;;;;;;4EAKA,kBACEQ,EADF;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA,mCAGGG,MAHH,EAGGA,MAHH,4BAGY,IAHZ,mCAGkBC,MAHlB,EAGkBA,MAHlB,4BAG2B,CAH3B,mCAG8BC,MAH9B,EAG8BA,MAH9B,4BAGuCF,MAAM,CAACG,UAH9C,qCAG0DC,QAH1D,EAG0DA,QAH1D,8BAGqE,IAHrE;AAKMC,gBAAAA,cALN,GAKuB,CALvB;;AAAA;AAAA,sBAOSA,cAAc,GAAGH,MAP1B;AAAA;AAAA;AAAA;;AAAA;AAAA,uBAQ8BjB,EAAE,CAACqB,IAAH,CACxBT,EADwB,EAExBG,MAFwB,EAGxBC,MAAM,GAAGI,cAHe,EAIxBH,MAAM,GAAGG,cAJe,EAKxBD,QAAQ,GAAGC,cALa,CAR9B;;AAAA;AAAA;AAQWE,gBAAAA,SARX,kBAQWA,SARX;AAeIF,gBAAAA,cAAc,IAAIE,SAAlB;AAfJ;AAAA;;AAAA;AAAA,kDAiBS;AAACA,kBAAAA,SAAS,EAAEF,cAAZ;AAA4BL,kBAAAA,MAAM,EAANA;AAA5B,iBAjBT;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,O","sourcesContent":["import * as fs from '../node/fs';\nimport {IFileSystem, IRandomAccessReadFileSystem} from '@loaders.gl/loader-utils';\n// import {fetchFile} from \"../fetch/fetch-file\"\n// import {selectLoader} from \"../api/select-loader\";\n\ntype Stat = {\n size: number;\n isDirectory: () => boolean;\n info?: fs.Stats;\n};\n\ntype ReadOptions = {\n buffer?: Buffer;\n offset?: number;\n length?: number;\n position?: number;\n};\n\n/**\n * FileSystem pass-through for Node.js\n * Compatible with BrowserFileSystem.\n * @param options\n */\nexport default class NodeFileSystem implements IFileSystem, IRandomAccessReadFileSystem {\n // implements IFileSystem\n constructor(options: {[key: string]: any}) {\n this.fetch = options._fetch;\n }\n\n async readdir(dirname = '.', options?: {}): Promise<any[]> {\n return await fs.readdir(dirname, options);\n }\n\n async stat(path: string, options?: {}): Promise<Stat> {\n const info = await fs.stat(path, options);\n return {size: Number(info.size), isDirectory: () => false, info};\n }\n\n async fetch(path: string, options: {[key: string]: any}) {\n // Falls back to handle https:/http:/data: etc fetches\n // eslint-disable-next-line\n const fallbackFetch = options.fetch || this.fetch;\n return fallbackFetch(path, options);\n }\n\n // implements IRandomAccessFileSystem\n async open(path: string, flags: string | number, mode?: any): Promise<number> {\n return await fs.open(path, flags);\n }\n\n async close(fd: number): Promise<void> {\n return await fs.close(fd);\n }\n\n async fstat(fd: number): Promise<Stat> {\n const info = await fs.fstat(fd);\n return info;\n }\n\n async read(\n fd: number,\n // @ts-ignore Possibly null\n {buffer = null, offset = 0, length = buffer.byteLength, position = null}: ReadOptions\n ): Promise<{bytesRead: number; buffer: Buffer}> {\n let totalBytesRead = 0;\n // Read in loop until we get required number of bytes\n while (totalBytesRead < length) {\n const {bytesRead} = await fs.read(\n fd,\n buffer,\n offset + totalBytesRead,\n length - totalBytesRead,\n position + totalBytesRead\n );\n totalBytesRead += bytesRead;\n }\n return {bytesRead: totalBytesRead, buffer};\n }\n}\n"],"file":"node-filesystem.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/node/buffer.ts"],"names":["toArrayBuffer","buffer","Buffer","isBuffer","typedArray","Uint8Array","toBuffer","binaryData","ArrayBuffer","isView","byteLength","view","i","length"],"mappings":";;;;;;;;AAGA;;AAKO,SAASA,aAAT,CAAuBC,MAAvB,EAA+B;AAEpC,MAAIC,MAAM,CAACC,QAAP,CAAgBF,MAAhB,CAAJ,EAA6B;AAC3B,QAAMG,UAAU,GAAG,IAAIC,UAAJ,CAAeJ,MAAf,CAAnB;AACA,WAAOG,UAAU,CAACH,MAAlB;AACD;;AACD,SAAOA,MAAP;AACD;;AAKM,SAASK,QAAT,CAAkBC,UAAlB,EAA8B;AACnC,MAAIC,WAAW,CAACC,MAAZ,CAAmBF,UAAnB,CAAJ,EAAoC;AAClCA,IAAAA,UAAU,GAAGA,UAAU,CAACN,MAAxB;AACD;;AAED,MAAI,OAAOC,MAAP,KAAkB,WAAlB,IAAiCK,UAAU,YAAYC,WAA3D,EAAwE;AACtE,QAAMP,MAAM,GAAG,IAAIC,MAAJ,CAAWK,UAAU,CAACG,UAAtB,CAAf;AACA,QAAMC,IAAI,GAAG,IAAIN,UAAJ,CAAeE,UAAf,CAAb;;AACA,SAAK,IAAIK,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGX,MAAM,CAACY,MAA3B,EAAmC,EAAED,CAArC,EAAwC;AACtCX,MAAAA,MAAM,CAACW,CAAD,CAAN,GAAYD,IAAI,CAACC,CAAD,CAAhB;AACD;;AACD,WAAOX,MAAP;AACD;;AAED,SAAO,oBAAO,KAAP,CAAP;AACD","sourcesContent":["// Isolates Buffer references to ensure they are only bundled under Node.js (avoids big webpack polyfill)\n// this file is not visible to webpack (it is excluded in the package.json \"browser\" field).\n\nimport {assert} from '../env-utils/assert';\n\n/**\n * Convert Buffer to ArrayBuffer\n */\nexport function toArrayBuffer(buffer) {\n // TODO - per docs we should just be able to call buffer.buffer, but there are issues\n if (Buffer.isBuffer(buffer)) {\n const typedArray = new Uint8Array(buffer);\n return typedArray.buffer;\n }\n return buffer;\n}\n\n/**\n * Convert (copy) ArrayBuffer to Buffer\n */\nexport function toBuffer(binaryData) {\n if (ArrayBuffer.isView(binaryData)) {\n binaryData = binaryData.buffer;\n }\n\n if (typeof Buffer !== 'undefined' && binaryData instanceof ArrayBuffer) {\n const buffer = new Buffer(binaryData.byteLength);\n const view = new Uint8Array(binaryData);\n for (let i = 0; i < buffer.length; ++i) {\n buffer[i] = view[i];\n }\n return buffer;\n }\n\n return assert(false);\n}\n"],"file":"buffer.js"}
|
package/dist/es5/lib/node/fs.js
CHANGED
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports._readToArrayBuffer = _readToArrayBuffer;
|
|
9
|
-
exports.
|
|
9
|
+
exports.isSupported = exports.fstat = exports.read = exports.close = exports.open = exports.writeFileSync = exports.writeFile = exports.readFileSync = exports.readFile = exports.stat = exports.readdir = void 0;
|
|
10
10
|
|
|
11
11
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
12
12
|
|
|
@@ -14,32 +14,32 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
|
|
|
14
14
|
|
|
15
15
|
var _fs = _interopRequireDefault(require("fs"));
|
|
16
16
|
|
|
17
|
-
var
|
|
17
|
+
var _buffer = require("./buffer");
|
|
18
18
|
|
|
19
|
-
var _util = require("util");
|
|
19
|
+
var _util = require("./util");
|
|
20
20
|
|
|
21
|
-
var
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
var isSupported = Boolean(_fs.default);
|
|
28
|
-
exports.isSupported = isSupported;
|
|
29
|
-
var open = _fs.default !== null && _fs.default !== void 0 && _fs.default.open ? (0, _util.promisify)(_fs.default.open) : error('fs.open');
|
|
30
|
-
exports.open = open;
|
|
31
|
-
var close = _fs.default !== null && _fs.default !== void 0 && _fs.default.close ? (0, _util.promisify)(_fs.default.close) : error('fs.close');
|
|
32
|
-
exports.close = close;
|
|
33
|
-
var read = _fs.default !== null && _fs.default !== void 0 && _fs.default.read ? (0, _util.promisify)(_fs.default.read) : error('fs.read');
|
|
34
|
-
exports.read = read;
|
|
35
|
-
var readFile = _fs.default !== null && _fs.default !== void 0 && _fs.default.readFile ? (0, _util.promisify)(_fs.default.readFile) : error('fs.readFile');
|
|
21
|
+
var readdir = (0, _util.promisify)(_fs.default.readdir);
|
|
22
|
+
exports.readdir = readdir;
|
|
23
|
+
var stat = (0, _util.promisify)(_fs.default.stat);
|
|
24
|
+
exports.stat = stat;
|
|
25
|
+
var readFile = (0, _util.promisify)(_fs.default.readFile);
|
|
36
26
|
exports.readFile = readFile;
|
|
37
|
-
var readFileSync = _fs.default
|
|
27
|
+
var readFileSync = _fs.default.readFileSync;
|
|
38
28
|
exports.readFileSync = readFileSync;
|
|
39
|
-
var writeFile =
|
|
29
|
+
var writeFile = (0, _util.promisify)(_fs.default.writeFile);
|
|
40
30
|
exports.writeFile = writeFile;
|
|
41
|
-
var writeFileSync = _fs.default
|
|
31
|
+
var writeFileSync = _fs.default.writeFileSync;
|
|
42
32
|
exports.writeFileSync = writeFileSync;
|
|
33
|
+
var open = (0, _util.promisify)(_fs.default.open);
|
|
34
|
+
exports.open = open;
|
|
35
|
+
var close = (0, _util.promisify)(_fs.default.close);
|
|
36
|
+
exports.close = close;
|
|
37
|
+
var read = (0, _util.promisify)(_fs.default.read);
|
|
38
|
+
exports.read = read;
|
|
39
|
+
var fstat = (0, _util.promisify)(_fs.default.fstat);
|
|
40
|
+
exports.fstat = fstat;
|
|
41
|
+
var isSupported = Boolean(_fs.default);
|
|
42
|
+
exports.isSupported = isSupported;
|
|
43
43
|
|
|
44
44
|
function _readToArrayBuffer(_x, _x2, _x3) {
|
|
45
45
|
return _readToArrayBuffer2.apply(this, arguments);
|
|
@@ -69,7 +69,7 @@ function _readToArrayBuffer2() {
|
|
|
69
69
|
throw new Error('fs.read failed');
|
|
70
70
|
|
|
71
71
|
case 7:
|
|
72
|
-
return _context.abrupt("return", (0,
|
|
72
|
+
return _context.abrupt("return", (0, _buffer.toArrayBuffer)(buffer));
|
|
73
73
|
|
|
74
74
|
case 8:
|
|
75
75
|
case "end":
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/node/fs.ts"],"names":["
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/node/fs.ts"],"names":["readdir","fs","stat","readFile","readFileSync","writeFile","writeFileSync","open","close","read","fstat","isSupported","Boolean","_readToArrayBuffer","fd","start","length","buffer","Buffer","alloc","bytesRead","Error"],"mappings":";;;;;;;;;;;;;;AACA;;AACA;;AACA;;AAOO,IAAMA,OAAO,GAAG,qBAAUC,YAAGD,OAAb,CAAhB;;AAEA,IAAME,IAAI,GAAG,qBAAUD,YAAGC,IAAb,CAAb;;AAGA,IAAMC,QAAQ,GAAG,qBAAUF,YAAGE,QAAb,CAAjB;;AAEA,IAAMC,YAAY,GAAGH,YAAGG,YAAxB;;AAEA,IAAMC,SAAS,GAAG,qBAAUJ,YAAGI,SAAb,CAAlB;;AAEA,IAAMC,aAAa,GAAGL,YAAGK,aAAzB;;AAKA,IAAMC,IAAI,GAAG,qBAAUN,YAAGM,IAAb,CAAb;;AAEA,IAAMC,KAAK,GAAG,qBAAUP,YAAGO,KAAb,CAAd;;AAEA,IAAMC,IAAI,GAAG,qBAAUR,YAAGQ,IAAb,CAAb;;AAEA,IAAMC,KAAK,GAAG,qBAAUT,YAAGS,KAAb,CAAd;;AAEA,IAAMC,WAAW,GAAGC,OAAO,CAACX,WAAD,CAA3B;;;SAEeY,kB;;;;;kFAAf,iBAAkCC,EAAlC,EAA8CC,KAA9C,EAA6DC,MAA7D;AAAA;;AAAA;AAAA;AAAA;AAAA;AACCC,YAAAA,MADD,GACUC,MAAM,CAACC,KAAP,CAAaH,MAAb,CADV;AAAA;AAAA,mBAEqBP,IAAI,CAACK,EAAD,EAAKG,MAAL,EAAa,CAAb,EAAgBD,MAAhB,EAAwBD,KAAxB,CAFzB;;AAAA;AAAA;AAEEK,YAAAA,SAFF,eAEEA,SAFF;;AAAA,kBAGDA,SAAS,KAAKJ,MAHb;AAAA;AAAA;AAAA;;AAAA,kBAIG,IAAIK,KAAJ,CAAU,gBAAV,CAJH;;AAAA;AAAA,6CAME,2BAAcJ,MAAd,CANF;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,G","sourcesContent":["// fs wrapper (promisified fs + avoids bundling fs in browsers)\nimport fs from 'fs';\nimport {toArrayBuffer} from './buffer';\nimport {promisify} from './util';\n\nexport type {Stats} from 'fs';\n\n// paths\n\n/** Wrapper for Node.js fs method */\nexport const readdir = promisify(fs.readdir);\n/** Wrapper for Node.js fs method */\nexport const stat = promisify(fs.stat);\n\n/** Wrapper for Node.js fs method */\nexport const readFile = promisify(fs.readFile);\n/** Wrapper for Node.js fs method */\nexport const readFileSync = fs.readFileSync;\n/** Wrapper for Node.js fs method */\nexport const writeFile = promisify(fs.writeFile);\n/** Wrapper for Node.js fs method */\nexport const writeFileSync = fs.writeFileSync;\n\n// file descriptors\n\n/** Wrapper for Node.js fs method */\nexport const open = promisify(fs.open);\n/** Wrapper for Node.js fs method */\nexport const close = promisify(fs.close);\n/** Wrapper for Node.js fs method */\nexport const read = promisify(fs.read);\n/** Wrapper for Node.js fs method */\nexport const fstat = promisify(fs.fstat);\n\nexport const isSupported = Boolean(fs);\n\nexport async function _readToArrayBuffer(fd: number, start: number, length: number) {\n const buffer = Buffer.alloc(length);\n const {bytesRead} = await read(fd, buffer, 0, length, start);\n if (bytesRead !== length) {\n throw new Error('fs.read failed');\n }\n return toArrayBuffer(buffer);\n}\n"],"file":"fs.js"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.promisify = void 0;
|
|
9
|
+
|
|
10
|
+
var util = _interopRequireWildcard(require("util"));
|
|
11
|
+
|
|
12
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
13
|
+
|
|
14
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
15
|
+
|
|
16
|
+
var promisify = util.promisify;
|
|
17
|
+
exports.promisify = promisify;
|
|
18
|
+
//# sourceMappingURL=util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/node/util.ts"],"names":["promisify","util"],"mappings":";;;;;;;;;AAAA;;;;;;AAGO,IAAMA,SAAS,GAAGC,IAAI,CAACD,SAAvB","sourcesContent":["import * as util from 'util';\n\n/** Wrapper for Node.js promisify */\nexport const promisify = util.promisify;\n"],"file":"util.js"}
|
package/dist/esm/index.js
CHANGED
|
@@ -11,12 +11,16 @@ export { getFirstCharacters, getMagicString } from './lib/binary-utils/get-first
|
|
|
11
11
|
export { makeTextEncoderIterator, makeTextDecoderIterator, makeLineIterator, makeNumberedLineIterator } from './lib/iterators/text-iterators';
|
|
12
12
|
export { forEach, concatenateArrayBuffersAsync } from './lib/iterators/async-iteration';
|
|
13
13
|
export { default as RequestScheduler } from './lib/request-utils/request-scheduler';
|
|
14
|
-
import * as path from './lib/path-utils/path';
|
|
15
|
-
export { path };
|
|
16
14
|
export { setPathPrefix, getPathPrefix, resolvePath } from './lib/path-utils/file-aliases';
|
|
17
15
|
export { addAliases as _addAliases } from './lib/path-utils/file-aliases';
|
|
16
|
+
export { JSONLoader } from './json-loader';
|
|
17
|
+
import * as path from './lib/path-utils/path';
|
|
18
|
+
export { path };
|
|
19
|
+
export { isBuffer, toBuffer, bufferToArrayBuffer } from './lib/binary-utils/buffer-utils';
|
|
20
|
+
import * as util from './lib/node/util';
|
|
21
|
+
export { util };
|
|
22
|
+
export { promisify } from './lib/node/util';
|
|
18
23
|
import * as fs from './lib/node/fs';
|
|
19
24
|
export { fs };
|
|
20
|
-
export {
|
|
21
|
-
export { JSONLoader } from './json-loader';
|
|
25
|
+
export { default as _NodeFileSystem } from './lib/filesystems/node-filesystem';
|
|
22
26
|
//# sourceMappingURL=index.js.map
|