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

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 (252) hide show
  1. package/dist/es5/index.js +328 -0
  2. package/dist/es5/index.js.map +1 -0
  3. package/dist/es5/json-loader.js +44 -0
  4. package/dist/es5/json-loader.js.map +1 -0
  5. package/dist/es5/lib/binary-utils/array-buffer-utils.js +80 -0
  6. package/dist/es5/lib/binary-utils/array-buffer-utils.js.map +1 -0
  7. package/dist/es5/lib/binary-utils/dataview-copy-utils.js +58 -0
  8. package/dist/es5/lib/binary-utils/dataview-copy-utils.js.map +1 -0
  9. package/dist/es5/lib/binary-utils/get-first-characters.js +31 -0
  10. package/dist/es5/lib/binary-utils/get-first-characters.js.map +1 -0
  11. package/dist/es5/lib/binary-utils/memory-conversion-utils.js +44 -0
  12. package/dist/es5/lib/binary-utils/memory-conversion-utils.js.map +1 -0
  13. package/dist/es5/lib/binary-utils/memory-copy-utils.js +34 -0
  14. package/dist/es5/lib/binary-utils/memory-copy-utils.js.map +1 -0
  15. package/dist/es5/lib/env-utils/assert.js +12 -0
  16. package/dist/es5/lib/env-utils/assert.js.map +1 -0
  17. package/dist/es5/lib/env-utils/globals.js +30 -0
  18. package/dist/es5/lib/env-utils/globals.js.map +1 -0
  19. package/dist/es5/lib/filesystems/node-filesystem.js +210 -0
  20. package/dist/es5/lib/filesystems/node-filesystem.js.map +1 -0
  21. package/dist/es5/lib/filesystems/readable-file.js +91 -0
  22. package/dist/es5/lib/filesystems/readable-file.js.map +1 -0
  23. package/dist/es5/lib/filesystems/writable-file.js +82 -0
  24. package/dist/es5/lib/filesystems/writable-file.js.map +1 -0
  25. package/dist/es5/lib/iterators/async-iteration.js +190 -0
  26. package/dist/es5/lib/iterators/async-iteration.js.map +1 -0
  27. package/dist/es5/lib/iterators/text-iterators.js +305 -0
  28. package/dist/es5/lib/iterators/text-iterators.js.map +1 -0
  29. package/dist/es5/lib/node/buffer.browser.js +14 -0
  30. package/dist/es5/lib/node/buffer.browser.js.map +1 -0
  31. package/dist/es5/lib/node/buffer.js +27 -0
  32. package/dist/es5/lib/node/buffer.js.map +1 -0
  33. package/dist/es5/lib/node/fs.js +88 -0
  34. package/dist/es5/lib/node/fs.js.map +1 -0
  35. package/dist/es5/lib/node/promisify.js +36 -0
  36. package/dist/es5/lib/node/promisify.js.map +1 -0
  37. package/dist/es5/lib/node/stream.js +16 -0
  38. package/dist/es5/lib/node/stream.js.map +1 -0
  39. package/dist/es5/lib/option-utils/merge-loader-options.js +30 -0
  40. package/dist/es5/lib/option-utils/merge-loader-options.js.map +1 -0
  41. package/dist/es5/lib/parser-utils/parse-json.js +15 -0
  42. package/dist/es5/lib/parser-utils/parse-json.js.map +1 -0
  43. package/dist/es5/lib/path-utils/file-aliases.js +33 -0
  44. package/dist/es5/lib/path-utils/file-aliases.js.map +1 -0
  45. package/dist/es5/lib/path-utils/get-cwd.js +15 -0
  46. package/dist/es5/lib/path-utils/get-cwd.js.map +1 -0
  47. package/dist/es5/lib/path-utils/path.js +136 -0
  48. package/dist/es5/lib/path-utils/path.js.map +1 -0
  49. package/dist/es5/lib/request-utils/request-scheduler.js +150 -0
  50. package/dist/es5/lib/request-utils/request-scheduler.js.map +1 -0
  51. package/dist/es5/lib/worker-loader-utils/create-loader-worker.js +142 -0
  52. package/dist/es5/lib/worker-loader-utils/create-loader-worker.js.map +1 -0
  53. package/dist/es5/lib/worker-loader-utils/encode-with-worker.js +18 -0
  54. package/dist/es5/lib/worker-loader-utils/encode-with-worker.js.map +1 -0
  55. package/dist/es5/lib/worker-loader-utils/parse-with-worker.js +115 -0
  56. package/dist/es5/lib/worker-loader-utils/parse-with-worker.js.map +1 -0
  57. package/dist/es5/types.js +2 -0
  58. package/dist/es5/types.js.map +1 -0
  59. package/dist/es5/workers/json-worker.js +6 -0
  60. package/dist/es5/workers/json-worker.js.map +1 -0
  61. package/dist/esm/index.js +29 -0
  62. package/dist/esm/index.js.map +1 -0
  63. package/dist/esm/json-loader.js +18 -0
  64. package/dist/esm/json-loader.js.map +1 -0
  65. package/dist/esm/lib/binary-utils/array-buffer-utils.js +52 -0
  66. package/dist/esm/lib/binary-utils/array-buffer-utils.js.map +1 -0
  67. package/dist/{lib/binary-utils/binary-copy-utils.js → esm/lib/binary-utils/dataview-copy-utils.js} +27 -4
  68. package/dist/esm/lib/binary-utils/dataview-copy-utils.js.map +1 -0
  69. package/dist/esm/lib/binary-utils/get-first-characters.js +24 -0
  70. package/dist/esm/lib/binary-utils/get-first-characters.js.map +1 -0
  71. package/dist/esm/lib/binary-utils/memory-conversion-utils.js +31 -0
  72. package/dist/esm/lib/binary-utils/memory-conversion-utils.js.map +1 -0
  73. package/dist/esm/lib/binary-utils/memory-copy-utils.js +26 -0
  74. package/dist/esm/lib/binary-utils/memory-copy-utils.js.map +1 -0
  75. package/dist/esm/lib/env-utils/assert.js +6 -0
  76. package/dist/esm/lib/env-utils/assert.js.map +1 -0
  77. package/dist/esm/lib/env-utils/globals.js +16 -0
  78. package/dist/esm/lib/env-utils/globals.js.map +1 -0
  79. package/dist/esm/lib/filesystems/node-filesystem.js +53 -0
  80. package/dist/esm/lib/filesystems/node-filesystem.js.map +1 -0
  81. package/dist/esm/lib/filesystems/readable-file.js +20 -0
  82. package/dist/esm/lib/filesystems/readable-file.js.map +1 -0
  83. package/dist/esm/lib/filesystems/writable-file.js +20 -0
  84. package/dist/esm/lib/filesystems/writable-file.js.map +1 -0
  85. package/dist/esm/lib/iterators/async-iteration.js +32 -0
  86. package/dist/esm/lib/iterators/async-iteration.js.map +1 -0
  87. package/dist/esm/lib/iterators/text-iterators.js +47 -0
  88. package/dist/esm/lib/iterators/text-iterators.js.map +1 -0
  89. package/dist/esm/lib/node/buffer.browser.js +7 -0
  90. package/dist/esm/lib/node/buffer.browser.js.map +1 -0
  91. package/dist/esm/lib/node/buffer.js +20 -0
  92. package/dist/esm/lib/node/buffer.js.map +1 -0
  93. package/dist/esm/lib/node/fs.js +40 -0
  94. package/dist/esm/lib/node/fs.js.map +1 -0
  95. package/dist/esm/lib/node/promisify.js +10 -0
  96. package/dist/esm/lib/node/promisify.js.map +1 -0
  97. package/dist/esm/lib/node/stream.js +7 -0
  98. package/dist/esm/lib/node/stream.js.map +1 -0
  99. package/dist/esm/lib/option-utils/merge-loader-options.js +17 -0
  100. package/dist/esm/lib/option-utils/merge-loader-options.js.map +1 -0
  101. package/dist/esm/lib/parser-utils/parse-json.js +9 -0
  102. package/dist/esm/lib/parser-utils/parse-json.js.map +1 -0
  103. package/dist/esm/lib/path-utils/file-aliases.js +24 -0
  104. package/dist/esm/lib/path-utils/file-aliases.js.map +1 -0
  105. package/dist/esm/lib/path-utils/get-cwd.js +9 -0
  106. package/dist/esm/lib/path-utils/get-cwd.js.map +1 -0
  107. package/dist/esm/lib/path-utils/path.js +127 -0
  108. package/dist/esm/lib/path-utils/path.js.map +1 -0
  109. package/dist/esm/lib/request-utils/request-scheduler.js +120 -0
  110. package/dist/esm/lib/request-utils/request-scheduler.js.map +1 -0
  111. package/dist/esm/lib/worker-loader-utils/create-loader-worker.js +95 -0
  112. package/dist/esm/lib/worker-loader-utils/create-loader-worker.js.map +1 -0
  113. package/dist/esm/lib/worker-loader-utils/encode-with-worker.js +12 -0
  114. package/dist/esm/lib/worker-loader-utils/encode-with-worker.js.map +1 -0
  115. package/dist/esm/lib/worker-loader-utils/parse-with-worker.js +63 -0
  116. package/dist/esm/lib/worker-loader-utils/parse-with-worker.js.map +1 -0
  117. package/dist/esm/types.js +2 -0
  118. package/dist/esm/types.js.map +1 -0
  119. package/dist/esm/workers/json-worker.js +4 -0
  120. package/dist/esm/workers/json-worker.js.map +1 -0
  121. package/dist/index.d.ts +13 -8
  122. package/dist/index.d.ts.map +1 -1
  123. package/dist/index.js +122 -26
  124. package/dist/json-loader.d.ts +4 -17
  125. package/dist/json-loader.d.ts.map +1 -1
  126. package/dist/json-loader.js +24 -18
  127. package/dist/lib/binary-utils/array-buffer-utils.d.ts +4 -8
  128. package/dist/lib/binary-utils/array-buffer-utils.d.ts.map +1 -1
  129. package/dist/lib/binary-utils/array-buffer-utils.js +78 -80
  130. package/dist/lib/binary-utils/dataview-copy-utils.d.ts +43 -0
  131. package/dist/lib/binary-utils/dataview-copy-utils.d.ts.map +1 -0
  132. package/dist/lib/binary-utils/dataview-copy-utils.js +97 -0
  133. package/dist/lib/binary-utils/get-first-characters.d.ts +15 -1
  134. package/dist/lib/binary-utils/get-first-characters.d.ts.map +1 -1
  135. package/dist/lib/binary-utils/get-first-characters.js +43 -25
  136. package/dist/lib/binary-utils/{buffer-utils.d.ts → memory-conversion-utils.d.ts} +3 -4
  137. package/dist/lib/binary-utils/memory-conversion-utils.d.ts.map +1 -0
  138. package/dist/lib/binary-utils/memory-conversion-utils.js +73 -0
  139. package/dist/lib/binary-utils/memory-copy-utils.js +58 -24
  140. package/dist/lib/env-utils/assert.js +12 -5
  141. package/dist/lib/env-utils/globals.d.ts +1 -1
  142. package/dist/lib/env-utils/globals.d.ts.map +1 -1
  143. package/dist/lib/env-utils/globals.js +23 -9
  144. package/dist/lib/filesystems/node-filesystem.d.ts +3 -2
  145. package/dist/lib/filesystems/node-filesystem.d.ts.map +1 -1
  146. package/dist/lib/filesystems/node-filesystem.js +72 -59
  147. package/dist/lib/filesystems/readable-file.d.ts +10 -0
  148. package/dist/lib/filesystems/readable-file.d.ts.map +1 -0
  149. package/dist/lib/filesystems/readable-file.js +25 -0
  150. package/dist/lib/filesystems/writable-file.d.ts +18 -0
  151. package/dist/lib/filesystems/writable-file.d.ts.map +1 -0
  152. package/dist/lib/filesystems/writable-file.js +48 -0
  153. package/dist/lib/iterators/async-iteration.js +49 -35
  154. package/dist/lib/iterators/text-iterators.js +56 -41
  155. package/dist/lib/node/buffer.browser.d.ts +12 -0
  156. package/dist/lib/node/buffer.browser.d.ts.map +1 -0
  157. package/dist/lib/node/buffer.browser.js +22 -0
  158. package/dist/lib/node/buffer.d.ts +3 -1
  159. package/dist/lib/node/buffer.d.ts.map +1 -1
  160. package/dist/lib/node/buffer.js +33 -25
  161. package/dist/lib/node/fs.d.ts +4 -2
  162. package/dist/lib/node/fs.d.ts.map +1 -1
  163. package/dist/lib/node/fs.js +47 -40
  164. package/dist/lib/node/promisify.d.ts +13 -0
  165. package/dist/lib/node/promisify.d.ts.map +1 -0
  166. package/dist/lib/node/promisify.js +22 -0
  167. package/dist/lib/node/stream.d.ts +4 -0
  168. package/dist/lib/node/stream.d.ts.map +1 -0
  169. package/dist/lib/node/stream.js +17 -0
  170. package/dist/lib/option-utils/merge-loader-options.d.ts +9 -0
  171. package/dist/lib/option-utils/merge-loader-options.d.ts.map +1 -0
  172. package/dist/lib/option-utils/merge-loader-options.js +27 -0
  173. package/dist/lib/parser-utils/parse-json.js +15 -8
  174. package/dist/lib/path-utils/file-aliases.js +40 -19
  175. package/dist/lib/path-utils/get-cwd.d.ts +2 -0
  176. package/dist/lib/path-utils/get-cwd.d.ts.map +1 -0
  177. package/dist/lib/path-utils/get-cwd.js +12 -0
  178. package/dist/lib/path-utils/path.d.ts +8 -0
  179. package/dist/lib/path-utils/path.d.ts.map +1 -1
  180. package/dist/lib/path-utils/path.js +173 -19
  181. package/dist/lib/request-utils/request-scheduler.d.ts +6 -6
  182. package/dist/lib/request-utils/request-scheduler.d.ts.map +1 -1
  183. package/dist/lib/request-utils/request-scheduler.js +127 -131
  184. package/dist/lib/worker-loader-utils/create-loader-worker.d.ts.map +1 -1
  185. package/dist/lib/worker-loader-utils/create-loader-worker.js +92 -96
  186. package/dist/lib/worker-loader-utils/encode-with-worker.d.ts +8 -0
  187. package/dist/lib/worker-loader-utils/encode-with-worker.d.ts.map +1 -0
  188. package/dist/lib/worker-loader-utils/encode-with-worker.js +21 -0
  189. package/dist/lib/worker-loader-utils/parse-with-worker.d.ts.map +1 -1
  190. package/dist/lib/worker-loader-utils/parse-with-worker.js +77 -60
  191. package/dist/types.d.ts +85 -72
  192. package/dist/types.d.ts.map +1 -1
  193. package/dist/types.js +3 -2
  194. package/dist/workers/json-worker.js +5 -4
  195. package/package.json +12 -19
  196. package/src/index.ts +32 -18
  197. package/src/json-loader.ts +5 -4
  198. package/src/lib/binary-utils/array-buffer-utils.ts +4 -40
  199. package/src/lib/binary-utils/{binary-copy-utils.ts → dataview-copy-utils.ts} +57 -5
  200. package/src/lib/binary-utils/get-first-characters.ts +17 -1
  201. package/src/lib/binary-utils/memory-conversion-utils.ts +53 -0
  202. package/src/lib/filesystems/readable-file.ts +30 -0
  203. package/src/lib/filesystems/writable-file.ts +44 -0
  204. package/src/lib/node/buffer.browser.ts +20 -0
  205. package/src/lib/node/buffer.ts +12 -11
  206. package/src/lib/node/fs.ts +16 -11
  207. package/src/lib/node/promisify.ts +70 -0
  208. package/src/lib/node/stream.ts +18 -0
  209. package/src/lib/option-utils/merge-loader-options.ts +35 -0
  210. package/src/lib/path-utils/get-cwd.ts +9 -0
  211. package/src/lib/path-utils/path.ts +138 -4
  212. package/src/lib/worker-loader-utils/create-loader-worker.ts +3 -2
  213. package/src/lib/worker-loader-utils/encode-with-worker.ts +21 -0
  214. package/src/lib/worker-loader-utils/parse-with-worker.ts +15 -2
  215. package/src/types.ts +156 -93
  216. package/dist/index.js.map +0 -1
  217. package/dist/json-loader.js.map +0 -1
  218. package/dist/lib/binary-utils/array-buffer-utils.js.map +0 -1
  219. package/dist/lib/binary-utils/binary-copy-utils.d.ts +0 -24
  220. package/dist/lib/binary-utils/binary-copy-utils.d.ts.map +0 -1
  221. package/dist/lib/binary-utils/binary-copy-utils.js.map +0 -1
  222. package/dist/lib/binary-utils/buffer-utils.d.ts.map +0 -1
  223. package/dist/lib/binary-utils/buffer-utils.js +0 -16
  224. package/dist/lib/binary-utils/buffer-utils.js.map +0 -1
  225. package/dist/lib/binary-utils/encode-utils.d.ts +0 -4
  226. package/dist/lib/binary-utils/encode-utils.d.ts.map +0 -1
  227. package/dist/lib/binary-utils/encode-utils.js +0 -31
  228. package/dist/lib/binary-utils/encode-utils.js.map +0 -1
  229. package/dist/lib/binary-utils/get-first-characters.js.map +0 -1
  230. package/dist/lib/binary-utils/memory-copy-utils.js.map +0 -1
  231. package/dist/lib/env-utils/assert.js.map +0 -1
  232. package/dist/lib/env-utils/globals.js.map +0 -1
  233. package/dist/lib/filesystems/node-filesystem.js.map +0 -1
  234. package/dist/lib/iterators/async-iteration.js.map +0 -1
  235. package/dist/lib/iterators/text-iterators.js.map +0 -1
  236. package/dist/lib/node/buffer.js.map +0 -1
  237. package/dist/lib/node/fs.js.map +0 -1
  238. package/dist/lib/node/util.d.ts +0 -5
  239. package/dist/lib/node/util.d.ts.map +0 -1
  240. package/dist/lib/node/util.js +0 -3
  241. package/dist/lib/node/util.js.map +0 -1
  242. package/dist/lib/parser-utils/parse-json.js.map +0 -1
  243. package/dist/lib/path-utils/file-aliases.js.map +0 -1
  244. package/dist/lib/path-utils/path.js.map +0 -1
  245. package/dist/lib/request-utils/request-scheduler.js.map +0 -1
  246. package/dist/lib/worker-loader-utils/create-loader-worker.js.map +0 -1
  247. package/dist/lib/worker-loader-utils/parse-with-worker.js.map +0 -1
  248. package/dist/types.js.map +0 -1
  249. package/dist/workers/json-worker.js.map +0 -1
  250. package/src/lib/binary-utils/buffer-utils.ts +0 -28
  251. package/src/lib/binary-utils/encode-utils.ts +0 -32
  252. package/src/lib/node/util.ts +0 -4
package/dist/index.js CHANGED
@@ -1,26 +1,122 @@
1
- export { assert } from './lib/env-utils/assert';
2
- export { isBrowser, isWorker, nodeVersion, self, window, global, document } from './lib/env-utils/globals';
3
- export { createLoaderWorker } from './lib/worker-loader-utils/create-loader-worker';
4
- export { parseWithWorker, canParseWithWorker } from './lib/worker-loader-utils/parse-with-worker';
5
- export { parseJSON } from './lib/parser-utils/parse-json';
6
- export { toArrayBuffer, sliceArrayBuffer, concatenateArrayBuffers, concatenateTypedArrays, compareArrayBuffers } from './lib/binary-utils/array-buffer-utils';
7
- export { padToNBytes, copyToArray, copyArrayBuffer } from './lib/binary-utils/memory-copy-utils';
8
- export { copyPaddedArrayBufferToDataView, copyPaddedStringToDataView } from './lib/binary-utils/binary-copy-utils';
9
- export { padStringToByteAlignment, copyStringToDataView, copyBinaryToDataView } from './lib/binary-utils/encode-utils';
10
- export { getFirstCharacters, getMagicString } from './lib/binary-utils/get-first-characters';
11
- export { makeTextEncoderIterator, makeTextDecoderIterator, makeLineIterator, makeNumberedLineIterator } from './lib/iterators/text-iterators';
12
- export { forEach, concatenateArrayBuffersAsync } from './lib/iterators/async-iteration';
13
- export { default as RequestScheduler } from './lib/request-utils/request-scheduler';
14
- export { setPathPrefix, getPathPrefix, resolvePath } from './lib/path-utils/file-aliases';
15
- export { addAliases as _addAliases } from './lib/path-utils/file-aliases';
16
- export { JSONLoader } from './json-loader';
17
- import * as path from './lib/path-utils/path';
18
- export { path };
19
- export { isBuffer, toBuffer, bufferToArrayBuffer } from './lib/binary-utils/buffer-utils';
20
- import * as util from './lib/node/util';
21
- export { util };
22
- export { promisify } from './lib/node/util';
23
- import * as fs from './lib/node/fs';
24
- export { fs };
25
- export { default as _NodeFileSystem } from './lib/filesystems/node-filesystem';
26
- //# sourceMappingURL=index.js.map
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.makeWritableFile = exports.makeReadableFile = exports.stream = exports.fs = exports.path = exports.promisify2 = exports.promisify1 = exports.toArrayBuffer = exports.toBuffer = exports.isBuffer = exports.JSONLoader = exports._addAliases = exports.resolvePath = exports.getPathPrefix = exports.setPathPrefix = exports.RequestScheduler = exports.concatenateArrayBuffersAsync = exports.forEach = exports.makeNumberedLineIterator = exports.makeLineIterator = exports.makeTextDecoderIterator = exports.makeTextEncoderIterator = exports.getMagicString = exports.getFirstCharacters = exports.copyPaddedStringToDataView = exports.copyPaddedArrayBufferToDataView = exports.copyBinaryToDataView = exports.copyStringToDataView = exports.padStringToByteAlignment = exports.copyArrayBuffer = exports.copyToArray = exports.padToNBytes = exports.compareArrayBuffers = exports.concatenateTypedArrays = exports.concatenateArrayBuffers = exports.sliceArrayBuffer = exports.parseJSON = exports.canEncodeWithWorker = exports.canParseWithWorker = exports.parseWithWorker = exports.createLoaderWorker = exports.mergeLoaderOptions = exports.document = exports.global = exports.window = exports.self = exports.nodeVersion = exports.isWorker = exports.isBrowser = exports.assert = void 0;
30
+ exports._NodeFileSystem = void 0;
31
+ // GENERAL UTILS
32
+ var assert_1 = require("./lib/env-utils/assert");
33
+ Object.defineProperty(exports, "assert", { enumerable: true, get: function () { return assert_1.assert; } });
34
+ var globals_1 = require("./lib/env-utils/globals");
35
+ Object.defineProperty(exports, "isBrowser", { enumerable: true, get: function () { return globals_1.isBrowser; } });
36
+ Object.defineProperty(exports, "isWorker", { enumerable: true, get: function () { return globals_1.isWorker; } });
37
+ Object.defineProperty(exports, "nodeVersion", { enumerable: true, get: function () { return globals_1.nodeVersion; } });
38
+ Object.defineProperty(exports, "self", { enumerable: true, get: function () { return globals_1.self; } });
39
+ Object.defineProperty(exports, "window", { enumerable: true, get: function () { return globals_1.window; } });
40
+ Object.defineProperty(exports, "global", { enumerable: true, get: function () { return globals_1.global; } });
41
+ Object.defineProperty(exports, "document", { enumerable: true, get: function () { return globals_1.document; } });
42
+ var merge_loader_options_1 = require("./lib/option-utils/merge-loader-options");
43
+ Object.defineProperty(exports, "mergeLoaderOptions", { enumerable: true, get: function () { return merge_loader_options_1.mergeLoaderOptions; } });
44
+ // LOADERS.GL-SPECIFIC WORKER UTILS
45
+ var create_loader_worker_1 = require("./lib/worker-loader-utils/create-loader-worker");
46
+ Object.defineProperty(exports, "createLoaderWorker", { enumerable: true, get: function () { return create_loader_worker_1.createLoaderWorker; } });
47
+ var parse_with_worker_1 = require("./lib/worker-loader-utils/parse-with-worker");
48
+ Object.defineProperty(exports, "parseWithWorker", { enumerable: true, get: function () { return parse_with_worker_1.parseWithWorker; } });
49
+ Object.defineProperty(exports, "canParseWithWorker", { enumerable: true, get: function () { return parse_with_worker_1.canParseWithWorker; } });
50
+ var encode_with_worker_1 = require("./lib/worker-loader-utils/encode-with-worker");
51
+ Object.defineProperty(exports, "canEncodeWithWorker", { enumerable: true, get: function () { return encode_with_worker_1.canEncodeWithWorker; } });
52
+ // PARSER UTILS
53
+ var parse_json_1 = require("./lib/parser-utils/parse-json");
54
+ Object.defineProperty(exports, "parseJSON", { enumerable: true, get: function () { return parse_json_1.parseJSON; } });
55
+ // MEMORY COPY UTILS
56
+ var array_buffer_utils_1 = require("./lib/binary-utils/array-buffer-utils");
57
+ Object.defineProperty(exports, "sliceArrayBuffer", { enumerable: true, get: function () { return array_buffer_utils_1.sliceArrayBuffer; } });
58
+ Object.defineProperty(exports, "concatenateArrayBuffers", { enumerable: true, get: function () { return array_buffer_utils_1.concatenateArrayBuffers; } });
59
+ Object.defineProperty(exports, "concatenateTypedArrays", { enumerable: true, get: function () { return array_buffer_utils_1.concatenateTypedArrays; } });
60
+ Object.defineProperty(exports, "compareArrayBuffers", { enumerable: true, get: function () { return array_buffer_utils_1.compareArrayBuffers; } });
61
+ var memory_copy_utils_1 = require("./lib/binary-utils/memory-copy-utils");
62
+ Object.defineProperty(exports, "padToNBytes", { enumerable: true, get: function () { return memory_copy_utils_1.padToNBytes; } });
63
+ Object.defineProperty(exports, "copyToArray", { enumerable: true, get: function () { return memory_copy_utils_1.copyToArray; } });
64
+ Object.defineProperty(exports, "copyArrayBuffer", { enumerable: true, get: function () { return memory_copy_utils_1.copyArrayBuffer; } });
65
+ var dataview_copy_utils_1 = require("./lib/binary-utils/dataview-copy-utils");
66
+ Object.defineProperty(exports, "padStringToByteAlignment", { enumerable: true, get: function () { return dataview_copy_utils_1.padStringToByteAlignment; } });
67
+ Object.defineProperty(exports, "copyStringToDataView", { enumerable: true, get: function () { return dataview_copy_utils_1.copyStringToDataView; } });
68
+ Object.defineProperty(exports, "copyBinaryToDataView", { enumerable: true, get: function () { return dataview_copy_utils_1.copyBinaryToDataView; } });
69
+ Object.defineProperty(exports, "copyPaddedArrayBufferToDataView", { enumerable: true, get: function () { return dataview_copy_utils_1.copyPaddedArrayBufferToDataView; } });
70
+ Object.defineProperty(exports, "copyPaddedStringToDataView", { enumerable: true, get: function () { return dataview_copy_utils_1.copyPaddedStringToDataView; } });
71
+ var get_first_characters_1 = require("./lib/binary-utils/get-first-characters");
72
+ Object.defineProperty(exports, "getFirstCharacters", { enumerable: true, get: function () { return get_first_characters_1.getFirstCharacters; } });
73
+ Object.defineProperty(exports, "getMagicString", { enumerable: true, get: function () { return get_first_characters_1.getMagicString; } });
74
+ // ITERATOR UTILS
75
+ var text_iterators_1 = require("./lib/iterators/text-iterators");
76
+ Object.defineProperty(exports, "makeTextEncoderIterator", { enumerable: true, get: function () { return text_iterators_1.makeTextEncoderIterator; } });
77
+ Object.defineProperty(exports, "makeTextDecoderIterator", { enumerable: true, get: function () { return text_iterators_1.makeTextDecoderIterator; } });
78
+ Object.defineProperty(exports, "makeLineIterator", { enumerable: true, get: function () { return text_iterators_1.makeLineIterator; } });
79
+ Object.defineProperty(exports, "makeNumberedLineIterator", { enumerable: true, get: function () { return text_iterators_1.makeNumberedLineIterator; } });
80
+ var async_iteration_1 = require("./lib/iterators/async-iteration");
81
+ Object.defineProperty(exports, "forEach", { enumerable: true, get: function () { return async_iteration_1.forEach; } });
82
+ Object.defineProperty(exports, "concatenateArrayBuffersAsync", { enumerable: true, get: function () { return async_iteration_1.concatenateArrayBuffersAsync; } });
83
+ // REQUEST UTILS
84
+ var request_scheduler_1 = require("./lib/request-utils/request-scheduler");
85
+ Object.defineProperty(exports, "RequestScheduler", { enumerable: true, get: function () { return __importDefault(request_scheduler_1).default; } });
86
+ // PATH HELPERS
87
+ var file_aliases_1 = require("./lib/path-utils/file-aliases");
88
+ Object.defineProperty(exports, "setPathPrefix", { enumerable: true, get: function () { return file_aliases_1.setPathPrefix; } });
89
+ Object.defineProperty(exports, "getPathPrefix", { enumerable: true, get: function () { return file_aliases_1.getPathPrefix; } });
90
+ Object.defineProperty(exports, "resolvePath", { enumerable: true, get: function () { return file_aliases_1.resolvePath; } });
91
+ var file_aliases_2 = require("./lib/path-utils/file-aliases");
92
+ Object.defineProperty(exports, "_addAliases", { enumerable: true, get: function () { return file_aliases_2.addAliases; } });
93
+ // MICRO LOADERS
94
+ var json_loader_1 = require("./json-loader");
95
+ Object.defineProperty(exports, "JSONLoader", { enumerable: true, get: function () { return json_loader_1.JSONLoader; } });
96
+ // NODE support
97
+ // Node.js emulation (can be used in browser)
98
+ // Avoid direct use of `Buffer` which pulls in 50KB polyfill
99
+ var memory_conversion_utils_1 = require("./lib/binary-utils/memory-conversion-utils");
100
+ Object.defineProperty(exports, "isBuffer", { enumerable: true, get: function () { return memory_conversion_utils_1.isBuffer; } });
101
+ Object.defineProperty(exports, "toBuffer", { enumerable: true, get: function () { return memory_conversion_utils_1.toBuffer; } });
102
+ Object.defineProperty(exports, "toArrayBuffer", { enumerable: true, get: function () { return memory_conversion_utils_1.toArrayBuffer; } });
103
+ // Note.js wrappers (can be safely imported, but not used in browser)
104
+ // Use instead of importing 'util' to avoid node dependencies
105
+ var promisify_1 = require("./lib/node/promisify");
106
+ Object.defineProperty(exports, "promisify1", { enumerable: true, get: function () { return promisify_1.promisify1; } });
107
+ Object.defineProperty(exports, "promisify2", { enumerable: true, get: function () { return promisify_1.promisify2; } });
108
+ // `path` replacement (avoids bundling big path polyfill)
109
+ const path = __importStar(require("./lib/path-utils/path"));
110
+ exports.path = path;
111
+ // Use instead of importing 'fs' to avoid node dependencies`
112
+ const fs = __importStar(require("./lib/node/fs"));
113
+ exports.fs = fs;
114
+ // Use instead of importing 'stream' to avoid node dependencies`
115
+ const stream = __importStar(require("./lib/node/stream"));
116
+ exports.stream = stream;
117
+ var readable_file_1 = require("./lib/filesystems/readable-file");
118
+ Object.defineProperty(exports, "makeReadableFile", { enumerable: true, get: function () { return readable_file_1.makeReadableFile; } });
119
+ var writable_file_1 = require("./lib/filesystems/writable-file");
120
+ Object.defineProperty(exports, "makeWritableFile", { enumerable: true, get: function () { return writable_file_1.makeWritableFile; } });
121
+ var node_filesystem_1 = require("./lib/filesystems/node-filesystem");
122
+ Object.defineProperty(exports, "_NodeFileSystem", { enumerable: true, get: function () { return __importDefault(node_filesystem_1).default; } });
@@ -1,22 +1,9 @@
1
- import type { LoaderWithParser } from './types';
1
+ import type { LoaderWithParser, LoaderOptions } from './types';
2
+ import type { Table, TableBatch } from '@loaders.gl/schema';
3
+ export type JSONLoaderOptions = LoaderOptions;
2
4
  /**
3
5
  * A JSON Micro loader (minimal bundle size)
4
6
  * Alternative to `@loaders.gl/json`
5
7
  */
6
- export declare const JSONLoader: {
7
- name: string;
8
- id: string;
9
- module: string;
10
- version: any;
11
- extensions: string[];
12
- mimeTypes: string[];
13
- category: string;
14
- text: boolean;
15
- parseTextSync: typeof parseTextSync;
16
- parse: (arrayBuffer: any) => Promise<any>;
17
- options: {};
18
- };
19
- declare function parseTextSync(text: any): any;
20
- export declare const _typecheckJSONLoader: LoaderWithParser;
21
- export {};
8
+ export declare const JSONLoader: LoaderWithParser<Table, TableBatch, JSONLoaderOptions>;
22
9
  //# sourceMappingURL=json-loader.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"json-loader.d.ts","sourceRoot":"","sources":["../src/json-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,SAAS,CAAC;AAM9C;;;GAGG;AACH,eAAO,MAAM,UAAU;;;;;;;;;;;;CAYtB,CAAC;AAGF,iBAAS,aAAa,CAAC,IAAI,KAAA,OAE1B;AAED,eAAO,MAAM,oBAAoB,EAAE,gBAA6B,CAAC"}
1
+ {"version":3,"file":"json-loader.d.ts","sourceRoot":"","sources":["../src/json-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAE,aAAa,EAAC,MAAM,SAAS,CAAC;AAC7D,OAAO,KAAK,EAAC,KAAK,EAAE,UAAU,EAAC,MAAM,oBAAoB,CAAC;AAM1D,MAAM,MAAM,iBAAiB,GAAG,aAAa,CAAC;AAE9C;;;GAGG;AACH,eAAO,MAAM,UAAU,EAAE,gBAAgB,CAAC,KAAK,EAAE,UAAU,EAAE,iBAAiB,CAY7E,CAAC"}
@@ -1,21 +1,27 @@
1
- const VERSION = typeof "4.0.0-alpha.5" !== 'undefined' ? "4.0.0-alpha.5" : 'latest';
2
- export const JSONLoader = {
3
- name: 'JSON',
4
- id: 'json',
5
- module: 'json',
6
- version: VERSION,
7
- extensions: ['json', 'geojson'],
8
- mimeTypes: ['application/json'],
9
- category: 'json',
10
- text: true,
11
- parseTextSync,
12
- parse: async arrayBuffer => parseTextSync(new TextDecoder().decode(arrayBuffer)),
13
- options: {}
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JSONLoader = void 0;
4
+ // __VERSION__ is injected by babel-plugin-version-inline
5
+ // @ts-ignore TS2304: Cannot find name '__VERSION__'.
6
+ const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
7
+ /**
8
+ * A JSON Micro loader (minimal bundle size)
9
+ * Alternative to `@loaders.gl/json`
10
+ */
11
+ exports.JSONLoader = {
12
+ name: 'JSON',
13
+ id: 'json',
14
+ module: 'json',
15
+ version: VERSION,
16
+ extensions: ['json', 'geojson'],
17
+ mimeTypes: ['application/json'],
18
+ category: 'json',
19
+ text: true,
20
+ parseTextSync,
21
+ parse: async (arrayBuffer) => parseTextSync(new TextDecoder().decode(arrayBuffer)),
22
+ options: {}
14
23
  };
15
-
24
+ // TODO - deprecated
16
25
  function parseTextSync(text) {
17
- return JSON.parse(text);
26
+ return JSON.parse(text);
18
27
  }
19
-
20
- export const _typecheckJSONLoader = JSONLoader;
21
- //# sourceMappingURL=json-loader.js.map
@@ -1,12 +1,8 @@
1
- /**
2
- * Convert an object to an array buffer
3
- */
4
- export declare function toArrayBuffer(data: any): ArrayBuffer;
5
1
  /**
6
2
  * compare two binary arrays for equality
7
- * @param {ArrayBuffer} a
8
- * @param {ArrayBuffer} b
9
- * @param {number} byteLength
3
+ * @param a
4
+ * @param b
5
+ * @param byteLength
10
6
  */
11
7
  export declare function compareArrayBuffers(arrayBuffer1: ArrayBuffer, arrayBuffer2: ArrayBuffer, byteLength?: number): boolean;
12
8
  /**
@@ -17,7 +13,7 @@ export declare function concatenateArrayBuffers(...sources: (ArrayBuffer | Uint8
17
13
  /**
18
14
  * Concatenate arbitrary count of typed arrays
19
15
  * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays
20
- * @param {...*} arrays - list of arrays. All arrays should be the same type
16
+ * @param - list of arrays. All arrays should be the same type
21
17
  * @return A concatenated TypedArray
22
18
  */
23
19
  export declare function concatenateTypedArrays<T>(...typedArrays: T[]): T;
@@ -1 +1 @@
1
- {"version":3,"file":"array-buffer-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/binary-utils/array-buffer-utils.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,GAAG,GAAG,WAAW,CA8BpD;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,WAAW,EACzB,YAAY,EAAE,WAAW,EACzB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAaT;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,OAAO,EAAE,CAAC,WAAW,GAAG,UAAU,CAAC,EAAE,GAAG,WAAW,CAqB7F;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,GAAG,WAAW,EAAE,CAAC,EAAE,GAAG,CAAC,CAoBhE;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,WAAW,EACxB,UAAU,EAAE,MAAM,EAClB,UAAU,CAAC,EAAE,MAAM,GAClB,WAAW,CAOb"}
1
+ {"version":3,"file":"array-buffer-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/binary-utils/array-buffer-utils.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,WAAW,EACzB,YAAY,EAAE,WAAW,EACzB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAaT;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,OAAO,EAAE,CAAC,WAAW,GAAG,UAAU,CAAC,EAAE,GAAG,WAAW,CAqB7F;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,GAAG,WAAW,EAAE,CAAC,EAAE,GAAG,CAAC,CAoBhE;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,WAAW,EACxB,UAAU,EAAE,MAAM,EAClB,UAAU,CAAC,EAAE,MAAM,GAClB,WAAW,CAOb"}
@@ -1,86 +1,84 @@
1
- import { isBuffer, bufferToArrayBuffer } from './buffer-utils';
2
- export function toArrayBuffer(data) {
3
- if (isBuffer(data)) {
4
- return bufferToArrayBuffer(data);
5
- }
6
-
7
- if (data instanceof ArrayBuffer) {
8
- return data;
9
- }
10
-
11
- if (ArrayBuffer.isView(data)) {
12
- if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) {
13
- return data.buffer;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sliceArrayBuffer = exports.concatenateTypedArrays = exports.concatenateArrayBuffers = exports.compareArrayBuffers = void 0;
4
+ /**
5
+ * compare two binary arrays for equality
6
+ * @param a
7
+ * @param b
8
+ * @param byteLength
9
+ */
10
+ function compareArrayBuffers(arrayBuffer1, arrayBuffer2, byteLength) {
11
+ byteLength = byteLength || arrayBuffer1.byteLength;
12
+ if (arrayBuffer1.byteLength < byteLength || arrayBuffer2.byteLength < byteLength) {
13
+ return false;
14
14
  }
15
-
16
- return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
17
- }
18
-
19
- if (typeof data === 'string') {
20
- const text = data;
21
- const uint8Array = new TextEncoder().encode(text);
22
- return uint8Array.buffer;
23
- }
24
-
25
- if (data && typeof data === 'object' && data._toArrayBuffer) {
26
- return data._toArrayBuffer();
27
- }
28
-
29
- throw new Error('toArrayBuffer');
30
- }
31
- export function compareArrayBuffers(arrayBuffer1, arrayBuffer2, byteLength) {
32
- byteLength = byteLength || arrayBuffer1.byteLength;
33
-
34
- if (arrayBuffer1.byteLength < byteLength || arrayBuffer2.byteLength < byteLength) {
35
- return false;
36
- }
37
-
38
- const array1 = new Uint8Array(arrayBuffer1);
39
- const array2 = new Uint8Array(arrayBuffer2);
40
-
41
- for (let i = 0; i < array1.length; ++i) {
42
- if (array1[i] !== array2[i]) {
43
- return false;
15
+ const array1 = new Uint8Array(arrayBuffer1);
16
+ const array2 = new Uint8Array(arrayBuffer2);
17
+ for (let i = 0; i < array1.length; ++i) {
18
+ if (array1[i] !== array2[i]) {
19
+ return false;
20
+ }
44
21
  }
45
- }
46
-
47
- return true;
22
+ return true;
48
23
  }
49
- export function concatenateArrayBuffers(...sources) {
50
- const sourceArrays = sources.map(source2 => source2 instanceof ArrayBuffer ? new Uint8Array(source2) : source2);
51
- const byteLength = sourceArrays.reduce((length, typedArray) => length + typedArray.byteLength, 0);
52
- const result = new Uint8Array(byteLength);
53
- let offset = 0;
54
-
55
- for (const sourceArray of sourceArrays) {
56
- result.set(sourceArray, offset);
57
- offset += sourceArray.byteLength;
58
- }
59
-
60
- return result.buffer;
24
+ exports.compareArrayBuffers = compareArrayBuffers;
25
+ /**
26
+ * Concatenate a sequence of ArrayBuffers
27
+ * @return A concatenated ArrayBuffer
28
+ */
29
+ function concatenateArrayBuffers(...sources) {
30
+ // Make sure all inputs are wrapped in typed arrays
31
+ const sourceArrays = sources.map((source2) => source2 instanceof ArrayBuffer ? new Uint8Array(source2) : source2);
32
+ // Get length of all inputs
33
+ const byteLength = sourceArrays.reduce((length, typedArray) => length + typedArray.byteLength, 0);
34
+ // Allocate array with space for all inputs
35
+ const result = new Uint8Array(byteLength);
36
+ // Copy the subarrays
37
+ let offset = 0;
38
+ for (const sourceArray of sourceArrays) {
39
+ result.set(sourceArray, offset);
40
+ offset += sourceArray.byteLength;
41
+ }
42
+ // We work with ArrayBuffers, discard the typed array wrapper
43
+ return result.buffer;
61
44
  }
62
- export function concatenateTypedArrays(...typedArrays) {
63
- const arrays = typedArrays;
64
- const TypedArrayConstructor = arrays && arrays.length > 1 && arrays[0].constructor || null;
65
-
66
- if (!TypedArrayConstructor) {
67
- throw new Error('"concatenateTypedArrays" - incorrect quantity of arguments or arguments have incompatible data types');
68
- }
69
-
70
- const sumLength = arrays.reduce((acc, value) => acc + value.length, 0);
71
- const result = new TypedArrayConstructor(sumLength);
72
- let offset = 0;
73
-
74
- for (const array of arrays) {
75
- result.set(array, offset);
76
- offset += array.length;
77
- }
78
-
79
- return result;
45
+ exports.concatenateArrayBuffers = concatenateArrayBuffers;
46
+ /**
47
+ * Concatenate arbitrary count of typed arrays
48
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays
49
+ * @param - list of arrays. All arrays should be the same type
50
+ * @return A concatenated TypedArray
51
+ */
52
+ function concatenateTypedArrays(...typedArrays) {
53
+ // @ts-ignore
54
+ const arrays = typedArrays;
55
+ // @ts-ignore
56
+ const TypedArrayConstructor = (arrays && arrays.length > 1 && arrays[0].constructor) || null;
57
+ if (!TypedArrayConstructor) {
58
+ throw new Error('"concatenateTypedArrays" - incorrect quantity of arguments or arguments have incompatible data types');
59
+ }
60
+ const sumLength = arrays.reduce((acc, value) => acc + value.length, 0);
61
+ // @ts-ignore typescript does not like dynamic constructors
62
+ const result = new TypedArrayConstructor(sumLength);
63
+ let offset = 0;
64
+ for (const array of arrays) {
65
+ result.set(array, offset);
66
+ offset += array.length;
67
+ }
68
+ return result;
80
69
  }
81
- export function sliceArrayBuffer(arrayBuffer, byteOffset, byteLength) {
82
- const subArray = byteLength !== undefined ? new Uint8Array(arrayBuffer).subarray(byteOffset, byteOffset + byteLength) : new Uint8Array(arrayBuffer).subarray(byteOffset);
83
- const arrayCopy = new Uint8Array(subArray);
84
- return arrayCopy.buffer;
70
+ exports.concatenateTypedArrays = concatenateTypedArrays;
71
+ /**
72
+ * Copy a view of an ArrayBuffer into new ArrayBuffer with byteOffset = 0
73
+ * @param arrayBuffer
74
+ * @param byteOffset
75
+ * @param byteLength
76
+ */
77
+ function sliceArrayBuffer(arrayBuffer, byteOffset, byteLength) {
78
+ const subArray = byteLength !== undefined
79
+ ? new Uint8Array(arrayBuffer).subarray(byteOffset, byteOffset + byteLength)
80
+ : new Uint8Array(arrayBuffer).subarray(byteOffset);
81
+ const arrayCopy = new Uint8Array(subArray);
82
+ return arrayCopy.buffer;
85
83
  }
86
- //# sourceMappingURL=array-buffer-utils.js.map
84
+ exports.sliceArrayBuffer = sliceArrayBuffer;
@@ -0,0 +1,43 @@
1
+ import { TypedArray } from '../../types';
2
+ /**
3
+ * Helper function that pads a string with spaces to fit a certain byte alignment
4
+ * @param string
5
+ * @param byteAlignment
6
+ * @returns
7
+ *
8
+ * @todo PERFORMANCE IDEA: No need to copy string twice...
9
+ */
10
+ export declare function padStringToByteAlignment(string: string, byteAlignment: number): string;
11
+ /**
12
+ *
13
+ * @param dataView
14
+ * @param byteOffset
15
+ * @param string
16
+ * @param byteLength
17
+ * @returns
18
+ */
19
+ export declare function copyStringToDataView(dataView: DataView, byteOffset: number, string: string, byteLength: number): number;
20
+ export declare function copyBinaryToDataView(dataView: any, byteOffset: any, binary: any, byteLength: any): any;
21
+ /**
22
+ * Copy sourceBuffer to dataView with some padding
23
+ *
24
+ * @param dataView - destination data container. If null - only new offset is calculated
25
+ * @param byteOffset - destination byte offset to copy to
26
+ * @param sourceBuffer - source data buffer
27
+ * @param padding - pad the resulting array to multiple of "padding" bytes. Additional bytes are filled with 0x20 (ASCII space)
28
+ *
29
+ * @return new byteOffset of resulting dataView
30
+ */
31
+ export declare function copyPaddedArrayBufferToDataView(dataView: DataView | null, byteOffset: number, sourceBuffer: TypedArray, padding: number): number;
32
+ /**
33
+ * Copy string to dataView with some padding
34
+ *
35
+ * @param {DataView | null} dataView - destination data container. If null - only new offset is calculated
36
+ * @param {number} byteOffset - destination byte offset to copy to
37
+ * @param {string} string - source string
38
+ * @param {number} padding - pad the resulting array to multiple of "padding" bytes. Additional bytes are filled with 0x20 (ASCII space)
39
+ *
40
+ * @return new byteOffset of resulting dataView
41
+ */
42
+ export declare function copyPaddedStringToDataView(dataView: DataView | null, byteOffset: number, string: string, padding: number): number;
43
+ //# sourceMappingURL=dataview-copy-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dataview-copy-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/binary-utils/dataview-copy-utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,UAAU,EAAC,MAAM,aAAa,CAAC;AAGvC;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,CAStF;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,QAAQ,EAClB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,GACjB,MAAM,CAOR;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,KAAA,EAAE,UAAU,KAAA,EAAE,MAAM,KAAA,EAAE,UAAU,KAAA,OAO5E;AAED;;;;;;;;;GASG;AACH,wBAAgB,+BAA+B,CAC7C,QAAQ,EAAE,QAAQ,GAAG,IAAI,EACzB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,UAAU,EACxB,OAAO,EAAE,MAAM,GACd,MAAM,CAsBR;AAED;;;;;;;;;GASG;AACH,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,QAAQ,GAAG,IAAI,EACzB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GACd,MAAM,CASR"}
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ // loaders./gl, MIT license
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.copyPaddedStringToDataView = exports.copyPaddedArrayBufferToDataView = exports.copyBinaryToDataView = exports.copyStringToDataView = exports.padStringToByteAlignment = void 0;
5
+ const memory_copy_utils_1 = require("./memory-copy-utils");
6
+ /**
7
+ * Helper function that pads a string with spaces to fit a certain byte alignment
8
+ * @param string
9
+ * @param byteAlignment
10
+ * @returns
11
+ *
12
+ * @todo PERFORMANCE IDEA: No need to copy string twice...
13
+ */
14
+ function padStringToByteAlignment(string, byteAlignment) {
15
+ const length = string.length;
16
+ const paddedLength = Math.ceil(length / byteAlignment) * byteAlignment; // Round up to the required alignment
17
+ const padding = paddedLength - length;
18
+ let whitespace = '';
19
+ for (let i = 0; i < padding; ++i) {
20
+ whitespace += ' ';
21
+ }
22
+ return string + whitespace;
23
+ }
24
+ exports.padStringToByteAlignment = padStringToByteAlignment;
25
+ /**
26
+ *
27
+ * @param dataView
28
+ * @param byteOffset
29
+ * @param string
30
+ * @param byteLength
31
+ * @returns
32
+ */
33
+ function copyStringToDataView(dataView, byteOffset, string, byteLength) {
34
+ if (dataView) {
35
+ for (let i = 0; i < byteLength; i++) {
36
+ dataView.setUint8(byteOffset + i, string.charCodeAt(i));
37
+ }
38
+ }
39
+ return byteOffset + byteLength;
40
+ }
41
+ exports.copyStringToDataView = copyStringToDataView;
42
+ function copyBinaryToDataView(dataView, byteOffset, binary, byteLength) {
43
+ if (dataView) {
44
+ for (let i = 0; i < byteLength; i++) {
45
+ dataView.setUint8(byteOffset + i, binary[i]);
46
+ }
47
+ }
48
+ return byteOffset + byteLength;
49
+ }
50
+ exports.copyBinaryToDataView = copyBinaryToDataView;
51
+ /**
52
+ * Copy sourceBuffer to dataView with some padding
53
+ *
54
+ * @param dataView - destination data container. If null - only new offset is calculated
55
+ * @param byteOffset - destination byte offset to copy to
56
+ * @param sourceBuffer - source data buffer
57
+ * @param padding - pad the resulting array to multiple of "padding" bytes. Additional bytes are filled with 0x20 (ASCII space)
58
+ *
59
+ * @return new byteOffset of resulting dataView
60
+ */
61
+ function copyPaddedArrayBufferToDataView(dataView, byteOffset, sourceBuffer, padding) {
62
+ const paddedLength = (0, memory_copy_utils_1.padToNBytes)(sourceBuffer.byteLength, padding);
63
+ const padLength = paddedLength - sourceBuffer.byteLength;
64
+ if (dataView) {
65
+ // Copy array
66
+ const targetArray = new Uint8Array(dataView.buffer, dataView.byteOffset + byteOffset, sourceBuffer.byteLength);
67
+ const sourceArray = new Uint8Array(sourceBuffer);
68
+ targetArray.set(sourceArray);
69
+ // Add PADDING
70
+ for (let i = 0; i < padLength; ++i) {
71
+ // json chunk is padded with spaces (ASCII 0x20)
72
+ dataView.setUint8(byteOffset + sourceBuffer.byteLength + i, 0x20);
73
+ }
74
+ }
75
+ byteOffset += paddedLength;
76
+ return byteOffset;
77
+ }
78
+ exports.copyPaddedArrayBufferToDataView = copyPaddedArrayBufferToDataView;
79
+ /**
80
+ * Copy string to dataView with some padding
81
+ *
82
+ * @param {DataView | null} dataView - destination data container. If null - only new offset is calculated
83
+ * @param {number} byteOffset - destination byte offset to copy to
84
+ * @param {string} string - source string
85
+ * @param {number} padding - pad the resulting array to multiple of "padding" bytes. Additional bytes are filled with 0x20 (ASCII space)
86
+ *
87
+ * @return new byteOffset of resulting dataView
88
+ */
89
+ function copyPaddedStringToDataView(dataView, byteOffset, string, padding) {
90
+ const textEncoder = new TextEncoder();
91
+ // PERFORMANCE IDEA: We encode twice, once to get size and once to store
92
+ // PERFORMANCE IDEA: Use TextEncoder.encodeInto() to avoid temporary copy
93
+ const stringBuffer = textEncoder.encode(string);
94
+ byteOffset = copyPaddedArrayBufferToDataView(dataView, byteOffset, stringBuffer, padding);
95
+ return byteOffset;
96
+ }
97
+ exports.copyPaddedStringToDataView = copyPaddedStringToDataView;
@@ -1,3 +1,17 @@
1
- export declare function getFirstCharacters(data: any, length?: number): string;
1
+ /**
2
+ * Get the first characters from a binary file (interpret the first bytes as an ASCII string)
3
+ * @param data
4
+ * @param length
5
+ * @returns
6
+ */
7
+ export declare function getFirstCharacters(data: string | ArrayBuffer, length?: number): string;
8
+ /**
9
+ * Gets a magic string from a "file"
10
+ * Typically used to check or detect file format
11
+ * @param arrayBuffer
12
+ * @param byteOffset
13
+ * @param length
14
+ * @returns
15
+ */
2
16
  export declare function getMagicString(arrayBuffer: ArrayBuffer, byteOffset: number, length: number): string;
3
17
  //# sourceMappingURL=get-first-characters.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"get-first-characters.d.ts","sourceRoot":"","sources":["../../../src/lib/binary-utils/get-first-characters.ts"],"names":[],"mappings":"AAAA,wBAAgB,kBAAkB,CAAC,IAAI,KAAA,EAAE,MAAM,SAAI,GAAG,MAAM,CAW3D;AAED,wBAAgB,cAAc,CAC5B,WAAW,EAAE,WAAW,EACxB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,GACb,MAAM,CAUR"}
1
+ {"version":3,"file":"get-first-characters.d.ts","sourceRoot":"","sources":["../../../src/lib/binary-utils/get-first-characters.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,EAAE,MAAM,GAAE,MAAU,GAAG,MAAM,CAWzF;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,WAAW,EAAE,WAAW,EACxB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,GACb,MAAM,CAUR"}