@loaders.gl/loader-utils 3.3.0-alpha.1 → 3.3.0-alpha.11

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 (119) hide show
  1. package/dist/es5/index.js +97 -119
  2. package/dist/es5/index.js.map +1 -1
  3. package/dist/es5/json-loader.js +2 -9
  4. package/dist/es5/json-loader.js.map +1 -1
  5. package/dist/es5/lib/binary-utils/array-buffer-utils.js +6 -26
  6. package/dist/es5/lib/binary-utils/array-buffer-utils.js.map +1 -1
  7. package/dist/es5/lib/binary-utils/binary-copy-utils.js +0 -4
  8. package/dist/es5/lib/binary-utils/binary-copy-utils.js.map +1 -1
  9. package/dist/es5/lib/binary-utils/buffer-utils.js +1 -9
  10. package/dist/es5/lib/binary-utils/buffer-utils.js.map +1 -1
  11. package/dist/es5/lib/binary-utils/encode-utils.js +2 -8
  12. package/dist/es5/lib/binary-utils/encode-utils.js.map +1 -1
  13. package/dist/es5/lib/binary-utils/get-first-characters.js +0 -7
  14. package/dist/es5/lib/binary-utils/get-first-characters.js.map +1 -1
  15. package/dist/es5/lib/binary-utils/memory-copy-utils.js +1 -4
  16. package/dist/es5/lib/binary-utils/memory-copy-utils.js.map +1 -1
  17. package/dist/es5/lib/env-utils/assert.js +0 -1
  18. package/dist/es5/lib/env-utils/assert.js.map +1 -1
  19. package/dist/es5/lib/env-utils/globals.js +5 -4
  20. package/dist/es5/lib/env-utils/globals.js.map +1 -1
  21. package/dist/es5/lib/filesystems/node-filesystem.js +2 -45
  22. package/dist/es5/lib/filesystems/node-filesystem.js.map +1 -1
  23. package/dist/es5/lib/iterators/async-iteration.js +57 -127
  24. package/dist/es5/lib/iterators/async-iteration.js.map +1 -1
  25. package/dist/es5/lib/iterators/text-iterators.js +127 -242
  26. package/dist/es5/lib/iterators/text-iterators.js.map +1 -1
  27. package/dist/es5/lib/node/buffer.js +0 -6
  28. package/dist/es5/lib/node/buffer.js.map +1 -1
  29. package/dist/es5/lib/node/fs.js +17 -24
  30. package/dist/es5/lib/node/fs.js.map +1 -1
  31. package/dist/es5/lib/node/util.js +20 -11
  32. package/dist/es5/lib/node/util.js.map +1 -1
  33. package/dist/es5/lib/parser-utils/parse-json.js +0 -2
  34. package/dist/es5/lib/parser-utils/parse-json.js.map +1 -1
  35. package/dist/es5/lib/path-utils/file-aliases.js +3 -4
  36. package/dist/es5/lib/path-utils/file-aliases.js.map +1 -1
  37. package/dist/es5/lib/path-utils/path.js +1 -4
  38. package/dist/es5/lib/path-utils/path.js.map +1 -1
  39. package/dist/es5/lib/request-utils/request-scheduler.js +24 -33
  40. package/dist/es5/lib/request-utils/request-scheduler.js.map +1 -1
  41. package/dist/es5/lib/worker-loader-utils/create-loader-worker.js +2 -36
  42. package/dist/es5/lib/worker-loader-utils/create-loader-worker.js.map +1 -1
  43. package/dist/es5/lib/worker-loader-utils/encode-with-worker.js +0 -4
  44. package/dist/es5/lib/worker-loader-utils/encode-with-worker.js.map +1 -1
  45. package/dist/es5/lib/worker-loader-utils/parse-with-worker.js +2 -23
  46. package/dist/es5/lib/worker-loader-utils/parse-with-worker.js.map +1 -1
  47. package/dist/es5/types.js.map +1 -1
  48. package/dist/es5/workers/json-worker.js +0 -2
  49. package/dist/es5/workers/json-worker.js.map +1 -1
  50. package/dist/esm/index.js +15 -3
  51. package/dist/esm/index.js.map +1 -1
  52. package/dist/esm/json-loader.js +3 -2
  53. package/dist/esm/json-loader.js.map +1 -1
  54. package/dist/esm/lib/binary-utils/array-buffer-utils.js +16 -15
  55. package/dist/esm/lib/binary-utils/array-buffer-utils.js.map +1 -1
  56. package/dist/esm/lib/binary-utils/binary-copy-utils.js +2 -2
  57. package/dist/esm/lib/binary-utils/binary-copy-utils.js.map +1 -1
  58. package/dist/esm/lib/binary-utils/buffer-utils.js +3 -1
  59. package/dist/esm/lib/binary-utils/buffer-utils.js.map +1 -1
  60. package/dist/esm/lib/binary-utils/encode-utils.js +2 -4
  61. package/dist/esm/lib/binary-utils/encode-utils.js.map +1 -1
  62. package/dist/esm/lib/binary-utils/get-first-characters.js +2 -5
  63. package/dist/esm/lib/binary-utils/get-first-characters.js.map +1 -1
  64. package/dist/esm/lib/binary-utils/memory-copy-utils.js +5 -2
  65. package/dist/esm/lib/binary-utils/memory-copy-utils.js.map +1 -1
  66. package/dist/esm/lib/env-utils/assert.js +1 -0
  67. package/dist/esm/lib/env-utils/assert.js.map +1 -1
  68. package/dist/esm/lib/env-utils/globals.js +7 -1
  69. package/dist/esm/lib/env-utils/globals.js.map +1 -1
  70. package/dist/esm/lib/filesystems/node-filesystem.js +10 -16
  71. package/dist/esm/lib/filesystems/node-filesystem.js.map +1 -1
  72. package/dist/esm/lib/iterators/async-iteration.js +2 -7
  73. package/dist/esm/lib/iterators/async-iteration.js.map +1 -1
  74. package/dist/esm/lib/iterators/text-iterators.js +7 -7
  75. package/dist/esm/lib/iterators/text-iterators.js.map +1 -1
  76. package/dist/esm/lib/node/buffer.js +4 -5
  77. package/dist/esm/lib/node/buffer.js.map +1 -1
  78. package/dist/esm/lib/node/fs.js +16 -13
  79. package/dist/esm/lib/node/fs.js.map +1 -1
  80. package/dist/esm/lib/node/util.js +16 -2
  81. package/dist/esm/lib/node/util.js.map +1 -1
  82. package/dist/esm/lib/parser-utils/parse-json.js +1 -0
  83. package/dist/esm/lib/parser-utils/parse-json.js.map +1 -1
  84. package/dist/esm/lib/path-utils/file-aliases.js +6 -2
  85. package/dist/esm/lib/path-utils/file-aliases.js.map +1 -1
  86. package/dist/esm/lib/path-utils/path.js +8 -3
  87. package/dist/esm/lib/path-utils/path.js.map +1 -1
  88. package/dist/esm/lib/request-utils/request-scheduler.js +11 -21
  89. package/dist/esm/lib/request-utils/request-scheduler.js.map +1 -1
  90. package/dist/esm/lib/worker-loader-utils/create-loader-worker.js +19 -17
  91. package/dist/esm/lib/worker-loader-utils/create-loader-worker.js.map +1 -1
  92. package/dist/esm/lib/worker-loader-utils/encode-with-worker.js +1 -1
  93. package/dist/esm/lib/worker-loader-utils/encode-with-worker.js.map +1 -1
  94. package/dist/esm/lib/worker-loader-utils/parse-with-worker.js +6 -7
  95. package/dist/esm/lib/worker-loader-utils/parse-with-worker.js.map +1 -1
  96. package/dist/esm/types.js.map +1 -1
  97. package/dist/esm/workers/json-worker.js.map +1 -1
  98. package/dist/index.d.ts +1 -3
  99. package/dist/index.d.ts.map +1 -1
  100. package/dist/index.js +10 -8
  101. package/dist/lib/binary-utils/buffer-utils.js +5 -1
  102. package/dist/lib/env-utils/globals.d.ts +1 -1
  103. package/dist/lib/env-utils/globals.d.ts.map +1 -1
  104. package/dist/lib/filesystems/node-filesystem.d.ts +3 -2
  105. package/dist/lib/filesystems/node-filesystem.d.ts.map +1 -1
  106. package/dist/lib/filesystems/node-filesystem.js +5 -1
  107. package/dist/lib/node/fs.js +8 -8
  108. package/dist/lib/node/util.d.ts +10 -3
  109. package/dist/lib/node/util.d.ts.map +1 -1
  110. package/dist/lib/node/util.js +24 -23
  111. package/dist/lib/request-utils/request-scheduler.d.ts +6 -6
  112. package/dist/lib/request-utils/request-scheduler.d.ts.map +1 -1
  113. package/dist/lib/worker-loader-utils/create-loader-worker.js +1 -1
  114. package/dist/types.d.ts +29 -29
  115. package/dist/types.d.ts.map +1 -1
  116. package/package.json +3 -3
  117. package/src/index.ts +3 -6
  118. package/src/lib/node/fs.ts +9 -9
  119. package/src/lib/node/util.ts +28 -2
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/binary-utils/array-buffer-utils.ts"],"names":["isBuffer","bufferToArrayBuffer","toArrayBuffer","data","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","array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CAAUE,WAA1C,IAA0D,IAAxF;;AACA,MAAI,CAACD,qBAAL,EAA4B;AAC1B,UAAM,IAAIvB,KAAJ,CACJ,sGADI,CAAN;AAGD;;AAED,QAAMyB,SAAS,GAAGH,MAAM,CAACR,MAAP,CAAc,CAACY,GAAD,EAAMC,KAAN,KAAgBD,GAAG,GAAGC,KAAK,CAACnB,MAA1C,EAAkD,CAAlD,CAAlB;AAEA,QAAMQ,MAAM,GAAG,IAAIO,qBAAJ,CAA0BE,SAA1B,CAAf;AACA,MAAIR,MAAM,GAAG,CAAb;;AACA,OAAK,MAAMW,KAAX,IAAoBN,MAApB,EAA4B;AAC1BN,IAAAA,MAAM,CAACG,GAAP,CAAWS,KAAX,EAAkBX,MAAlB;AACAA,IAAAA,MAAM,IAAIW,KAAK,CAACpB,MAAhB;AACD;;AACD,SAAOQ,MAAP;AACD;AAQD,OAAO,SAASa,gBAAT,CACLC,WADK,EAELvC,UAFK,EAGLC,UAHK,EAIQ;AACb,QAAMuC,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,QAAM2C,SAAS,GAAG,IAAI7B,UAAJ,CAAe0B,QAAf,CAAlB;AACA,SAAOG,SAAS,CAACzC,MAAjB;AACD","sourcesContent":["import {TypedArray} from '../../types';\nimport {isBuffer, bufferToArrayBuffer} 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 (isBuffer(data)) {\n return 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"}
1
+ {"version":3,"file":"array-buffer-utils.js","names":["isBuffer","bufferToArrayBuffer","toArrayBuffer","data","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"],"sources":["../../../../src/lib/binary-utils/array-buffer-utils.ts"],"sourcesContent":["import {TypedArray} from '../../types';\nimport {isBuffer, bufferToArrayBuffer} 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 (isBuffer(data)) {\n return 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"],"mappings":"AACA,SAAQA,QAAQ,EAAEC,mBAAmB,QAAO,gBAAgB;;AAK5D,OAAO,SAASC,aAAa,CAACC,IAAS,EAAe;EAEpD,IAAIH,QAAQ,CAACG,IAAI,CAAC,EAAE;IAClB,OAAOF,mBAAmB,CAACE,IAAI,CAAC;EAClC;EAEA,IAAIA,IAAI,YAAYC,WAAW,EAAE;IAC/B,OAAOD,IAAI;EACb;;EAGA,IAAIC,WAAW,CAACC,MAAM,C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AAK,IAAIN,MAAM,EAAE;IAC1BN,MAAM,CAACG,GAAG,CAACS,KAAK,EAAEX,MAAM,CAAC;IACzBA,MAAM,IAAIW,KAAK,CAACpB,MAAM;EACxB;EACA,OAAOQ,MAAM;AACf;;AAQA,OAAO,SAASa,gBAAgB,CAC9BC,WAAwB,EACxBvC,UAAkB,EAClBC,UAAmB,EACN;EACb,MAAMuC,QAAQ,GACZvC,UAAU,KAAKwC,SAAS,GACpB,IAAI3B,UAAU,CAACyB,WAAW,CAAC,CAACG,QAAQ,CAAC1C,UAAU,EAAEA,UAAU,GAAGC,UAAU,CAAC,GACzE,IAAIa,UAAU,CAACyB,WAAW,CAAC,CAACG,QAAQ,CAAC1C,UAAU,CAAC;EACtD,MAAM2C,SAAS,GAAG,IAAI7B,UAAU,CAAC0B,QAAQ,CAAC;EAC1C,OAAOG,SAAS,CAACzC,MAAM;AACzB"}
@@ -1,8 +1,8 @@
1
1
  import { padToNBytes } from './memory-copy-utils';
2
+
2
3
  export function copyPaddedArrayBufferToDataView(dataView, byteOffset, sourceBuffer, padding) {
3
4
  const paddedLength = padToNBytes(sourceBuffer.byteLength, padding);
4
5
  const padLength = paddedLength - sourceBuffer.byteLength;
5
-
6
6
  if (dataView) {
7
7
  const targetArray = new Uint8Array(dataView.buffer, dataView.byteOffset + byteOffset, sourceBuffer.byteLength);
8
8
  const sourceArray = new Uint8Array(sourceBuffer);
@@ -12,10 +12,10 @@ export function copyPaddedArrayBufferToDataView(dataView, byteOffset, sourceBuff
12
12
  dataView.setUint8(byteOffset + sourceBuffer.byteLength + i, 0x20);
13
13
  }
14
14
  }
15
-
16
15
  byteOffset += paddedLength;
17
16
  return byteOffset;
18
17
  }
18
+
19
19
  export function copyPaddedStringToDataView(dataView, byteOffset, string, padding) {
20
20
  const textEncoder = new TextEncoder();
21
21
  const stringBuffer = textEncoder.encode(string);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/binary-utils/binary-copy-utils.ts"],"names":["padToNBytes","copyPaddedArrayBufferToDataView","dataView","byteOffset","sourceBuffer","padding","paddedLength","byteLength","padLength","targetArray","Uint8Array","buffer","sourceArray","set","i","setUint8","copyPaddedStringToDataView","string","textEncoder","TextEncoder","stringBuffer","encode"],"mappings":"AACA,SAAQA,WAAR,QAA0B,qBAA1B;AAYA,OAAO,SAASC,+BAAT,CACLC,QADK,EAELC,UAFK,EAGLC,YAHK,EAILC,OAJK,EAKL;AACA,QAAMC,YAAY,GAAGN,WAAW,CAACI,YAAY,CAACG,UAAd,EAA0BF,OAA1B,CAAhC;AACA,QAAMG,SAAS,GAAGF,YAAY,GAAGF,YAAY,CAACG,UAA9C;;AAEA,MAAIL,QAAJ,EAAc;AAEZ,UAAMO,WAAW,GAAG,IAAIC,UAAJ,CAClBR,QAAQ,CAACS,MADS,EAElBT,QAAQ,CAACC,UAAT,GAAsBA,UAFJ,EAGlBC,YAAY,CAACG,UAHK,CAApB;AAKA,UAAMK,WAAW,GAAG,IAAIF,UAAJ,CAAeN,YAAf,CAApB;AACAK,IAAAA,WAAW,CAACI,GAAZ,CAAgBD,WAAhB;;AAGA,SAAK,IAAIE,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGN,SAApB,EAA+B,EAAEM,CAAjC,EAAoC;AAElCZ,MAAAA,QAAQ,CAACa,QAAT,CAAkBZ,UAAU,GAAGC,YAAY,CAACG,UAA1B,GAAuCO,CAAzD,EAA4D,IAA5D;AACD;AACF;;AACDX,EAAAA,UAAU,IAAIG,YAAd;AACA,SAAOH,UAAP;AACD;AAYD,OAAO,SAASa,0BAAT,CACLd,QADK,EAELC,UAFK,EAGLc,MAHK,EAILZ,OAJK,EAKG;AACR,QAAMa,WAAW,GAAG,IAAIC,WAAJ,EAApB;AAGA,QAAMC,YAAY,GAAGF,WAAW,CAACG,MAAZ,CAAmBJ,MAAnB,CAArB;AAEAd,EAAAA,UAAU,GAAGF,+BAA+B,CAACC,QAAD,EAAWC,UAAX,EAAuBiB,YAAvB,EAAqCf,OAArC,CAA5C;AAEA,SAAOF,UAAP;AACD","sourcesContent":["import {TypedArray} from '../../types';\nimport {padToNBytes} from './memory-copy-utils';\n\n/**\n * Copy sourceBuffer to dataView with some padding\n *\n * @param {DataView | null} dataView - destination data container. If null - only new offset is calculated\n * @param {number} byteOffset - destination byte offset to copy to\n * @param {Array | TypedArray} sourceBuffer - source data buffer\n * @param {number} padding - pad the resulting array to multiple of \"padding\" bytes. Additional bytes are filled with 0x20 (ASCII space)\n *\n * @return new byteOffset of resulting dataView\n */\nexport function copyPaddedArrayBufferToDataView(\n dataView: DataView | null,\n byteOffset: number,\n sourceBuffer: TypedArray,\n padding: number\n) {\n const paddedLength = padToNBytes(sourceBuffer.byteLength, padding);\n const padLength = paddedLength - sourceBuffer.byteLength;\n\n if (dataView) {\n // Copy array\n const targetArray = new Uint8Array(\n dataView.buffer,\n dataView.byteOffset + byteOffset,\n sourceBuffer.byteLength\n );\n const sourceArray = new Uint8Array(sourceBuffer);\n targetArray.set(sourceArray);\n\n // Add PADDING\n for (let i = 0; i < padLength; ++i) {\n // json chunk is padded with spaces (ASCII 0x20)\n dataView.setUint8(byteOffset + sourceBuffer.byteLength + i, 0x20);\n }\n }\n byteOffset += paddedLength;\n return byteOffset;\n}\n\n/**\n * Copy string to dataView with some padding\n *\n * @param {DataView | null} dataView - destination data container. If null - only new offset is calculated\n * @param {number} byteOffset - destination byte offset to copy to\n * @param {string} string - source string\n * @param {number} padding - pad the resulting array to multiple of \"padding\" bytes. Additional bytes are filled with 0x20 (ASCII space)\n *\n * @return new byteOffset of resulting dataView\n */\nexport function copyPaddedStringToDataView(\n dataView: DataView | null,\n byteOffset: number,\n string: string,\n padding: number\n): number {\n const textEncoder = new TextEncoder();\n // PERFORMANCE IDEA: We encode twice, once to get size and once to store\n // PERFORMANCE IDEA: Use TextEncoder.encodeInto() to avoid temporary copy\n const stringBuffer = textEncoder.encode(string);\n\n byteOffset = copyPaddedArrayBufferToDataView(dataView, byteOffset, stringBuffer, padding);\n\n return byteOffset;\n}\n"],"file":"binary-copy-utils.js"}
1
+ {"version":3,"file":"binary-copy-utils.js","names":["padToNBytes","copyPaddedArrayBufferToDataView","dataView","byteOffset","sourceBuffer","padding","paddedLength","byteLength","padLength","targetArray","Uint8Array","buffer","sourceArray","set","i","setUint8","copyPaddedStringToDataView","string","textEncoder","TextEncoder","stringBuffer","encode"],"sources":["../../../../src/lib/binary-utils/binary-copy-utils.ts"],"sourcesContent":["import {TypedArray} from '../../types';\nimport {padToNBytes} from './memory-copy-utils';\n\n/**\n * Copy sourceBuffer to dataView with some padding\n *\n * @param {DataView | null} dataView - destination data container. If null - only new offset is calculated\n * @param {number} byteOffset - destination byte offset to copy to\n * @param {Array | TypedArray} sourceBuffer - source data buffer\n * @param {number} padding - pad the resulting array to multiple of \"padding\" bytes. Additional bytes are filled with 0x20 (ASCII space)\n *\n * @return new byteOffset of resulting dataView\n */\nexport function copyPaddedArrayBufferToDataView(\n dataView: DataView | null,\n byteOffset: number,\n sourceBuffer: TypedArray,\n padding: number\n) {\n const paddedLength = padToNBytes(sourceBuffer.byteLength, padding);\n const padLength = paddedLength - sourceBuffer.byteLength;\n\n if (dataView) {\n // Copy array\n const targetArray = new Uint8Array(\n dataView.buffer,\n dataView.byteOffset + byteOffset,\n sourceBuffer.byteLength\n );\n const sourceArray = new Uint8Array(sourceBuffer);\n targetArray.set(sourceArray);\n\n // Add PADDING\n for (let i = 0; i < padLength; ++i) {\n // json chunk is padded with spaces (ASCII 0x20)\n dataView.setUint8(byteOffset + sourceBuffer.byteLength + i, 0x20);\n }\n }\n byteOffset += paddedLength;\n return byteOffset;\n}\n\n/**\n * Copy string to dataView with some padding\n *\n * @param {DataView | null} dataView - destination data container. If null - only new offset is calculated\n * @param {number} byteOffset - destination byte offset to copy to\n * @param {string} string - source string\n * @param {number} padding - pad the resulting array to multiple of \"padding\" bytes. Additional bytes are filled with 0x20 (ASCII space)\n *\n * @return new byteOffset of resulting dataView\n */\nexport function copyPaddedStringToDataView(\n dataView: DataView | null,\n byteOffset: number,\n string: string,\n padding: number\n): number {\n const textEncoder = new TextEncoder();\n // PERFORMANCE IDEA: We encode twice, once to get size and once to store\n // PERFORMANCE IDEA: Use TextEncoder.encodeInto() to avoid temporary copy\n const stringBuffer = textEncoder.encode(string);\n\n byteOffset = copyPaddedArrayBufferToDataView(dataView, byteOffset, stringBuffer, padding);\n\n return byteOffset;\n}\n"],"mappings":"AACA,SAAQA,WAAW,QAAO,qBAAqB;;AAY/C,OAAO,SAASC,+BAA+B,CAC7CC,QAAyB,EACzBC,UAAkB,EAClBC,YAAwB,EACxBC,OAAe,EACf;EACA,MAAMC,YAAY,GAAGN,WAAW,CAACI,YAAY,CAACG,UAAU,EAAEF,OAAO,CAAC;EAClE,MAAMG,SAAS,GAAGF,YAAY,GAAGF,YAAY,CAACG,UAAU;EAExD,IAAIL,QAAQ,EAAE;IAEZ,MAAMO,WAAW,GAAG,IAAIC,UAAU,CAChCR,QAAQ,CAACS,MAAM,EACfT,QAAQ,CAACC,UAAU,GAAGA,UAAU,EAChCC,YAAY,CAACG,UAAU,CACxB;IACD,MAAMK,WAAW,GAAG,IAAIF,UAAU,CAACN,YAAY,CAAC;IAChDK,WAAW,CAACI,GAAG,CAACD,WAAW,CAAC;;IAG5B,KAAK,IAAIE,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGN,SAAS,EAAE,EAAEM,CAAC,EAAE;MAElCZ,QAAQ,CAACa,QAAQ,CAACZ,UAAU,GAAGC,YAAY,CAACG,UAAU,GAAGO,CAAC,EAAE,IAAI,CAAC;IACnE;EACF;EACAX,UAAU,IAAIG,YAAY;EAC1B,OAAOH,UAAU;AACnB;;AAYA,OAAO,SAASa,0BAA0B,CACxCd,QAAyB,EACzBC,UAAkB,EAClBc,MAAc,EACdZ,OAAe,EACP;EACR,MAAMa,WAAW,GAAG,IAAIC,WAAW,EAAE;EAGrC,MAAMC,YAAY,GAAGF,WAAW,CAACG,MAAM,CAACJ,MAAM,CAAC;EAE/Cd,UAAU,GAAGF,+BAA+B,CAACC,QAAQ,EAAEC,UAAU,EAAEiB,YAAY,EAAEf,OAAO,CAAC;EAEzF,OAAOF,UAAU;AACnB"}
@@ -1,16 +1,18 @@
1
1
  import * as node from '../node/buffer';
2
+
2
3
  export function isBuffer(value) {
3
4
  return value && typeof value === 'object' && value.isBuffer;
4
5
  }
6
+
5
7
  export function toBuffer(data) {
6
8
  return node.toBuffer ? node.toBuffer(data) : data;
7
9
  }
10
+
8
11
  export function bufferToArrayBuffer(buffer) {
9
12
  if (isBuffer(buffer)) {
10
13
  const typedArray = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.length);
11
14
  return typedArray.slice().buffer;
12
15
  }
13
-
14
16
  return buffer;
15
17
  }
16
18
  //# sourceMappingURL=buffer-utils.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/binary-utils/buffer-utils.ts"],"names":["node","isBuffer","value","toBuffer","data","bufferToArrayBuffer","buffer","typedArray","Uint8Array","byteOffset","length","slice"],"mappings":"AAAA,OAAO,KAAKA,IAAZ,MAAsB,gBAAtB;AAKA,OAAO,SAASC,QAAT,CAAkBC,KAAlB,EAAuC;AAC5C,SAAOA,KAAK,IAAI,OAAOA,KAAP,KAAiB,QAA1B,IAAsCA,KAAK,CAACD,QAAnD;AACD;AAMD,OAAO,SAASE,QAAT,CAAkBC,IAAlB,EAAqC;AAC1C,SAAOJ,IAAI,CAACG,QAAL,GAAgBH,IAAI,CAACG,QAAL,CAAcC,IAAd,CAAhB,GAAsCA,IAA7C;AACD;AAMD,OAAO,SAASC,mBAAT,CAA6BC,MAA7B,EAAuD;AAC5D,MAAIL,QAAQ,CAACK,MAAD,CAAZ,EAAsB;AACpB,UAAMC,UAAU,GAAG,IAAIC,UAAJ,CAAeF,MAAM,CAACA,MAAtB,EAA8BA,MAAM,CAACG,UAArC,EAAiDH,MAAM,CAACI,MAAxD,CAAnB;AACA,WAAOH,UAAU,CAACI,KAAX,GAAmBL,MAA1B;AACD;;AACD,SAAOA,MAAP;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(buffer: any): ArrayBuffer {\n if (isBuffer(buffer)) {\n const typedArray = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.length);\n return typedArray.slice().buffer;\n }\n return buffer;\n}\n"],"file":"buffer-utils.js"}
1
+ {"version":3,"file":"buffer-utils.js","names":["node","isBuffer","value","toBuffer","data","bufferToArrayBuffer","buffer","typedArray","Uint8Array","byteOffset","length","slice"],"sources":["../../../../src/lib/binary-utils/buffer-utils.ts"],"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(buffer: any): ArrayBuffer {\n if (isBuffer(buffer)) {\n const typedArray = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.length);\n return typedArray.slice().buffer;\n }\n return buffer;\n}\n"],"mappings":"AAAA,OAAO,KAAKA,IAAI,MAAM,gBAAgB;;AAKtC,OAAO,SAASC,QAAQ,CAACC,KAAU,EAAW;EAC5C,OAAOA,KAAK,IAAI,OAAOA,KAAK,KAAK,QAAQ,IAAIA,KAAK,CAACD,QAAQ;AAC7D;;AAMA,OAAO,SAASE,QAAQ,CAACC,IAAS,EAAU;EAC1C,OAAOJ,IAAI,CAACG,QAAQ,GAAGH,IAAI,CAACG,QAAQ,CAACC,IAAI,CAAC,GAAGA,IAAI;AACnD;;AAMA,OAAO,SAASC,mBAAmB,CAACC,MAAW,EAAe;EAC5D,IAAIL,QAAQ,CAACK,MAAM,CAAC,EAAE;IACpB,MAAMC,UAAU,GAAG,IAAIC,UAAU,CAACF,MAAM,CAACA,MAAM,EAAEA,MAAM,CAACG,UAAU,EAAEH,MAAM,CAACI,MAAM,CAAC;IAClF,OAAOH,UAAU,CAACI,KAAK,EAAE,CAACL,MAAM;EAClC;EACA,OAAOA,MAAM;AACf"}
@@ -1,13 +1,13 @@
1
+
2
+
1
3
  export function padStringToByteAlignment(string, byteAlignment) {
2
4
  const length = string.length;
3
5
  const paddedLength = Math.ceil(length / byteAlignment) * byteAlignment;
4
6
  const padding = paddedLength - length;
5
7
  let whitespace = '';
6
-
7
8
  for (let i = 0; i < padding; ++i) {
8
9
  whitespace += ' ';
9
10
  }
10
-
11
11
  return string + whitespace;
12
12
  }
13
13
  export function copyStringToDataView(dataView, byteOffset, string, byteLength) {
@@ -16,7 +16,6 @@ export function copyStringToDataView(dataView, byteOffset, string, byteLength) {
16
16
  dataView.setUint8(byteOffset + i, string.charCodeAt(i));
17
17
  }
18
18
  }
19
-
20
19
  return byteOffset + byteLength;
21
20
  }
22
21
  export function copyBinaryToDataView(dataView, byteOffset, binary, byteLength) {
@@ -25,7 +24,6 @@ export function copyBinaryToDataView(dataView, byteOffset, binary, byteLength) {
25
24
  dataView.setUint8(byteOffset + i, binary[i]);
26
25
  }
27
26
  }
28
-
29
27
  return byteOffset + byteLength;
30
28
  }
31
29
  //# sourceMappingURL=encode-utils.js.map
@@ -1 +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
+ {"version":3,"file":"encode-utils.js","names":["padStringToByteAlignment","string","byteAlignment","length","paddedLength","Math","ceil","padding","whitespace","i","copyStringToDataView","dataView","byteOffset","byteLength","setUint8","charCodeAt","copyBinaryToDataView","binary"],"sources":["../../../../src/lib/binary-utils/encode-utils.ts"],"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"],"mappings":";;AAIA,OAAO,SAASA,wBAAwB,CAACC,MAAM,EAAEC,aAAa,EAAE;EAC9D,MAAMC,MAAM,GAAGF,MAAM,CAACE,MAAM;EAC5B,MAAMC,YAAY,GAAGC,IAAI,CAACC,IAAI,CAACH,MAAM,GAAGD,aAAa,CAAC,GAAGA,aAAa;EACtE,MAAMK,OAAO,GAAGH,YAAY,GAAGD,MAAM;EACrC,IAAIK,UAAU,GAAG,EAAE;EACnB,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGF,OAAO,EAAE,EAAEE,CAAC,EAAE;IAChCD,UAAU,IAAI,GAAG;EACnB;EACA,OAAOP,MAAM,GAAGO,UAAU;AAC5B;AAEA,OAAO,SAASE,oBAAoB,CAACC,QAAQ,EAAEC,UAAU,EAAEX,MAAM,EAAEY,UAAU,EAAE;EAC7E,IAAIF,QAAQ,EAAE;IACZ,KAAK,IAAIF,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGI,UAAU,EAAEJ,CAAC,EAAE,EAAE;MACnCE,QAAQ,CAACG,QAAQ,CAACF,UAAU,GAAGH,CAAC,EAAER,MAAM,CAACc,UAAU,CAACN,CAAC,CAAC,CAAC;IACzD;EACF;EACA,OAAOG,UAAU,GAAGC,UAAU;AAChC;AAEA,OAAO,SAASG,oBAAoB,CAACL,QAAQ,EAAEC,UAAU,EAAEK,MAAM,EAAEJ,UAAU,EAAE;EAC7E,IAAIF,QAAQ,EAAE;IACZ,KAAK,IAAIF,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGI,UAAU,EAAEJ,CAAC,EAAE,EAAE;MACnCE,QAAQ,CAACG,QAAQ,CAACF,UAAU,GAAGH,CAAC,EAAEQ,MAAM,CAACR,CAAC,CAAC,CAAC;IAC9C;EACF;EACA,OAAOG,UAAU,GAAGC,UAAU;AAChC"}
@@ -1,4 +1,5 @@
1
- export function getFirstCharacters(data, length = 5) {
1
+ export function getFirstCharacters(data) {
2
+ let length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 5;
2
3
  if (typeof data === 'string') {
3
4
  return data.slice(0, length);
4
5
  } else if (ArrayBuffer.isView(data)) {
@@ -7,21 +8,17 @@ export function getFirstCharacters(data, length = 5) {
7
8
  const byteOffset = 0;
8
9
  return getMagicString(data, byteOffset, length);
9
10
  }
10
-
11
11
  return '';
12
12
  }
13
13
  export function getMagicString(arrayBuffer, byteOffset, length) {
14
14
  if (arrayBuffer.byteLength <= byteOffset + length) {
15
15
  return '';
16
16
  }
17
-
18
17
  const dataView = new DataView(arrayBuffer);
19
18
  let magic = '';
20
-
21
19
  for (let i = 0; i < length; i++) {
22
20
  magic += String.fromCharCode(dataView.getUint8(byteOffset + i));
23
21
  }
24
-
25
22
  return magic;
26
23
  }
27
24
  //# sourceMappingURL=get-first-characters.js.map
@@ -1 +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
+ {"version":3,"file":"get-first-characters.js","names":["getFirstCharacters","data","length","slice","ArrayBuffer","isView","getMagicString","buffer","byteOffset","arrayBuffer","byteLength","dataView","DataView","magic","i","String","fromCharCode","getUint8"],"sources":["../../../../src/lib/binary-utils/get-first-characters.ts"],"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"],"mappings":"AAAA,OAAO,SAASA,kBAAkB,CAACC,IAAI,EAAsB;EAAA,IAApBC,MAAM,uEAAG,CAAC;EACjD,IAAI,OAAOD,IAAI,KAAK,QAAQ,EAAE;IAC5B,OAAOA,IAAI,CAACE,KAAK,CAAC,CAAC,EAAED,MAAM,CAAC;EAC9B,CAAC,MAAM,IAAIE,WAAW,CAACC,MAAM,CAACJ,IAAI,CAAC,EAAE;IAEnC,OAAOK,cAAc,CAACL,IAAI,CAACM,MAAM,EAAEN,IAAI,CAACO,UAAU,EAAEN,MAAM,CAAC;EAC7D,CAAC,MAAM,IAAID,IAAI,YAAYG,WAAW,EAAE;IACtC,MAAMI,UAAU,GAAG,CAAC;IACpB,OAAOF,cAAc,CAACL,IAAI,EAAEO,UAAU,EAAEN,MAAM,CAAC;EACjD;EACA,OAAO,EAAE;AACX;AAEA,OAAO,SAASI,cAAc,CAC5BG,WAAwB,EACxBD,UAAkB,EAClBN,MAAc,EACN;EACR,IAAIO,WAAW,CAACC,UAAU,IAAIF,UAAU,GAAGN,MAAM,EAAE;IACjD,OAAO,EAAE;EACX;EACA,MAAMS,QAAQ,GAAG,IAAIC,QAAQ,CAACH,WAAW,CAAC;EAC1C,IAAII,KAAK,GAAG,EAAE;EACd,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGZ,MAAM,EAAEY,CAAC,EAAE,EAAE;IAC/BD,KAAK,IAAIE,MAAM,CAACC,YAAY,CAACL,QAAQ,CAACM,QAAQ,CAACT,UAAU,GAAGM,CAAC,CAAC,CAAC;EACjE;EACA,OAAOD,KAAK;AACd"}
@@ -1,18 +1,21 @@
1
1
  import { assert } from '../env-utils/assert';
2
+
2
3
  export function padToNBytes(byteLength, padding) {
3
4
  assert(byteLength >= 0);
4
5
  assert(padding > 0);
5
6
  return byteLength + (padding - 1) & ~(padding - 1);
6
7
  }
7
- export function copyArrayBuffer(targetBuffer, sourceBuffer, byteOffset, byteLength = sourceBuffer.byteLength) {
8
+
9
+ export function copyArrayBuffer(targetBuffer, sourceBuffer, byteOffset) {
10
+ let byteLength = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : sourceBuffer.byteLength;
8
11
  const targetArray = new Uint8Array(targetBuffer, byteOffset, byteLength);
9
12
  const sourceArray = new Uint8Array(sourceBuffer);
10
13
  targetArray.set(sourceArray);
11
14
  return targetBuffer;
12
15
  }
16
+
13
17
  export function copyToArray(source, target, targetOffset) {
14
18
  let sourceArray;
15
-
16
19
  if (source instanceof ArrayBuffer) {
17
20
  sourceArray = new Uint8Array(source);
18
21
  } else {
@@ -1 +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
+ {"version":3,"file":"memory-copy-utils.js","names":["assert","padToNBytes","byteLength","padding","copyArrayBuffer","targetBuffer","sourceBuffer","byteOffset","targetArray","Uint8Array","sourceArray","set","copyToArray","source","target","targetOffset","ArrayBuffer","srcByteOffset","srcByteLength","buffer","arrayBuffer"],"sources":["../../../../src/lib/binary-utils/memory-copy-utils.ts"],"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"],"mappings":"AAAA,SAAQA,MAAM,QAAO,qBAAqB;;AAS1C,OAAO,SAASC,WAAW,CAACC,UAAkB,EAAEC,OAAe,EAAU;EACvEH,MAAM,CAACE,UAAU,IAAI,CAAC,CAAC;EACvBF,MAAM,CAACG,OAAO,GAAG,CAAC,CAAC;EACnB,OAAQD,UAAU,IAAIC,OAAO,GAAG,CAAC,CAAC,GAAI,EAAEA,OAAO,GAAG,CAAC,CAAC;AACtD;;AAQA,OAAO,SAASC,eAAe,CAC7BC,YAAyB,EACzBC,YAAyB,EACzBC,UAAkB,EAEL;EAAA,IADbL,UAAkB,uEAAGI,YAAY,CAACJ,UAAU;EAE5C,MAAMM,WAAW,GAAG,IAAIC,UAAU,CAACJ,YAAY,EAAEE,UAAU,EAAEL,UAAU,CAAC;EACxE,MAAMQ,WAAW,GAAG,IAAID,UAAU,CAACH,YAAY,CAAC;EAChDE,WAAW,CAACG,GAAG,CAACD,WAAW,CAAC;EAC5B,OAAOL,YAAY;AACrB;;AAUA,OAAO,SAASO,WAAW,CAACC,MAAyB,EAAEC,MAAW,EAAEC,YAAoB,EAAU;EAChG,IAAIL,WAAW;EAEf,IAAIG,MAAM,YAAYG,WAAW,EAAE;IACjCN,WAAW,GAAG,IAAID,UAAU,CAACI,MAAM,CAAC;EACtC,CAAC,MAAM;IAOL,MAAMI,aAAa,GAAGJ,MAAM,CAACN,UAAU;IACvC,MAAMW,aAAa,GAAGL,MAAM,CAACX,UAAU;IAGvCQ,WAAW,GAAG,IAAID,UAAU,CAACI,MAAM,CAACM,MAAM,IAAIN,MAAM,CAACO,WAAW,EAAEH,aAAa,EAAEC,aAAa,CAAC;EACjG;;EAGAJ,MAAM,CAACH,GAAG,CAACD,WAAW,EAAEK,YAAY,CAAC;EAErC,OAAOA,YAAY,GAAGd,WAAW,CAACS,WAAW,CAACR,UAAU,EAAE,CAAC,CAAC;AAC9D"}
@@ -1,3 +1,4 @@
1
+
1
2
  export function assert(condition, message) {
2
3
  if (!condition) {
3
4
  throw new Error(message || 'loader assertion failed.');
@@ -1 +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
+ {"version":3,"file":"assert.js","names":["assert","condition","message","Error"],"sources":["../../../../src/lib/env-utils/assert.ts"],"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"],"mappings":";AAIA,OAAO,SAASA,MAAM,CAACC,SAAc,EAAEC,OAAgB,EAAQ;EAC7D,IAAI,CAACD,SAAS,EAAE;IACd,MAAM,IAAIE,KAAK,CAACD,OAAO,IAAI,0BAA0B,CAAC;EACxD;AACF"}
@@ -1,3 +1,5 @@
1
+
2
+
1
3
  const globals = {
2
4
  self: typeof self !== 'undefined' && self,
3
5
  window: typeof window !== 'undefined' && window,
@@ -9,8 +11,12 @@ const window_ = globals.window || globals.self || globals.global || {};
9
11
  const global_ = globals.global || globals.self || globals.window || {};
10
12
  const document_ = globals.document || {};
11
13
  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);
14
+
15
+ export const isBrowser =
16
+ Boolean(typeof process !== 'object' || String(process) !== '[object process]' || process.browser);
17
+
13
18
  export const isWorker = typeof importScripts === 'function';
19
+
14
20
  const matches = typeof process !== 'undefined' && process.version && /v([0-9]*)/.exec(process.version);
15
21
  export const nodeVersion = matches && parseFloat(matches[1]) || 0;
16
22
  //# sourceMappingURL=globals.js.map
@@ -1 +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
+ {"version":3,"file":"globals.js","names":["globals","self","window","global","document","self_","window_","global_","document_","isBrowser","Boolean","process","String","browser","isWorker","importScripts","matches","version","exec","nodeVersion","parseFloat"],"sources":["../../../../src/lib/env-utils/globals.ts"],"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"],"mappings":";;AAIA,MAAMA,OAAO,GAAG;EACdC,IAAI,EAAE,OAAOA,IAAI,KAAK,WAAW,IAAIA,IAAI;EACzCC,MAAM,EAAE,OAAOA,MAAM,KAAK,WAAW,IAAIA,MAAM;EAC/CC,MAAM,EAAE,OAAOA,MAAM,KAAK,WAAW,IAAIA,MAAM;EAC/CC,QAAQ,EAAE,OAAOA,QAAQ,KAAK,WAAW,IAAIA;AAC/C,CAAC;AAGD,MAAMC,KAAU,GAAGL,OAAO,CAACC,IAAI,IAAID,OAAO,CAACE,MAAM,IAAIF,OAAO,CAACG,MAAM,IAAI,CAAC,CAAC;AACzE,MAAMG,OAAY,GAAGN,OAAO,CAACE,MAAM,IAAIF,OAAO,CAACC,IAAI,IAAID,OAAO,CAACG,MAAM,IAAI,CAAC,CAAC;AAC3E,MAAMI,OAAY,GAAGP,OAAO,CAACG,MAAM,IAAIH,OAAO,CAACC,IAAI,IAAID,OAAO,CAACE,MAAM,IAAI,CAAC,CAAC;AAC3E,MAAMM,SAAc,GAAGR,OAAO,CAACI,QAAQ,IAAI,CAAC,CAAC;AAE7C,SAAQC,KAAK,IAAIJ,IAAI,EAAEK,OAAO,IAAIJ,MAAM,EAAEK,OAAO,IAAIJ,MAAM,EAAEK,SAAS,IAAIJ,QAAQ;;AAGlF,OAAO,MAAMK,SAAkB;AAE7BC,OAAO,CAAC,OAAOC,OAAO,KAAK,QAAQ,IAAIC,MAAM,CAACD,OAAO,CAAC,KAAK,kBAAkB,IAAIA,OAAO,CAACE,OAAO,CAAC;;AAGnG,OAAO,MAAMC,QAAiB,GAAG,OAAOC,aAAa,KAAK,UAAU;;AAGpE,MAAMC,OAAO,GACX,OAAOL,OAAO,KAAK,WAAW,IAAIA,OAAO,CAACM,OAAO,IAAI,WAAW,CAACC,IAAI,CAACP,OAAO,CAACM,OAAO,CAAC;AAExF,OAAO,MAAME,WAAmB,GAAIH,OAAO,IAAII,UAAU,CAACJ,OAAO,CAAC,CAAC,CAAC,CAAC,IAAK,CAAC"}
@@ -3,11 +3,11 @@ export default class NodeFileSystem {
3
3
  constructor(options) {
4
4
  this.fetch = options._fetch;
5
5
  }
6
-
7
- async readdir(dirname = '.', options) {
6
+ async readdir() {
7
+ let dirname = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '.';
8
+ let options = arguments.length > 1 ? arguments[1] : undefined;
8
9
  return await fs.readdir(dirname, options);
9
10
  }
10
-
11
11
  async stat(path, options) {
12
12
  const info = await fs.stat(path, options);
13
13
  return {
@@ -16,7 +16,6 @@ export default class NodeFileSystem {
16
16
  info
17
17
  };
18
18
  }
19
-
20
19
  async fetch(path, options) {
21
20
  const fallbackFetch = options.fetch || this.fetch;
22
21
  return fallbackFetch(path, options);
@@ -25,36 +24,31 @@ export default class NodeFileSystem {
25
24
  async open(path, flags, mode) {
26
25
  return await fs.open(path, flags);
27
26
  }
28
-
29
27
  async close(fd) {
30
28
  return await fs.close(fd);
31
29
  }
32
-
33
30
  async fstat(fd) {
34
31
  const info = await fs.fstat(fd);
35
32
  return info;
36
33
  }
37
-
38
- async read(fd, {
39
- buffer = null,
40
- offset = 0,
41
- length = buffer.byteLength,
42
- position = null
43
- }) {
34
+ async read(fd, _ref) {
35
+ let {
36
+ buffer = null,
37
+ offset = 0,
38
+ length = buffer.byteLength,
39
+ position = null
40
+ } = _ref;
44
41
  let totalBytesRead = 0;
45
-
46
42
  while (totalBytesRead < length) {
47
43
  const {
48
44
  bytesRead
49
45
  } = await fs.read(fd, buffer, offset + totalBytesRead, length - totalBytesRead, position + totalBytesRead);
50
46
  totalBytesRead += bytesRead;
51
47
  }
52
-
53
48
  return {
54
49
  bytesRead: totalBytesRead,
55
50
  buffer
56
51
  };
57
52
  }
58
-
59
53
  }
60
54
  //# sourceMappingURL=node-filesystem.js.map
@@ -1 +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,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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
+ {"version":3,"file":"node-filesystem.js","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"],"sources":["../../../../src/lib/filesystems/node-filesystem.ts"],"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"],"mappings":"AAAA,OAAO,KAAKA,EAAE,MAAM,YAAY;AAuBhC,eAAe,MAAMC,cAAc,CAAqD;EAEtFC,WAAW,CAACC,OAA6B,EAAE;IACzC,IAAI,CAACC,KAAK,GAAGD,OAAO,CAACE,MAAM;EAC7B;EAEA,MAAMC,OAAO,GAA8C;IAAA,IAA7CC,OAAO,uEAAG,GAAG;IAAA,IAAEJ,OAAY;IACvC,OAAO,MAAMH,EAAE,CAACM,OAAO,CAACC,OAAO,EAAEJ,OAAO,CAAC;EAC3C;EAEA,MAAMK,IAAI,CAACC,IAAY,EAAEN,OAAY,EAAiB;IACpD,MAAMO,IAAI,GAAG,MAAMV,EAAE,CAACQ,IAAI,CAACC,IAAI,EAAEN,OAAO,CAAC;IACzC,OAAO;MAACQ,IAAI,EAAEC,MAAM,CAACF,IAAI,CAACC,IAAI,CAAC;MAAEE,WAAW,EAAE,MAAM,KAAK;MAAEH;IAAI,CAAC;EAClE;EAEA,MAAMN,KAAK,CAACK,IAAY,EAAEN,OAA6B,EAAE;IAGvD,MAAMW,aAAa,GAAGX,OAAO,CAACC,KAAK,IAAI,IAAI,CAACA,KAAK;IACjD,OAAOU,aAAa,CAACL,IAAI,EAAEN,OAAO,CAAC;EACrC;;EAGA,MAAMY,IAAI,CAACN,IAAY,EAAEO,KAAsB,EAAEC,IAAU,EAAmB;IAC5E,OAAO,MAAMjB,EAAE,CAACe,IAAI,CAACN,IAAI,EAAEO,KAAK,CAAC;EACnC;EAEA,MAAME,KAAK,CAACC,EAAU,EAAiB;IACrC,OAAO,MAAMnB,EAAE,CAACkB,KAAK,CAACC,EAAE,CAAC;EAC3B;EAEA,MAAMC,KAAK,CAACD,EAAU,EAAiB;IACrC,MAAMT,IAAI,GAAG,MAAMV,EAAE,CAACoB,KAAK,CAACD,EAAE,CAAC;IAC/B,OAAOT,IAAI;EACb;EAEA,MAAMW,IAAI,CACRF,EAAU,QAGoC;IAAA,IAD9C;MAACG,MAAM,GAAG,IAAI;MAAEC,MAAM,GAAG,CAAC;MAAEC,MAAM,GAAGF,MAAM,CAACG,UAAU;MAAEC,QAAQ,GAAG;IAAiB,CAAC;IAErF,IAAIC,cAAc,GAAG,CAAC;IAEtB,OAAOA,cAAc,GAAGH,MAAM,EAAE;MAC9B,MAAM;QAACI;MAAS,CAAC,GAAG,MAAM5B,EAAE,CAACqB,IAAI,CAC/BF,EAAE,EACFG,MAAM,EACNC,MAAM,GAAGI,cAAc,EACvBH,MAAM,GAAGG,cAAc,EACvBD,QAAQ,GAAGC,cAAc,CAC1B;MACDA,cAAc,IAAIC,SAAS;IAC7B;IACA,OAAO;MAACA,SAAS,EAAED,cAAc;MAAEL;IAAM,CAAC;EAC5C;AACF"}
@@ -1,39 +1,34 @@
1
1
  import { concatenateArrayBuffers } from '../binary-utils/array-buffer-utils';
2
+
2
3
  export async function forEach(iterator, visitor) {
3
4
  while (true) {
4
5
  const {
5
6
  done,
6
7
  value
7
8
  } = await iterator.next();
8
-
9
9
  if (done) {
10
10
  iterator.return();
11
11
  return;
12
12
  }
13
-
14
13
  const cancel = visitor(value);
15
-
16
14
  if (cancel) {
17
15
  return;
18
16
  }
19
17
  }
20
18
  }
19
+
21
20
  export async function concatenateArrayBuffersAsync(asyncIterator) {
22
21
  const arrayBuffers = [];
23
-
24
22
  for await (const chunk of asyncIterator) {
25
23
  arrayBuffers.push(chunk);
26
24
  }
27
-
28
25
  return concatenateArrayBuffers(...arrayBuffers);
29
26
  }
30
27
  export async function concatenateStringsAsync(asyncIterator) {
31
28
  const strings = [];
32
-
33
29
  for await (const chunk of asyncIterator) {
34
30
  strings.push(chunk);
35
31
  }
36
-
37
32
  return strings.join('');
38
33
  }
39
34
  //# sourceMappingURL=async-iteration.js.map
@@ -1 +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"}
1
+ {"version":3,"file":"async-iteration.js","names":["concatenateArrayBuffers","forEach","iterator","visitor","done","value","next","return","cancel","concatenateArrayBuffersAsync","asyncIterator","arrayBuffers","chunk","push","concatenateStringsAsync","strings","join"],"sources":["../../../../src/lib/iterators/async-iteration.ts"],"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"],"mappings":"AAAA,SAAQA,uBAAuB,QAAO,oCAAoC;;AAgB1E,OAAO,eAAeC,OAAO,CAACC,QAAQ,EAAEC,OAAO,EAAE;EAE/C,OAAO,IAAI,EAAE;IACX,MAAM;MAACC,IAAI;MAAEC;IAAK,CAAC,GAAG,MAAMH,QAAQ,CAACI,IAAI,EAAE;IAC3C,IAAIF,IAAI,EAAE;MACRF,QAAQ,CAACK,MAAM,EAAE;MACjB;IACF;IACA,MAAMC,MAAM,GAAGL,OAAO,CAACE,KAAK,CAAC;IAC7B,IAAIG,MAAM,EAAE;MACV;IACF;EACF;AACF;;AASA,OAAO,eAAeC,4BAA4B,CAChDC,aAAiE,EAC3C;EACtB,MAAMC,YAA2B,GAAG,EAAE;EACtC,WAAW,MAAMC,KAAK,IAAIF,aAAa,EAAE;IACvCC,YAAY,CAACE,IAAI,CAACD,KAAK,CAAC;EAC1B;EACA,OAAOZ,uBAAuB,CAAC,GAAGW,YAAY,CAAC;AACjD;AAEA,OAAO,eAAeG,uBAAuB,CAC3CJ,aAAuD,EACtC;EACjB,MAAMK,OAAiB,GAAG,EAAE;EAC5B,WAAW,MAAMH,KAAK,IAAIF,aAAa,EAAE;IACvCK,OAAO,CAACF,IAAI,CAACD,KAAK,CAAC;EACrB;EACA,OAAOG,OAAO,CAACC,IAAI,CAAC,EAAE,CAAC;AACzB"}
@@ -1,40 +1,40 @@
1
- export async function* makeTextDecoderIterator(arrayBufferIterator, options = {}) {
2
- const textDecoder = new TextDecoder(undefined, options);
3
1
 
2
+
3
+ export async function* makeTextDecoderIterator(arrayBufferIterator) {
4
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
5
+ const textDecoder = new TextDecoder(undefined, options);
4
6
  for await (const arrayBuffer of arrayBufferIterator) {
5
7
  yield typeof arrayBuffer === 'string' ? arrayBuffer : textDecoder.decode(arrayBuffer, {
6
8
  stream: true
7
9
  });
8
10
  }
9
11
  }
12
+
10
13
  export async function* makeTextEncoderIterator(textIterator) {
11
14
  const textEncoder = new TextEncoder();
12
-
13
15
  for await (const text of textIterator) {
14
16
  yield typeof text === 'string' ? textEncoder.encode(text) : text;
15
17
  }
16
18
  }
19
+
17
20
  export async function* makeLineIterator(textIterator) {
18
21
  let previous = '';
19
-
20
22
  for await (const textChunk of textIterator) {
21
23
  previous += textChunk;
22
24
  let eolIndex;
23
-
24
25
  while ((eolIndex = previous.indexOf('\n')) >= 0) {
25
26
  const line = previous.slice(0, eolIndex + 1);
26
27
  previous = previous.slice(eolIndex + 1);
27
28
  yield line;
28
29
  }
29
30
  }
30
-
31
31
  if (previous.length > 0) {
32
32
  yield previous;
33
33
  }
34
34
  }
35
+
35
36
  export async function* makeNumberedLineIterator(lineIterator) {
36
37
  let counter = 1;
37
-
38
38
  for await (const line of lineIterator) {
39
39
  yield {
40
40
  counter,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/iterators/text-iterators.ts"],"names":["makeTextDecoderIterator","arrayBufferIterator","options","textDecoder","TextDecoder","undefined","arrayBuffer","decode","stream","makeTextEncoderIterator","textIterator","textEncoder","TextEncoder","text","encode","makeLineIterator","previous","textChunk","eolIndex","indexOf","line","slice","length","makeNumberedLineIterator","lineIterator","counter"],"mappings":"AAGA,OAAO,gBAAgBA,uBA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AG,CAAd;;AACA,aAAW,MAAML,IAAjB,IAAyBI,YAAzB,EAAuC;AACrC,UAAM;AAACC,MAAAA,OAAD;AAAUL,MAAAA;AAAV,KAAN;AACAK,IAAAA,OAAO;AACR;AACF","sourcesContent":["// TextDecoder iterators\n// TextDecoder will keep any partial undecoded bytes between calls to `decode`\n\nexport async function* makeTextDecoderIterator(\n arrayBufferIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,\n options: TextDecoderOptions = {}\n): AsyncIterable<string> {\n const textDecoder = new TextDecoder(undefined, options);\n for await (const arrayBuffer of arrayBufferIterator) {\n yield typeof arrayBuffer === 'string'\n ? arrayBuffer\n : textDecoder.decode(arrayBuffer, {stream: true});\n }\n}\n\n// TextEncoder iterator\n// TODO - this is not useful unless min chunk size is given\n// TextEncoder will keep any partial undecoded bytes between calls to `encode`\n// If iterator does not yield strings, assume arrayBuffer and return unencoded\n\nexport async function* makeTextEncoderIterator(\n textIterator: AsyncIterable<string> | Iterable<ArrayBuffer>\n): AsyncIterable<ArrayBuffer> {\n const textEncoder = new TextEncoder();\n for await (const text of textIterator) {\n yield typeof text === 'string' ? textEncoder.encode(text) : text;\n }\n}\n\n/**\n * @param textIterator async iterable yielding strings\n * @returns an async iterable over lines\n * See http://2ality.com/2018/04/async-iter-nodejs.html\n */\n\nexport async function* makeLineIterator(\n textIterator: AsyncIterable<string>\n): AsyncIterable<string> {\n let previous = '';\n for await (const textChunk of textIterator) {\n previous += textChunk;\n let eolIndex;\n while ((eolIndex = previous.indexOf('\\n')) >= 0) {\n // line includes the EOL\n const line = previous.slice(0, eolIndex + 1);\n previous = previous.slice(eolIndex + 1);\n yield line;\n }\n }\n\n if (previous.length > 0) {\n yield previous;\n }\n}\n\n/**\n * @param lineIterator async iterable yielding lines\n * @returns async iterable yielding numbered lines\n *\n * See http://2ality.com/2018/04/async-iter-nodejs.html\n */\nexport async function* makeNumberedLineIterator(\n lineIterator: AsyncIterable<string>\n): AsyncIterable<{counter: number; line: string}> {\n let counter = 1;\n for await (const line of lineIterator) {\n yield {counter, line};\n counter++;\n }\n}\n"],"file":"text-iterators.js"}
1
+ {"version":3,"file":"text-iterators.js","names":["makeTextDecoderIterator","arrayBufferIterator","options","textDecoder","TextDecoder","undefined","arrayBuffer","decode","stream","makeTextEncoderIterator","textIterator","textEncoder","TextEncoder","text","encode","makeLineIterator","previous","textChunk","eolIndex","indexOf","line","slice","length","makeNumberedLineIterator","lineIterator","counter"],"sources":["../../../../src/lib/iterators/text-iterators.ts"],"sourcesContent":["// TextDecoder iterators\n// TextDecoder will keep any partial undecoded bytes between calls to `decode`\n\nexport async function* makeTextDecoderIterator(\n arrayBufferIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,\n options: TextDecoderOptions = {}\n): AsyncIterable<string> {\n const textDecoder = new TextDecoder(undefined, options);\n for await (const arrayBuffer of arrayBufferIterator) {\n yield typeof arrayBuffer === 'string'\n ? arrayBuffer\n : textDecoder.decode(arrayBuffer, {stream: true});\n }\n}\n\n// TextEncoder iterator\n// TODO - this is not useful unless min chunk size is given\n// TextEncoder will keep any partial undecoded bytes between calls to `encode`\n// If iterator does not yield strings, assume arrayBuffer and return unencoded\n\nexport async function* makeTextEncoderIterator(\n textIterator: AsyncIterable<string> | Iterable<ArrayBuffer>\n): AsyncIterable<ArrayBuffer> {\n const textEncoder = new TextEncoder();\n for await (const text of textIterator) {\n yield typeof text === 'string' ? textEncoder.encode(text) : text;\n }\n}\n\n/**\n * @param textIterator async iterable yielding strings\n * @returns an async iterable over lines\n * See http://2ality.com/2018/04/async-iter-nodejs.html\n */\n\nexport async function* makeLineIterator(\n textIterator: AsyncIterable<string>\n): AsyncIterable<string> {\n let previous = '';\n for await (const textChunk of textIterator) {\n previous += textChunk;\n let eolIndex;\n while ((eolIndex = previous.indexOf('\\n')) >= 0) {\n // line includes the EOL\n const line = previous.slice(0, eolIndex + 1);\n previous = previous.slice(eolIndex + 1);\n yield line;\n }\n }\n\n if (previous.length > 0) {\n yield previous;\n }\n}\n\n/**\n * @param lineIterator async iterable yielding lines\n * @returns async iterable yielding numbered lines\n *\n * See http://2ality.com/2018/04/async-iter-nodejs.html\n */\nexport async function* makeNumberedLineIterator(\n lineIterator: AsyncIterable<string>\n): AsyncIterable<{counter: number; line: string}> {\n let counter = 1;\n for await (const line of lineIterator) {\n yield {counter, line};\n counter++;\n }\n}\n"],"mappings":";;AAGA,OAAO,gBAAgBA,uBAAuB,CAC5CC,mBAAuE,EAEhD;EAAA,IADvBC,OAA2B,uEAAG,CAAC,CAAC;EAEhC,MAAMC,WAAW,GAAG,IAAIC,WAAW,CAACC,SAAS,EAAEH,OAAO,CAAC;EACvD,WAAW,MAAMI,WAAW,IAAIL,mBAAmB,EAAE;IACnD,MAAM,OAAOK,WAAW,KAAK,QAAQ,GACjCA,WAAW,GACXH,WAAW,CAACI,MAAM,CAACD,WAAW,EAAE;MAACE,MAAM,EAAE;IAAI,CAAC,CAAC;EACrD;AACF;;AAOA,OAAO,gBAAgBC,uBAAuB,CAC5CC,YAA2D,EAC/B;EAC5B,MAAMC,WAAW,GAAG,IAAIC,WAAW,EAAE;EACrC,WAAW,MAAMC,IAAI,IAAIH,YAAY,EAAE;IACrC,MAAM,OAAOG,IAAI,KAAK,QAAQ,GAAGF,WAAW,CAACG,MAAM,CAACD,IAAI,CAAC,GAAGA,IAAI;EAClE;AACF;;AAQA,OAAO,gBAAgBE,gBAAgB,CACrCL,YAAmC,EACZ;EACvB,IAAIM,QAAQ,GAAG,EAAE;EACjB,WAAW,MAAMC,SAAS,IAAIP,YAAY,EAAE;IAC1CM,QAAQ,IAAIC,SAAS;IACrB,IAAIC,QAAQ;IACZ,OAAO,CAACA,QAAQ,GAAGF,QAAQ,CAACG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;MAE/C,MAAMC,IAAI,GAAGJ,QAAQ,CAACK,KAAK,CAAC,CAAC,EAAEH,QAAQ,GAAG,CAAC,CAAC;MAC5CF,QAAQ,GAAGA,QAAQ,CAACK,KAAK,CAACH,QAAQ,GAAG,CAAC,CAAC;MACvC,MAAME,IAAI;IACZ;EACF;EAEA,IAAIJ,QAAQ,CAACM,MAAM,GAAG,CAAC,EAAE;IACvB,MAAMN,QAAQ;EAChB;AACF;;AAQA,OAAO,gBAAgBO,wBAAwB,CAC7CC,YAAmC,EACa;EAChD,IAAIC,OAAO,GAAG,CAAC;EACf,WAAW,MAAML,IAAI,IAAII,YAAY,EAAE;IACrC,MAAM;MAACC,OAAO;MAAEL;IAAI,CAAC;IACrBK,OAAO,EAAE;EACX;AACF"}
@@ -1,28 +1,27 @@
1
+
2
+
1
3
  import { assert } from '../env-utils/assert';
4
+
2
5
  export function toArrayBuffer(buffer) {
3
6
  if (Buffer.isBuffer(buffer)) {
4
7
  const typedArray = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.length);
5
8
  return typedArray.slice().buffer;
6
9
  }
7
-
8
10
  return buffer;
9
11
  }
12
+
10
13
  export function toBuffer(binaryData) {
11
14
  if (ArrayBuffer.isView(binaryData)) {
12
15
  binaryData = binaryData.buffer;
13
16
  }
14
-
15
17
  if (typeof Buffer !== 'undefined' && binaryData instanceof ArrayBuffer) {
16
18
  const buffer = new Buffer(binaryData.byteLength);
17
19
  const view = new Uint8Array(binaryData);
18
-
19
20
  for (let i = 0; i < buffer.length; ++i) {
20
21
  buffer[i] = view[i];
21
22
  }
22
-
23
23
  return buffer;
24
24
  }
25
-
26
25
  return assert(false);
27
26
  }
28
27
  //# sourceMappingURL=buffer.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/node/buffer.ts"],"names":["assert","toArrayBuffer","buffer","Buffer","isBuffer","typedArray","Uint8Array","byteOffset","length","slice","toBuffer","binaryData","ArrayBuffer","isView","byteLength","view","i"],"mappings":"AAGA,SAAQA,MAAR,QAAqB,qBAArB;AAKA,OAAO,SAASC,aAAT,CAAuBC,MAAvB,EAA+B;AAEpC,MAAIC,MAAM,CAACC,QAAP,CAAgBF,MAAhB,CAAJ,EAA6B;AAC3B,UAAMG,UAAU,GAAG,IAAIC,UAAJ,CAAeJ,MAAM,CAACA,MAAtB,EAA8BA,MAAM,CAACK,UAArC,EAAiDL,MAAM,CAACM,MAAxD,CAAnB;AACA,WAAOH,UAAU,CAACI,KAAX,GAAmBP,MAA1B;AACD;;AACD,SAAOA,MAAP;AACD;AAKD,OAAO,SAASQ,QAAT,CAAkBC,UAAlB,EAA8B;AACnC,MAAIC,WAAW,CAACC,MAAZ,CAAmBF,UAAnB,CAAJ,EAAoC;AAClCA,IAAAA,UAAU,GAAGA,UAAU,CAACT,MAAxB;AACD;;AAED,MAAI,OAAOC,MAAP,KAAkB,WAAlB,IAAiCQ,UAAU,YAAYC,WAA3D,EAAwE;AACtE,UAAMV,MAAM,GAAG,IAAIC,MAAJ,CAAWQ,UAAU,CAACG,UAAtB,CAAf;AACA,UAAMC,IAAI,GAAG,IAAIT,UAAJ,CAAeK,UAAf,CAAb;;AACA,SAAK,IAAIK,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGd,MAAM,CAACM,MAA3B,EAAmC,EAAEQ,CAArC,EAAwC;AACtCd,MAAAA,MAAM,CAACc,CAAD,CAAN,GAAYD,IAAI,CAACC,CAAD,CAAhB;AACD;;AACD,WAAOd,MAAP;AACD;;AAED,SAAOF,MAAM,CAAC,KAAD,CAAb;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.buffer, buffer.byteOffset, buffer.length);\n return typedArray.slice().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"}
1
+ {"version":3,"file":"buffer.js","names":["assert","toArrayBuffer","buffer","Buffer","isBuffer","typedArray","Uint8Array","byteOffset","length","slice","toBuffer","binaryData","ArrayBuffer","isView","byteLength","view","i"],"sources":["../../../../src/lib/node/buffer.ts"],"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.buffer, buffer.byteOffset, buffer.length);\n return typedArray.slice().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"],"mappings":";;AAGA,SAAQA,MAAM,QAAO,qBAAqB;;AAK1C,OAAO,SAASC,aAAa,CAACC,MAAM,EAAE;EAEpC,IAAIC,MAAM,CAACC,QAAQ,CAACF,MAAM,CAAC,EAAE;IAC3B,MAAMG,UAAU,GAAG,IAAIC,UAAU,CAACJ,MAAM,CAACA,MAAM,EAAEA,MAAM,CAACK,UAAU,EAAEL,MAAM,CAACM,MAAM,CAAC;IAClF,OAAOH,UAAU,CAACI,KAAK,EAAE,CAACP,MAAM;EAClC;EACA,OAAOA,MAAM;AACf;;AAKA,OAAO,SAASQ,QAAQ,CAACC,UAAU,EAAE;EACnC,IAAIC,WAAW,CAACC,MAAM,CAACF,UAAU,CAAC,EAAE;IAClCA,UAAU,GAAGA,UAAU,CAACT,MAAM;EAChC;EAEA,IAAI,OAAOC,MAAM,KAAK,WAAW,IAAIQ,UAAU,YAAYC,WAAW,EAAE;IACtE,MAAMV,MAAM,GAAG,IAAIC,MAAM,CAACQ,UAAU,CAACG,UAAU,CAAC;IAChD,MAAMC,IAAI,GAAG,IAAIT,UAAU,CAACK,UAAU,CAAC;IACvC,KAAK,IAAIK,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGd,MAAM,CAACM,MAAM,EAAE,EAAEQ,CAAC,EAAE;MACtCd,MAAM,CAACc,CAAC,CAAC,GAAGD,IAAI,CAACC,CAAC,CAAC;IACrB;IACA,OAAOd,MAAM;EACf;EAEA,OAAOF,MAAM,CAAC,KAAK,CAAC;AACtB"}