@loaders.gl/loader-utils 3.1.3 → 4.0.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/dist/index.js +26 -111
  2. package/dist/index.js.map +1 -0
  3. package/dist/json-loader.js +18 -25
  4. package/dist/json-loader.js.map +1 -0
  5. package/dist/lib/binary-utils/array-buffer-utils.js +79 -108
  6. package/dist/lib/binary-utils/array-buffer-utils.js.map +1 -0
  7. package/dist/lib/binary-utils/binary-copy-utils.js +22 -48
  8. package/dist/lib/binary-utils/binary-copy-utils.js.map +1 -0
  9. package/dist/lib/binary-utils/buffer-utils.js +13 -47
  10. package/dist/lib/binary-utils/buffer-utils.js.map +1 -0
  11. package/dist/lib/binary-utils/encode-utils.js +26 -30
  12. package/dist/lib/binary-utils/encode-utils.js.map +1 -0
  13. package/dist/lib/binary-utils/get-first-characters.js +25 -28
  14. package/dist/lib/binary-utils/get-first-characters.js.map +1 -0
  15. package/dist/lib/binary-utils/memory-copy-utils.js +24 -58
  16. package/dist/lib/binary-utils/memory-copy-utils.js.map +1 -0
  17. package/dist/lib/env-utils/assert.js +5 -12
  18. package/dist/lib/env-utils/assert.js.map +1 -0
  19. package/dist/lib/env-utils/globals.js +9 -23
  20. package/dist/lib/env-utils/globals.js.map +1 -0
  21. package/dist/lib/filesystems/node-filesystem.js +59 -68
  22. package/dist/lib/filesystems/node-filesystem.js.map +1 -0
  23. package/dist/lib/iterators/async-iteration.js +35 -49
  24. package/dist/lib/iterators/async-iteration.js.map +1 -0
  25. package/dist/lib/iterators/text-iterators.js +41 -56
  26. package/dist/lib/iterators/text-iterators.js.map +1 -0
  27. package/dist/lib/node/buffer.js +25 -33
  28. package/dist/lib/node/buffer.js.map +1 -0
  29. package/dist/lib/node/fs.js +40 -46
  30. package/dist/lib/node/fs.js.map +1 -0
  31. package/dist/lib/node/util.js +3 -25
  32. package/dist/lib/node/util.js.map +1 -0
  33. package/dist/lib/parser-utils/parse-json.js +8 -15
  34. package/dist/lib/parser-utils/parse-json.js.map +1 -0
  35. package/dist/lib/path-utils/file-aliases.js +19 -40
  36. package/dist/lib/path-utils/file-aliases.js.map +1 -0
  37. package/dist/lib/path-utils/path.js +21 -37
  38. package/dist/lib/path-utils/path.js.map +1 -0
  39. package/dist/lib/request-utils/request-scheduler.js +131 -127
  40. package/dist/lib/request-utils/request-scheduler.js.map +1 -0
  41. package/dist/lib/worker-loader-utils/create-loader-worker.js +96 -91
  42. package/dist/lib/worker-loader-utils/create-loader-worker.js.map +1 -0
  43. package/dist/lib/worker-loader-utils/parse-with-worker.js +60 -69
  44. package/dist/lib/worker-loader-utils/parse-with-worker.js.map +1 -0
  45. package/dist/types.js +2 -3
  46. package/dist/{es5/types.js.map → types.js.map} +0 -0
  47. package/dist/workers/json-worker.js +4 -5
  48. package/dist/workers/json-worker.js.map +1 -0
  49. package/package.json +5 -5
  50. package/dist/es5/index.js +0 -325
  51. package/dist/es5/index.js.map +0 -1
  52. package/dist/es5/json-loader.js +0 -57
  53. package/dist/es5/json-loader.js.map +0 -1
  54. package/dist/es5/lib/binary-utils/array-buffer-utils.js +0 -137
  55. package/dist/es5/lib/binary-utils/array-buffer-utils.js.map +0 -1
  56. package/dist/es5/lib/binary-utils/binary-copy-utils.js +0 -35
  57. package/dist/es5/lib/binary-utils/binary-copy-utils.js.map +0 -1
  58. package/dist/es5/lib/binary-utils/buffer-utils.js +0 -38
  59. package/dist/es5/lib/binary-utils/buffer-utils.js.map +0 -1
  60. package/dist/es5/lib/binary-utils/encode-utils.js +0 -42
  61. package/dist/es5/lib/binary-utils/encode-utils.js.map +0 -1
  62. package/dist/es5/lib/binary-utils/get-first-characters.js +0 -38
  63. package/dist/es5/lib/binary-utils/get-first-characters.js.map +0 -1
  64. package/dist/es5/lib/binary-utils/memory-copy-utils.js +0 -40
  65. package/dist/es5/lib/binary-utils/memory-copy-utils.js.map +0 -1
  66. package/dist/es5/lib/env-utils/assert.js +0 -13
  67. package/dist/es5/lib/env-utils/assert.js.map +0 -1
  68. package/dist/es5/lib/env-utils/globals.js +0 -33
  69. package/dist/es5/lib/env-utils/globals.js.map +0 -1
  70. package/dist/es5/lib/filesystems/node-filesystem.js +0 -267
  71. package/dist/es5/lib/filesystems/node-filesystem.js.map +0 -1
  72. package/dist/es5/lib/iterators/async-iteration.js +0 -266
  73. package/dist/es5/lib/iterators/async-iteration.js.map +0 -1
  74. package/dist/es5/lib/iterators/text-iterators.js +0 -434
  75. package/dist/es5/lib/iterators/text-iterators.js.map +0 -1
  76. package/dist/es5/lib/node/buffer.js +0 -38
  77. package/dist/es5/lib/node/buffer.js.map +0 -1
  78. package/dist/es5/lib/node/fs.js +0 -97
  79. package/dist/es5/lib/node/fs.js.map +0 -1
  80. package/dist/es5/lib/node/util.js +0 -18
  81. package/dist/es5/lib/node/util.js.map +0 -1
  82. package/dist/es5/lib/parser-utils/parse-json.js +0 -17
  83. package/dist/es5/lib/parser-utils/parse-json.js.map +0 -1
  84. package/dist/es5/lib/path-utils/file-aliases.js +0 -39
  85. package/dist/es5/lib/path-utils/file-aliases.js.map +0 -1
  86. package/dist/es5/lib/path-utils/path.js +0 -39
  87. package/dist/es5/lib/path-utils/path.js.map +0 -1
  88. package/dist/es5/lib/request-utils/request-scheduler.js +0 -182
  89. package/dist/es5/lib/request-utils/request-scheduler.js.map +0 -1
  90. package/dist/es5/lib/worker-loader-utils/create-loader-worker.js +0 -186
  91. package/dist/es5/lib/worker-loader-utils/create-loader-worker.js.map +0 -1
  92. package/dist/es5/lib/worker-loader-utils/parse-with-worker.js +0 -137
  93. package/dist/es5/lib/worker-loader-utils/parse-with-worker.js.map +0 -1
  94. package/dist/es5/types.js +0 -2
  95. package/dist/es5/workers/json-worker.js +0 -8
  96. package/dist/es5/workers/json-worker.js.map +0 -1
  97. package/dist/esm/index.js +0 -26
  98. package/dist/esm/index.js.map +0 -1
  99. package/dist/esm/json-loader.js +0 -21
  100. package/dist/esm/json-loader.js.map +0 -1
  101. package/dist/esm/lib/binary-utils/array-buffer-utils.js +0 -86
  102. package/dist/esm/lib/binary-utils/array-buffer-utils.js.map +0 -1
  103. package/dist/esm/lib/binary-utils/binary-copy-utils.js +0 -25
  104. package/dist/esm/lib/binary-utils/binary-copy-utils.js.map +0 -1
  105. package/dist/esm/lib/binary-utils/buffer-utils.js +0 -16
  106. package/dist/esm/lib/binary-utils/buffer-utils.js.map +0 -1
  107. package/dist/esm/lib/binary-utils/encode-utils.js +0 -31
  108. package/dist/esm/lib/binary-utils/encode-utils.js.map +0 -1
  109. package/dist/esm/lib/binary-utils/get-first-characters.js +0 -27
  110. package/dist/esm/lib/binary-utils/get-first-characters.js.map +0 -1
  111. package/dist/esm/lib/binary-utils/memory-copy-utils.js +0 -27
  112. package/dist/esm/lib/binary-utils/memory-copy-utils.js.map +0 -1
  113. package/dist/esm/lib/env-utils/assert.js +0 -6
  114. package/dist/esm/lib/env-utils/assert.js.map +0 -1
  115. package/dist/esm/lib/env-utils/globals.js +0 -16
  116. package/dist/esm/lib/env-utils/globals.js.map +0 -1
  117. package/dist/esm/lib/filesystems/node-filesystem.js +0 -60
  118. package/dist/esm/lib/filesystems/node-filesystem.js.map +0 -1
  119. package/dist/esm/lib/iterators/async-iteration.js +0 -39
  120. package/dist/esm/lib/iterators/async-iteration.js.map +0 -1
  121. package/dist/esm/lib/iterators/text-iterators.js +0 -46
  122. package/dist/esm/lib/iterators/text-iterators.js.map +0 -1
  123. package/dist/esm/lib/node/buffer.js +0 -28
  124. package/dist/esm/lib/node/buffer.js.map +0 -1
  125. package/dist/esm/lib/node/fs.js +0 -42
  126. package/dist/esm/lib/node/fs.js.map +0 -1
  127. package/dist/esm/lib/node/util.js +0 -3
  128. package/dist/esm/lib/node/util.js.map +0 -1
  129. package/dist/esm/lib/parser-utils/parse-json.js +0 -9
  130. package/dist/esm/lib/parser-utils/parse-json.js.map +0 -1
  131. package/dist/esm/lib/path-utils/file-aliases.js +0 -26
  132. package/dist/esm/lib/path-utils/file-aliases.js.map +0 -1
  133. package/dist/esm/lib/path-utils/path.js +0 -24
  134. package/dist/esm/lib/path-utils/path.js.map +0 -1
  135. package/dist/esm/lib/request-utils/request-scheduler.js +0 -146
  136. package/dist/esm/lib/request-utils/request-scheduler.js.map +0 -1
  137. package/dist/esm/lib/worker-loader-utils/create-loader-worker.js +0 -102
  138. package/dist/esm/lib/worker-loader-utils/create-loader-worker.js.map +0 -1
  139. package/dist/esm/lib/worker-loader-utils/parse-with-worker.js +0 -64
  140. package/dist/esm/lib/worker-loader-utils/parse-with-worker.js.map +0 -1
  141. package/dist/esm/types.js +0 -2
  142. package/dist/esm/types.js.map +0 -1
  143. package/dist/esm/workers/json-worker.js +0 -4
  144. package/dist/esm/workers/json-worker.js.map +0 -1
@@ -1,35 +1,31 @@
1
- "use strict";
2
- // Note: These were broken out from gltf loader...
3
- // eslint-disable-next-line complexity
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.copyBinaryToDataView = exports.copyStringToDataView = exports.padStringToByteAlignment = void 0;
6
- // PERFORMANCE IDEA: No need to copy string twice...
7
- function padStringToByteAlignment(string, byteAlignment) {
8
- const length = string.length;
9
- const paddedLength = Math.ceil(length / byteAlignment) * byteAlignment; // Round up to the required alignment
10
- const padding = paddedLength - length;
11
- let whitespace = '';
12
- for (let i = 0; i < padding; ++i) {
13
- whitespace += ' ';
14
- }
15
- return string + whitespace;
1
+ export function padStringToByteAlignment(string, byteAlignment) {
2
+ const length = string.length;
3
+ const paddedLength = Math.ceil(length / byteAlignment) * byteAlignment;
4
+ const padding = paddedLength - length;
5
+ let whitespace = '';
6
+
7
+ for (let i = 0; i < padding; ++i) {
8
+ whitespace += ' ';
9
+ }
10
+
11
+ return string + whitespace;
16
12
  }
17
- exports.padStringToByteAlignment = padStringToByteAlignment;
18
- function copyStringToDataView(dataView, byteOffset, string, byteLength) {
19
- if (dataView) {
20
- for (let i = 0; i < byteLength; i++) {
21
- dataView.setUint8(byteOffset + i, string.charCodeAt(i));
22
- }
13
+ export function copyStringToDataView(dataView, byteOffset, string, byteLength) {
14
+ if (dataView) {
15
+ for (let i = 0; i < byteLength; i++) {
16
+ dataView.setUint8(byteOffset + i, string.charCodeAt(i));
23
17
  }
24
- return byteOffset + byteLength;
18
+ }
19
+
20
+ return byteOffset + byteLength;
25
21
  }
26
- exports.copyStringToDataView = copyStringToDataView;
27
- function copyBinaryToDataView(dataView, byteOffset, binary, byteLength) {
28
- if (dataView) {
29
- for (let i = 0; i < byteLength; i++) {
30
- dataView.setUint8(byteOffset + i, binary[i]);
31
- }
22
+ export function copyBinaryToDataView(dataView, byteOffset, binary, byteLength) {
23
+ if (dataView) {
24
+ for (let i = 0; i < byteLength; i++) {
25
+ dataView.setUint8(byteOffset + i, binary[i]);
32
26
  }
33
- return byteOffset + byteLength;
27
+ }
28
+
29
+ return byteOffset + byteLength;
34
30
  }
35
- exports.copyBinaryToDataView = copyBinaryToDataView;
31
+ //# sourceMappingURL=encode-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/binary-utils/encode-utils.ts"],"names":["padStringToByteAlignment","string","byteAlignment","length","paddedLength","Math","ceil","padding","whitespace","i","copyStringToDataView","dataView","byteOffset","byteLength","setUint8","charCodeAt","copyBinaryToDataView","binary"],"mappings":"AAIA,OAAO,SAASA,wBAAT,CAAkCC,MAAlC,EAA0CC,aAA1C,EAAyD;AAC9D,QAAMC,MAAM,GAAGF,MAAM,CAACE,MAAtB;AACA,QAAMC,YAAY,GAAGC,IAAI,CAACC,IAAL,CAAUH,MAAM,GAAGD,aAAnB,IAAoCA,aAAzD;AACA,QAAMK,OAAO,GAAGH,YAAY,GAAGD,MAA/B;AACA,MAAIK,UAAU,GAAG,EAAjB;;AACA,OAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGF,OAApB,EAA6B,EAAEE,CAA/B,EAAkC;AAChCD,IAAAA,UAAU,IAAI,GAAd;AACD;;AACD,SAAOP,MAAM,GAAGO,UAAhB;AACD;AAED,OAAO,SAASE,oBAAT,CAA8BC,QAA9B,EAAwCC,UAAxC,EAAoDX,MAApD,EAA4DY,UAA5D,EAAwE;AAC7E,MAAIF,QAAJ,EAAc;AACZ,SAAK,IAAIF,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGI,UAApB,EAAgCJ,CAAC,EAAjC,EAAqC;AACnCE,MAAAA,QAAQ,CAACG,QAAT,CAAkBF,UAAU,GAAGH,CAA/B,EAAkCR,MAAM,CAACc,UAAP,CAAkBN,CAAlB,CAAlC;AACD;AACF;;AACD,SAAOG,UAAU,GAAGC,UAApB;AACD;AAED,OAAO,SAASG,oBAAT,CAA8BL,QAA9B,EAAwCC,UAAxC,EAAoDK,MAApD,EAA4DJ,UAA5D,EAAwE;AAC7E,MAAIF,QAAJ,EAAc;AACZ,SAAK,IAAIF,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGI,UAApB,EAAgCJ,CAAC,EAAjC,EAAqC;AACnCE,MAAAA,QAAQ,CAACG,QAAT,CAAkBF,UAAU,GAAGH,CAA/B,EAAkCQ,MAAM,CAACR,CAAD,CAAxC;AACD;AACF;;AACD,SAAOG,UAAU,GAAGC,UAApB;AACD","sourcesContent":["// Note: These were broken out from gltf loader...\n// eslint-disable-next-line complexity\n\n// PERFORMANCE IDEA: No need to copy string twice...\nexport function padStringToByteAlignment(string, byteAlignment) {\n const length = string.length;\n const paddedLength = Math.ceil(length / byteAlignment) * byteAlignment; // Round up to the required alignment\n const padding = paddedLength - length;\n let whitespace = '';\n for (let i = 0; i < padding; ++i) {\n whitespace += ' ';\n }\n return string + whitespace;\n}\n\nexport function copyStringToDataView(dataView, byteOffset, string, byteLength) {\n if (dataView) {\n for (let i = 0; i < byteLength; i++) {\n dataView.setUint8(byteOffset + i, string.charCodeAt(i));\n }\n }\n return byteOffset + byteLength;\n}\n\nexport function copyBinaryToDataView(dataView, byteOffset, binary, byteLength) {\n if (dataView) {\n for (let i = 0; i < byteLength; i++) {\n dataView.setUint8(byteOffset + i, binary[i]);\n }\n }\n return byteOffset + byteLength;\n}\n"],"file":"encode-utils.js"}
@@ -1,30 +1,27 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getMagicString = exports.getFirstCharacters = void 0;
4
- function getFirstCharacters(data, length = 5) {
5
- if (typeof data === 'string') {
6
- return data.slice(0, length);
7
- }
8
- else if (ArrayBuffer.isView(data)) {
9
- // Typed Arrays can have offsets into underlying buffer
10
- return getMagicString(data.buffer, data.byteOffset, length);
11
- }
12
- else if (data instanceof ArrayBuffer) {
13
- const byteOffset = 0;
14
- return getMagicString(data, byteOffset, length);
15
- }
16
- return '';
1
+ export function getFirstCharacters(data, length = 5) {
2
+ if (typeof data === 'string') {
3
+ return data.slice(0, length);
4
+ } else if (ArrayBuffer.isView(data)) {
5
+ return getMagicString(data.buffer, data.byteOffset, length);
6
+ } else if (data instanceof ArrayBuffer) {
7
+ const byteOffset = 0;
8
+ return getMagicString(data, byteOffset, length);
9
+ }
10
+
11
+ return '';
17
12
  }
18
- exports.getFirstCharacters = getFirstCharacters;
19
- function getMagicString(arrayBuffer, byteOffset, length) {
20
- if (arrayBuffer.byteLength <= byteOffset + length) {
21
- return '';
22
- }
23
- const dataView = new DataView(arrayBuffer);
24
- let magic = '';
25
- for (let i = 0; i < length; i++) {
26
- magic += String.fromCharCode(dataView.getUint8(byteOffset + i));
27
- }
28
- return magic;
13
+ export function getMagicString(arrayBuffer, byteOffset, length) {
14
+ if (arrayBuffer.byteLength <= byteOffset + length) {
15
+ return '';
16
+ }
17
+
18
+ const dataView = new DataView(arrayBuffer);
19
+ let magic = '';
20
+
21
+ for (let i = 0; i < length; i++) {
22
+ magic += String.fromCharCode(dataView.getUint8(byteOffset + i));
23
+ }
24
+
25
+ return magic;
29
26
  }
30
- exports.getMagicString = getMagicString;
27
+ //# sourceMappingURL=get-first-characters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/binary-utils/get-first-characters.ts"],"names":["getFirstCharacters","data","length","slice","ArrayBuffer","isView","getMagicString","buffer","byteOffset","arrayBuffer","byteLength","dataView","DataView","magic","i","String","fromCharCode","getUint8"],"mappings":"AAAA,OAAO,SAASA,kBAAT,CAA4BC,IAA5B,EAAkCC,MAAM,GAAG,CAA3C,EAAsD;AAC3D,MAAI,OAAOD,IAAP,KAAgB,QAApB,EAA8B;AAC5B,WAAOA,IAAI,CAACE,KAAL,CAAW,CAAX,EAAcD,MAAd,CAAP;AACD,GAFD,MAEO,IAAIE,WAAW,CAACC,MAAZ,CAAmBJ,IAAnB,CAAJ,EAA8B;AAEnC,WAAOK,cAAc,CAACL,IAAI,CAACM,MAAN,EAAcN,IAAI,CAACO,UAAnB,EAA+BN,MAA/B,CAArB;AACD,GAHM,MAGA,IAAID,IAAI,YAAYG,WAApB,EAAiC;AACtC,UAAMI,UAAU,GAAG,CAAnB;AACA,WAAOF,cAAc,CAACL,IAAD,EAAOO,UAAP,EAAmBN,MAAnB,CAArB;AACD;;AACD,SAAO,EAAP;AACD;AAED,OAAO,SAASI,cAAT,CACLG,WADK,EAELD,UAFK,EAGLN,MAHK,EAIG;AACR,MAAIO,WAAW,CAACC,UAAZ,IAA0BF,UAAU,GAAGN,MAA3C,EAAmD;AACjD,WAAO,EAAP;AACD;;AACD,QAAMS,QAAQ,GAAG,IAAIC,QAAJ,CAAaH,WAAb,CAAjB;AACA,MAAII,KAAK,GAAG,EAAZ;;AACA,OAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGZ,MAApB,EAA4BY,CAAC,EAA7B,EAAiC;AAC/BD,IAAAA,KAAK,IAAIE,MAAM,CAACC,YAAP,CAAoBL,QAAQ,CAACM,QAAT,CAAkBT,UAAU,GAAGM,CAA/B,CAApB,CAAT;AACD;;AACD,SAAOD,KAAP;AACD","sourcesContent":["export function getFirstCharacters(data, length = 5): string {\n if (typeof data === 'string') {\n return data.slice(0, length);\n } else if (ArrayBuffer.isView(data)) {\n // Typed Arrays can have offsets into underlying buffer\n return getMagicString(data.buffer, data.byteOffset, length);\n } else if (data instanceof ArrayBuffer) {\n const byteOffset = 0;\n return getMagicString(data, byteOffset, length);\n }\n return '';\n}\n\nexport function getMagicString(\n arrayBuffer: ArrayBuffer,\n byteOffset: number,\n length: number\n): string {\n if (arrayBuffer.byteLength <= byteOffset + length) {\n return '';\n }\n const dataView = new DataView(arrayBuffer);\n let magic = '';\n for (let i = 0; i < length; i++) {\n magic += String.fromCharCode(dataView.getUint8(byteOffset + i));\n }\n return magic;\n}\n"],"file":"get-first-characters.js"}
@@ -1,61 +1,27 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.copyToArray = exports.copyArrayBuffer = exports.padToNBytes = void 0;
4
- const assert_1 = require("../env-utils/assert");
5
- /**
6
- * Calculate new size of an arrayBuffer to be aligned to an n-byte boundary
7
- * This function increases `byteLength` by the minimum delta,
8
- * allowing the total length to be divided by `padding`
9
- * @param byteLength
10
- * @param padding
11
- */
12
- function padToNBytes(byteLength, padding) {
13
- (0, assert_1.assert)(byteLength >= 0); // `Incorrect 'byteLength' value: ${byteLength}`
14
- (0, assert_1.assert)(padding > 0); // `Incorrect 'padding' value: ${padding}`
15
- return (byteLength + (padding - 1)) & ~(padding - 1);
1
+ import { assert } from '../env-utils/assert';
2
+ export function padToNBytes(byteLength, padding) {
3
+ assert(byteLength >= 0);
4
+ assert(padding > 0);
5
+ return byteLength + (padding - 1) & ~(padding - 1);
16
6
  }
17
- exports.padToNBytes = padToNBytes;
18
- /**
19
- * Creates a new Uint8Array based on two different ArrayBuffers
20
- * @param targetBuffer The first buffer.
21
- * @param sourceBuffer The second buffer.
22
- * @return The new ArrayBuffer created out of the two.
23
- */
24
- function copyArrayBuffer(targetBuffer, sourceBuffer, byteOffset, byteLength = sourceBuffer.byteLength) {
25
- const targetArray = new Uint8Array(targetBuffer, byteOffset, byteLength);
26
- const sourceArray = new Uint8Array(sourceBuffer);
27
- targetArray.set(sourceArray);
28
- return targetBuffer;
7
+ export function copyArrayBuffer(targetBuffer, sourceBuffer, byteOffset, byteLength = sourceBuffer.byteLength) {
8
+ const targetArray = new Uint8Array(targetBuffer, byteOffset, byteLength);
9
+ const sourceArray = new Uint8Array(sourceBuffer);
10
+ targetArray.set(sourceArray);
11
+ return targetBuffer;
29
12
  }
30
- exports.copyArrayBuffer = copyArrayBuffer;
31
- /**
32
- * Copy from source to target at the targetOffset
33
- *
34
- * @param source - The data to copy
35
- * @param target - The destination to copy data into
36
- * @param targetOffset - The start offset into target to place the copied data
37
- * @returns the new offset taking into account proper padding
38
- */
39
- function copyToArray(source, target, targetOffset) {
40
- let sourceArray;
41
- if (source instanceof ArrayBuffer) {
42
- sourceArray = new Uint8Array(source);
43
- }
44
- else {
45
- // Pack buffer onto the big target array
46
- //
47
- // 'source.data.buffer' could be a view onto a larger buffer.
48
- // We MUST use this constructor to ensure the byteOffset and byteLength is
49
- // set to correct values from 'source.data' and not the underlying
50
- // buffer for target.set() to work properly.
51
- const srcByteOffset = source.byteOffset;
52
- const srcByteLength = source.byteLength;
53
- // In gltf parser it is set as "arrayBuffer" instead of "buffer"
54
- // https://github.com/visgl/loaders.gl/blob/1e3a82a0a65d7b6a67b1e60633453e5edda2960a/modules/gltf/src/lib/parse-gltf.js#L85
55
- sourceArray = new Uint8Array(source.buffer || source.arrayBuffer, srcByteOffset, srcByteLength);
56
- }
57
- // Pack buffer onto the big target array
58
- target.set(sourceArray, targetOffset);
59
- return targetOffset + padToNBytes(sourceArray.byteLength, 4);
13
+ export function copyToArray(source, target, targetOffset) {
14
+ let sourceArray;
15
+
16
+ if (source instanceof ArrayBuffer) {
17
+ sourceArray = new Uint8Array(source);
18
+ } else {
19
+ const srcByteOffset = source.byteOffset;
20
+ const srcByteLength = source.byteLength;
21
+ sourceArray = new Uint8Array(source.buffer || source.arrayBuffer, srcByteOffset, srcByteLength);
22
+ }
23
+
24
+ target.set(sourceArray, targetOffset);
25
+ return targetOffset + padToNBytes(sourceArray.byteLength, 4);
60
26
  }
61
- exports.copyToArray = copyToArray;
27
+ //# sourceMappingURL=memory-copy-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/binary-utils/memory-copy-utils.ts"],"names":["assert","padToNBytes","byteLength","padding","copyArrayBuffer","targetBuffer","sourceBuffer","byteOffset","targetArray","Uint8Array","sourceArray","set","copyToArray","source","target","targetOffset","ArrayBuffer","srcByteOffset","srcByteLength","buffer","arrayBuffer"],"mappings":"AAAA,SAAQA,MAAR,QAAqB,qBAArB;AASA,OAAO,SAASC,WAAT,CAAqBC,UAArB,EAAyCC,OAAzC,EAAkE;AACvEH,EAAAA,MAAM,CAACE,UAAU,IAAI,CAAf,CAAN;AACAF,EAAAA,MAAM,CAACG,OAAO,GAAG,CAAX,CAAN;AACA,SAAQD,UAAU,IAAIC,OAAO,GAAG,CAAd,CAAX,GAA+B,EAAEA,OAAO,GAAG,CAAZ,CAAtC;AACD;AAQD,OAAO,SAASC,eAAT,CACLC,YADK,EAELC,YAFK,EAGLC,UAHK,EAILL,UAAkB,GAAGI,YAAY,CAACJ,UAJ7B,EAKQ;AACb,QAAMM,WAAW,GAAG,IAAIC,UAAJ,CAAeJ,YAAf,EAA6BE,UAA7B,EAAyCL,UAAzC,CAApB;AACA,QAAMQ,WAAW,GAAG,IAAID,UAAJ,CAAeH,YAAf,CAApB;AACAE,EAAAA,WAAW,CAACG,GAAZ,CAAgBD,WAAhB;AACA,SAAOL,YAAP;AACD;AAUD,OAAO,SAASO,WAAT,CAAqBC,MAArB,EAAgDC,MAAhD,EAA6DC,YAA7D,EAA2F;AAChG,MAAIL,WAAJ;;AAEA,MAAIG,MAAM,YAAYG,WAAtB,EAAmC;AACjCN,IAAAA,WAAW,GAAG,IAAID,UAAJ,CAAeI,MAAf,CAAd;AACD,GAFD,MAEO;AAOL,UAAMI,aAAa,GAAGJ,MAAM,CAACN,UAA7B;AACA,UAAMW,aAAa,GAAGL,MAAM,CAACX,UAA7B;AAGAQ,IAAAA,WAAW,GAAG,IAAID,UAAJ,CAAeI,MAAM,CAACM,MAAP,IAAiBN,MAAM,CAACO,WAAvC,EAAoDH,aAApD,EAAmEC,aAAnE,CAAd;AACD;;AAGDJ,EAAAA,MAAM,CAACH,GAAP,CAAWD,WAAX,EAAwBK,YAAxB;AAEA,SAAOA,YAAY,GAAGd,WAAW,CAACS,WAAW,CAACR,UAAb,EAAyB,CAAzB,CAAjC;AACD","sourcesContent":["import {assert} from '../env-utils/assert';\n\n/**\n * Calculate new size of an arrayBuffer to be aligned to an n-byte boundary\n * This function increases `byteLength` by the minimum delta,\n * allowing the total length to be divided by `padding`\n * @param byteLength\n * @param padding\n */\nexport function padToNBytes(byteLength: number, padding: number): number {\n assert(byteLength >= 0); // `Incorrect 'byteLength' value: ${byteLength}`\n assert(padding > 0); // `Incorrect 'padding' value: ${padding}`\n return (byteLength + (padding - 1)) & ~(padding - 1);\n}\n\n/**\n * Creates a new Uint8Array based on two different ArrayBuffers\n * @param targetBuffer The first buffer.\n * @param sourceBuffer The second buffer.\n * @return The new ArrayBuffer created out of the two.\n */\nexport function copyArrayBuffer(\n targetBuffer: ArrayBuffer,\n sourceBuffer: ArrayBuffer,\n byteOffset: number,\n byteLength: number = sourceBuffer.byteLength\n): ArrayBuffer {\n const targetArray = new Uint8Array(targetBuffer, byteOffset, byteLength);\n const sourceArray = new Uint8Array(sourceBuffer);\n targetArray.set(sourceArray);\n return targetBuffer;\n}\n\n/**\n * Copy from source to target at the targetOffset\n *\n * @param source - The data to copy\n * @param target - The destination to copy data into\n * @param targetOffset - The start offset into target to place the copied data\n * @returns the new offset taking into account proper padding\n */\nexport function copyToArray(source: ArrayBuffer | any, target: any, targetOffset: number): number {\n let sourceArray;\n\n if (source instanceof ArrayBuffer) {\n sourceArray = new Uint8Array(source);\n } else {\n // Pack buffer onto the big target array\n //\n // 'source.data.buffer' could be a view onto a larger buffer.\n // We MUST use this constructor to ensure the byteOffset and byteLength is\n // set to correct values from 'source.data' and not the underlying\n // buffer for target.set() to work properly.\n const srcByteOffset = source.byteOffset;\n const srcByteLength = source.byteLength;\n // In gltf parser it is set as \"arrayBuffer\" instead of \"buffer\"\n // https://github.com/visgl/loaders.gl/blob/1e3a82a0a65d7b6a67b1e60633453e5edda2960a/modules/gltf/src/lib/parse-gltf.js#L85\n sourceArray = new Uint8Array(source.buffer || source.arrayBuffer, srcByteOffset, srcByteLength);\n }\n\n // Pack buffer onto the big target array\n target.set(sourceArray, targetOffset);\n\n return targetOffset + padToNBytes(sourceArray.byteLength, 4);\n}\n"],"file":"memory-copy-utils.js"}
@@ -1,13 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.assert = void 0;
4
- /**
5
- * Throws an `Error` with the optional `message` if `condition` is falsy
6
- * @note Replacement for the external assert method to reduce bundle size
7
- */
8
- function assert(condition, message) {
9
- if (!condition) {
10
- throw new Error(message || 'loader assertion failed.');
11
- }
1
+ export function assert(condition, message) {
2
+ if (!condition) {
3
+ throw new Error(message || 'loader assertion failed.');
4
+ }
12
5
  }
13
- exports.assert = assert;
6
+ //# sourceMappingURL=assert.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/env-utils/assert.ts"],"names":["assert","condition","message","Error"],"mappings":"AAIA,OAAO,SAASA,MAAT,CAAgBC,SAAhB,EAAgCC,OAAhC,EAAwD;AAC7D,MAAI,CAACD,SAAL,EAAgB;AACd,UAAM,IAAIE,KAAJ,CAAUD,OAAO,IAAI,0BAArB,CAAN;AACD;AACF","sourcesContent":["/**\n * Throws an `Error` with the optional `message` if `condition` is falsy\n * @note Replacement for the external assert method to reduce bundle size\n */\nexport function assert(condition: any, message?: string): void {\n if (!condition) {\n throw new Error(message || 'loader assertion failed.');\n }\n}\n"],"file":"assert.js"}
@@ -1,30 +1,16 @@
1
- "use strict";
2
- // Purpose: include this in your module to avoid
3
- // dependencies on micro modules like 'global' and 'is-browser';
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.nodeVersion = exports.isWorker = exports.isBrowser = exports.document = exports.global = exports.window = exports.self = void 0;
6
- /* eslint-disable no-restricted-globals */
7
1
  const globals = {
8
- self: typeof self !== 'undefined' && self,
9
- window: typeof window !== 'undefined' && window,
10
- global: typeof global !== 'undefined' && global,
11
- document: typeof document !== 'undefined' && document
2
+ self: typeof self !== 'undefined' && self,
3
+ window: typeof window !== 'undefined' && window,
4
+ global: typeof global !== 'undefined' && global,
5
+ document: typeof document !== 'undefined' && document
12
6
  };
13
7
  const self_ = globals.self || globals.window || globals.global || {};
14
- exports.self = self_;
15
8
  const window_ = globals.window || globals.self || globals.global || {};
16
- exports.window = window_;
17
9
  const global_ = globals.global || globals.self || globals.window || {};
18
- exports.global = global_;
19
10
  const document_ = globals.document || {};
20
- exports.document = document_;
21
- /** true if running in a browser */
22
- exports.isBrowser =
23
- // @ts-ignore process does not exist on browser
24
- Boolean(typeof process !== 'object' || String(process) !== '[object process]' || process.browser);
25
- /** true if running in a worker thread */
26
- exports.isWorker = typeof importScripts === 'function';
27
- // Extract node major version
11
+ export { self_ as self, window_ as window, global_ as global, document_ as document };
12
+ export const isBrowser = Boolean(typeof process !== 'object' || String(process) !== '[object process]' || process.browser);
13
+ export const isWorker = typeof importScripts === 'function';
28
14
  const matches = typeof process !== 'undefined' && process.version && /v([0-9]*)/.exec(process.version);
29
- /** Major Node version (as a number) */
30
- exports.nodeVersion = (matches && parseFloat(matches[1])) || 0;
15
+ export const nodeVersion = matches && parseFloat(matches[1]) || 0;
16
+ //# sourceMappingURL=globals.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/env-utils/globals.ts"],"names":["globals","self","window","global","document","self_","window_","global_","document_","isBrowser","Boolean","process","String","browser","isWorker","importScripts","matches","version","exec","nodeVersion","parseFloat"],"mappings":"AAIA,MAAMA,OAAO,GAAG;AACdC,EAAAA,IAAI,EAAE,OAAOA,IAAP,KAAgB,WAAhB,IAA+BA,IADvB;AAEdC,EAAAA,MAAM,EAAE,OAAOA,MAAP,KAAkB,WAAlB,IAAiCA,MAF3B;AAGdC,EAAAA,MAAM,EAAE,OAAOA,MAAP,KAAkB,WAAlB,IAAiCA,MAH3B;AAIdC,EAAAA,QAAQ,EAAE,OAAOA,QAAP,KAAoB,WAApB,IAAmCA;AAJ/B,CAAhB;AAQA,MAAMC,KAAU,GAAGL,OAAO,CAACC,IAAR,IAAgBD,OAAO,CAACE,MAAxB,IAAkCF,OAAO,CAACG,MAA1C,IAAoD,EAAvE;AACA,MAAMG,OAAY,GAAGN,OAAO,CAACE,MAAR,IAAkBF,OAAO,CAACC,IAA1B,IAAkCD,OAAO,CAACG,MAA1C,IAAoD,EAAzE;AACA,MAAMI,OAAY,GAAGP,OAAO,CAACG,MAAR,IAAkBH,OAAO,CAACC,IAA1B,IAAkCD,OAAO,CAACE,MAA1C,IAAoD,EAAzE;AACA,MAAMM,SAAc,GAAGR,OAAO,CAACI,QAAR,IAAoB,EAA3C;AAEA,SAAQC,KAAK,IAAIJ,IAAjB,EAAuBK,OAAO,IAAIJ,MAAlC,EAA0CK,OAAO,IAAIJ,MAArD,EAA6DK,SAAS,IAAIJ,QAA1E;AAGA,OAAO,MAAMK,SAAkB,GAE7BC,OAAO,CAAC,OAAOC,OAAP,KAAmB,QAAnB,IAA+BC,MAAM,CAACD,OAAD,CAAN,KAAoB,kBAAnD,IAAyEA,OAAO,CAACE,OAAlF,CAFF;AAKP,OAAO,MAAMC,QAAiB,GAAG,OAAOC,aAAP,KAAyB,UAAnD;AAGP,MAAMC,OAAO,GACX,OAAOL,OAAP,KAAmB,WAAnB,IAAkCA,OAAO,CAACM,OAA1C,IAAqD,YAAYC,IAAZ,CAAiBP,OAAO,CAACM,OAAzB,CADvD;AAGA,OAAO,MAAME,WAAmB,GAAIH,OAAO,IAAII,UAAU,CAACJ,OAAO,CAAC,CAAD,CAAR,CAAtB,IAAuC,CAAnE","sourcesContent":["// Purpose: include this in your module to avoid\n// dependencies on micro modules like 'global' and 'is-browser';\n\n/* eslint-disable no-restricted-globals */\nconst globals = {\n self: typeof self !== 'undefined' && self,\n window: typeof window !== 'undefined' && window,\n global: typeof global !== 'undefined' && global,\n document: typeof document !== 'undefined' && document\n};\n\ntype obj = {[key: string]: any};\nconst self_: obj = globals.self || globals.window || globals.global || {};\nconst window_: obj = globals.window || globals.self || globals.global || {};\nconst global_: obj = globals.global || globals.self || globals.window || {};\nconst document_: obj = globals.document || {};\n\nexport {self_ as self, window_ as window, global_ as global, document_ as document};\n\n/** true if running in a browser */\nexport const isBrowser: boolean =\n // @ts-ignore process does not exist on browser\n Boolean(typeof process !== 'object' || String(process) !== '[object process]' || process.browser);\n\n/** true if running in a worker thread */\nexport const isWorker: boolean = typeof importScripts === 'function';\n\n// Extract node major version\nconst matches =\n typeof process !== 'undefined' && process.version && /v([0-9]*)/.exec(process.version);\n/** Major Node version (as a number) */\nexport const nodeVersion: number = (matches && parseFloat(matches[1])) || 0;\n"],"file":"globals.js"}
@@ -1,69 +1,60 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- Object.defineProperty(exports, "__esModule", { value: true });
22
- const fs = __importStar(require("../node/fs"));
23
- /**
24
- * FileSystem pass-through for Node.js
25
- * Compatible with BrowserFileSystem.
26
- * @param options
27
- */
28
- class NodeFileSystem {
29
- // implements IFileSystem
30
- constructor(options) {
31
- this.fetch = options._fetch;
32
- }
33
- async readdir(dirname = '.', options) {
34
- return await fs.readdir(dirname, options);
35
- }
36
- async stat(path, options) {
37
- const info = await fs.stat(path, options);
38
- return { size: Number(info.size), isDirectory: () => false, info };
39
- }
40
- async fetch(path, options) {
41
- // Falls back to handle https:/http:/data: etc fetches
42
- // eslint-disable-next-line
43
- const fallbackFetch = options.fetch || this.fetch;
44
- return fallbackFetch(path, options);
45
- }
46
- // implements IRandomAccessFileSystem
47
- async open(path, flags, mode) {
48
- return await fs.open(path, flags);
49
- }
50
- async close(fd) {
51
- return await fs.close(fd);
52
- }
53
- async fstat(fd) {
54
- const info = await fs.fstat(fd);
55
- return info;
56
- }
57
- async read(fd,
58
- // @ts-ignore Possibly null
59
- { buffer = null, offset = 0, length = buffer.byteLength, position = null }) {
60
- let totalBytesRead = 0;
61
- // Read in loop until we get required number of bytes
62
- while (totalBytesRead < length) {
63
- const { bytesRead } = await fs.read(fd, buffer, offset + totalBytesRead, length - totalBytesRead, position + totalBytesRead);
64
- totalBytesRead += bytesRead;
65
- }
66
- return { bytesRead: totalBytesRead, buffer };
67
- }
1
+ import * as fs from '../node/fs';
2
+ export default class NodeFileSystem {
3
+ constructor(options) {
4
+ this.fetch = options._fetch;
5
+ }
6
+
7
+ async readdir(dirname = '.', options) {
8
+ return await fs.readdir(dirname, options);
9
+ }
10
+
11
+ async stat(path, options) {
12
+ const info = await fs.stat(path, options);
13
+ return {
14
+ size: Number(info.size),
15
+ isDirectory: () => false,
16
+ info
17
+ };
18
+ }
19
+
20
+ async fetch(path, options) {
21
+ const fallbackFetch = options.fetch || this.fetch;
22
+ return fallbackFetch(path, options);
23
+ }
24
+
25
+ async open(path, flags, mode) {
26
+ return await fs.open(path, flags);
27
+ }
28
+
29
+ async close(fd) {
30
+ return await fs.close(fd);
31
+ }
32
+
33
+ async fstat(fd) {
34
+ const info = await fs.fstat(fd);
35
+ return info;
36
+ }
37
+
38
+ async read(fd, {
39
+ buffer = null,
40
+ offset = 0,
41
+ length = buffer.byteLength,
42
+ position = null
43
+ }) {
44
+ let totalBytesRead = 0;
45
+
46
+ while (totalBytesRead < length) {
47
+ const {
48
+ bytesRead
49
+ } = await fs.read(fd, buffer, offset + totalBytesRead, length - totalBytesRead, position + totalBytesRead);
50
+ totalBytesRead += bytesRead;
51
+ }
52
+
53
+ return {
54
+ bytesRead: totalBytesRead,
55
+ buffer
56
+ };
57
+ }
58
+
68
59
  }
69
- exports.default = NodeFileSystem;
60
+ //# sourceMappingURL=node-filesystem.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/filesystems/node-filesystem.ts"],"names":["fs","NodeFileSystem","constructor","options","fetch","_fetch","readdir","dirname","stat","path","info","size","Number","isDirectory","fallbackFetch","open","flags","mode","close","fd","fstat","read","buffer","offset","length","byteLength","position","totalBytesRead","bytesRead"],"mappings":"AAAA,OAAO,KAAKA,EAAZ,MAAoB,YAApB;AAuBA,eAAe,MAAMC,cAAN,CAAyE;AAEtFC,EAAAA,WAAW,CAACC,OAAD,EAAgC;AACzC,SAAKC,KAAL,GAAaD,OAAO,CAACE,MAArB;AACD;;AAEY,QAAPC,OAAO,CAACC,OAAO,GAAG,GAAX,EAAgBJ,OAAhB,EAA8C;AACzD,WAAO,MAAMH,EAAE,CAACM,OAAH,CAAWC,OAAX,EAAoBJ,OAApB,CAAb;AACD;;AAES,QAAJK,IAAI,CAACC,IAAD,EAAeN,OAAf,EAA4C;AACpD,UAAMO,IAAI,GAAG,MAAMV,EAAE,CAACQ,IAAH,CAAQC,IAAR,EAAcN,OAAd,CAAnB;AACA,WAAO;AAACQ,MAAAA,IAAI,EAAEC,MAAM,CAACF,IAAI,CAACC,IAAN,CAAb;AAA0BE,MAAAA,WAAW,EAAE,MAAM,KAA7C;AAAoDH,MAAAA;AAApD,KAAP;AACD;;AAEU,QAALN,KAAK,CAACK,IAAD,EAAeN,OAAf,EAA8C;AAGvD,UAAMW,aAAa,GAAGX,OAAO,CAACC,KAAR,IAAiB,KAAKA,KAA5C;AACA,WAAOU,aAAa,CAACL,IAAD,EAAON,OAAP,CAApB;AACD;;AAGS,QAAJY,IAAI,CAACN,IAAD,EAAeO,KAAf,EAAuCC,IAAvC,EAAoE;AAC5E,WAAO,MAAMjB,EAAE,CAACe,IAAH,CAAQN,IAAR,EAAcO,KAAd,CAAb;AACD;;AAEU,QAALE,KAAK,CAACC,EAAD,EAA4B;AACrC,WAAO,MAAMnB,EAAE,CAACkB,KAAH,CAASC,EAAT,CAAb;AACD;;AAEU,QAALC,KAAK,CAACD,EAAD,EAA4B;AACrC,UAAMT,IAAI,GAAG,MAAMV,EAAE,CAACoB,KAAH,CAASD,EAAT,CAAnB;AACA,WAAOT,IAAP;AACD;;AAES,QAAJW,IAAI,CACRF,EADQ,EAGR;AAACG,IAAAA,MAAM,GAAG,IAAV;AAAgBC,IAAAA,MAAM,GAAG,CAAzB;AAA4BC,IAAAA,MAAM,GAAGF,MAAM,CAACG,UAA5C;AAAwDC,IAAAA,QAAQ,GAAG;AAAnE,GAHQ,EAIsC;AAC9C,QAAIC,cAAc,GAAG,CAArB;;AAEA,WAAOA,cAAc,GAAGH,MAAxB,EAAgC;AAC9B,YAAM;AAACI,QAAAA;AAAD,UAAc,MAAM5B,EAAE,CAACqB,IAAH,CACxBF,EADwB,EAExBG,MAFwB,EAGxBC,MAAM,GAAGI,cAHe,EAIxBH,MAAM,GAAGG,cAJe,EAKxBD,QAAQ,GAAGC,cALa,CAA1B;AAOAA,MAAAA,cAAc,IAAIC,SAAlB;AACD;;AACD,WAAO;AAACA,MAAAA,SAAS,EAAED,cAAZ;AAA4BL,MAAAA;AAA5B,KAAP;AACD;;AAtDqF","sourcesContent":["import * as fs from '../node/fs';\nimport {IFileSystem, IRandomAccessReadFileSystem} from '../../types';\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"}
@@ -1,53 +1,39 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.concatenateStringsAsync = exports.concatenateArrayBuffersAsync = exports.forEach = void 0;
4
- const array_buffer_utils_1 = require("../binary-utils/array-buffer-utils");
5
- // GENERAL UTILITIES
6
- /**
7
- * Iterate over async iterator, without resetting iterator if end is not reached
8
- * - forEach intentionally does not reset iterator if exiting loop prematurely
9
- * so that iteration can continue in a second loop
10
- * - It is recommended to use a standard for-await as last loop to ensure
11
- * iterator gets properly reset
12
- *
13
- * TODO - optimize using sync iteration if argument is an Iterable?
14
- *
15
- * @param iterator
16
- * @param visitor
17
- */
18
- async function forEach(iterator, visitor) {
19
- // eslint-disable-next-line
20
- while (true) {
21
- const { done, value } = await iterator.next();
22
- if (done) {
23
- iterator.return();
24
- return;
25
- }
26
- const cancel = visitor(value);
27
- if (cancel) {
28
- return;
29
- }
1
+ import { concatenateArrayBuffers } from '../binary-utils/array-buffer-utils';
2
+ export async function forEach(iterator, visitor) {
3
+ while (true) {
4
+ const {
5
+ done,
6
+ value
7
+ } = await iterator.next();
8
+
9
+ if (done) {
10
+ iterator.return();
11
+ return;
30
12
  }
31
- }
32
- exports.forEach = forEach;
33
- // Breaking big data into iterable chunks, concatenating iterable chunks into big data objects
34
- /**
35
- * Concatenates all data chunks yielded by an (async) iterator
36
- * This function can e.g. be used to enable atomic parsers to work on (async) iterator inputs
37
- */
38
- async function concatenateArrayBuffersAsync(asyncIterator) {
39
- const arrayBuffers = [];
40
- for await (const chunk of asyncIterator) {
41
- arrayBuffers.push(chunk);
13
+
14
+ const cancel = visitor(value);
15
+
16
+ if (cancel) {
17
+ return;
42
18
  }
43
- return (0, array_buffer_utils_1.concatenateArrayBuffers)(...arrayBuffers);
19
+ }
44
20
  }
45
- exports.concatenateArrayBuffersAsync = concatenateArrayBuffersAsync;
46
- async function concatenateStringsAsync(asyncIterator) {
47
- const strings = [];
48
- for await (const chunk of asyncIterator) {
49
- strings.push(chunk);
50
- }
51
- return strings.join('');
21
+ export async function concatenateArrayBuffersAsync(asyncIterator) {
22
+ const arrayBuffers = [];
23
+
24
+ for await (const chunk of asyncIterator) {
25
+ arrayBuffers.push(chunk);
26
+ }
27
+
28
+ return concatenateArrayBuffers(...arrayBuffers);
29
+ }
30
+ export async function concatenateStringsAsync(asyncIterator) {
31
+ const strings = [];
32
+
33
+ for await (const chunk of asyncIterator) {
34
+ strings.push(chunk);
35
+ }
36
+
37
+ return strings.join('');
52
38
  }
53
- exports.concatenateStringsAsync = concatenateStringsAsync;
39
+ //# sourceMappingURL=async-iteration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/iterators/async-iteration.ts"],"names":["concatenateArrayBuffers","forEach","iterator","visitor","done","value","next","return","cancel","concatenateArrayBuffersAsync","asyncIterator","arrayBuffers","chunk","push","concatenateStringsAsync","strings","join"],"mappings":"AAAA,SAAQA,uBAAR,QAAsC,oCAAtC;AAgBA,OAAO,eAAeC,OAAf,CAAuBC,QAAvB,EAAiCC,OAAjC,EAA0C;AAE/C,SAAO,IAAP,EAAa;AACX,UAAM;AAACC,MAAAA,IAAD;AAAOC,MAAAA;AAAP,QAAgB,MAAMH,QAAQ,CAACI,IAAT,EAA5B;;AACA,QAAIF,IAAJ,EAAU;AACRF,MAAAA,QAAQ,CAACK,MAAT;AACA;AACD;;AACD,UAAMC,MAAM,GAAGL,OAAO,CAACE,KAAD,CAAtB;;AACA,QAAIG,MAAJ,EAAY;AACV;AACD;AACF;AACF;AASD,OAAO,eAAeC,4BAAf,CACLC,aADK,EAEiB;AACtB,QAAMC,YAA2B,GAAG,EAApC;;AACA,aAAW,MAAMC,KAAjB,IAA0BF,aAA1B,EAAyC;AACvCC,IAAAA,YAAY,CAACE,IAAb,CAAkBD,KAAlB;AACD;;AACD,SAAOZ,uBAAuB,CAAC,GAAGW,YAAJ,CAA9B;AACD;AAED,OAAO,eAAeG,uBAAf,CACLJ,aADK,EAEY;AACjB,QAAMK,OAAiB,GAAG,EAA1B;;AACA,aAAW,MAAMH,KAAjB,IAA0BF,aAA1B,EAAyC;AACvCK,IAAAA,OAAO,CAACF,IAAR,CAAaD,KAAb;AACD;;AACD,SAAOG,OAAO,CAACC,IAAR,CAAa,EAAb,CAAP;AACD","sourcesContent":["import {concatenateArrayBuffers} from '../binary-utils/array-buffer-utils';\n\n// GENERAL UTILITIES\n\n/**\n * Iterate over async iterator, without resetting iterator if end is not reached\n * - forEach intentionally does not reset iterator if exiting loop prematurely\n * so that iteration can continue in a second loop\n * - It is recommended to use a standard for-await as last loop to ensure\n * iterator gets properly reset\n *\n * TODO - optimize using sync iteration if argument is an Iterable?\n *\n * @param iterator\n * @param visitor\n */\nexport async function forEach(iterator, visitor) {\n // eslint-disable-next-line\n while (true) {\n const {done, value} = await iterator.next();\n if (done) {\n iterator.return();\n return;\n }\n const cancel = visitor(value);\n if (cancel) {\n return;\n }\n }\n}\n\n// Breaking big data into iterable chunks, concatenating iterable chunks into big data objects\n\n/**\n * Concatenates all data chunks yielded by an (async) iterator\n * This function can e.g. be used to enable atomic parsers to work on (async) iterator inputs\n */\n\nexport async function concatenateArrayBuffersAsync(\n asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>\n): Promise<ArrayBuffer> {\n const arrayBuffers: ArrayBuffer[] = [];\n for await (const chunk of asyncIterator) {\n arrayBuffers.push(chunk);\n }\n return concatenateArrayBuffers(...arrayBuffers);\n}\n\nexport async function concatenateStringsAsync(\n asyncIterator: AsyncIterable<string> | Iterable<string>\n): Promise<string> {\n const strings: string[] = [];\n for await (const chunk of asyncIterator) {\n strings.push(chunk);\n }\n return strings.join('');\n}\n"],"file":"async-iteration.js"}