@loaders.gl/core 4.0.0-alpha.4 → 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 (413) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/bundle.js +2 -2
  4. package/dist/core-addons/write-file-browser.d.ts +1 -0
  5. package/dist/core-addons/write-file-browser.d.ts.map +1 -0
  6. package/dist/core-addons/write-file-browser.js +59 -1
  7. package/dist/dist.min.js +3874 -0
  8. package/dist/es5/bundle.js +6 -0
  9. package/dist/es5/bundle.js.map +1 -0
  10. package/dist/es5/core-addons/write-file-browser.js +2 -0
  11. package/dist/es5/core-addons/write-file-browser.js.map +1 -0
  12. package/dist/es5/index.js +377 -0
  13. package/dist/es5/index.js.map +1 -0
  14. package/dist/es5/iterators/batch-iterators/timed-batch-iterator.js +94 -0
  15. package/dist/es5/iterators/batch-iterators/timed-batch-iterator.js.map +1 -0
  16. package/dist/es5/iterators/make-iterator/make-array-buffer-iterator.js +42 -0
  17. package/dist/es5/iterators/make-iterator/make-array-buffer-iterator.js.map +1 -0
  18. package/dist/es5/iterators/make-iterator/make-blob-iterator.js +47 -0
  19. package/dist/es5/iterators/make-iterator/make-blob-iterator.js.map +1 -0
  20. package/dist/es5/iterators/make-iterator/make-iterator.js +31 -0
  21. package/dist/es5/iterators/make-iterator/make-iterator.js.map +1 -0
  22. package/dist/es5/iterators/make-iterator/make-stream-iterator.js +133 -0
  23. package/dist/es5/iterators/make-iterator/make-stream-iterator.js.map +1 -0
  24. package/dist/es5/iterators/make-iterator/make-string-iterator.js +38 -0
  25. package/dist/es5/iterators/make-iterator/make-string-iterator.js.map +1 -0
  26. package/dist/es5/iterators/make-stream/make-dom-stream.js +67 -0
  27. package/dist/es5/iterators/make-stream/make-dom-stream.js.map +1 -0
  28. package/dist/es5/iterators/make-stream/make-node-stream.js +168 -0
  29. package/dist/es5/iterators/make-stream/make-node-stream.js.map +1 -0
  30. package/dist/es5/javascript-utils/is-type.js +79 -0
  31. package/dist/es5/javascript-utils/is-type.js.map +1 -0
  32. package/dist/es5/lib/api/encode-table.js +159 -0
  33. package/dist/es5/lib/api/encode-table.js.map +1 -0
  34. package/dist/es5/lib/api/encode.js +244 -0
  35. package/dist/es5/lib/api/encode.js.map +1 -0
  36. package/dist/es5/lib/api/load-in-batches.js +63 -0
  37. package/dist/es5/lib/api/load-in-batches.js.map +1 -0
  38. package/dist/es5/lib/api/load.js +76 -0
  39. package/dist/es5/lib/api/load.js.map +1 -0
  40. package/dist/es5/lib/api/loader-options.js +19 -0
  41. package/dist/es5/lib/api/loader-options.js.map +1 -0
  42. package/dist/es5/lib/api/parse-in-batches.js +277 -0
  43. package/dist/es5/lib/api/parse-in-batches.js.map +1 -0
  44. package/dist/es5/lib/api/parse-sync.js +54 -0
  45. package/dist/es5/lib/api/parse-sync.js.map +1 -0
  46. package/dist/es5/lib/api/parse.js +143 -0
  47. package/dist/es5/lib/api/parse.js.map +1 -0
  48. package/dist/es5/lib/api/register-loaders.js +50 -0
  49. package/dist/es5/lib/api/register-loaders.js.map +1 -0
  50. package/dist/es5/lib/api/save.js +42 -0
  51. package/dist/es5/lib/api/save.js.map +1 -0
  52. package/dist/es5/lib/api/select-loader.js +303 -0
  53. package/dist/es5/lib/api/select-loader.js.map +1 -0
  54. package/dist/es5/lib/common.js +2 -0
  55. package/dist/es5/lib/common.js.map +1 -0
  56. package/dist/es5/lib/fetch/fetch-error-message.js +56 -0
  57. package/dist/es5/lib/fetch/fetch-error-message.js.map +1 -0
  58. package/dist/es5/lib/fetch/fetch-file.js +47 -0
  59. package/dist/es5/lib/fetch/fetch-file.js.map +1 -0
  60. package/dist/es5/lib/fetch/read-array-buffer.js +76 -0
  61. package/dist/es5/lib/fetch/read-array-buffer.js.map +1 -0
  62. package/dist/es5/lib/fetch/read-file.js +20 -0
  63. package/dist/es5/lib/fetch/read-file.js.map +1 -0
  64. package/dist/es5/lib/fetch/write-file.js +48 -0
  65. package/dist/es5/lib/fetch/write-file.js.map +1 -0
  66. package/dist/es5/lib/filesystems/browser-filesystem.js +249 -0
  67. package/dist/es5/lib/filesystems/browser-filesystem.js.map +1 -0
  68. package/dist/es5/lib/filesystems/filesystem.js +2 -0
  69. package/dist/es5/lib/filesystems/filesystem.js.map +1 -0
  70. package/dist/es5/lib/filesystems/read-array-buffer.js +41 -0
  71. package/dist/es5/lib/filesystems/read-array-buffer.js.map +1 -0
  72. package/dist/es5/lib/init.js +18 -0
  73. package/dist/es5/lib/init.js.map +1 -0
  74. package/dist/es5/lib/loader-utils/check-errors.js +57 -0
  75. package/dist/es5/lib/loader-utils/check-errors.js.map +1 -0
  76. package/dist/es5/lib/loader-utils/get-data.js +237 -0
  77. package/dist/es5/lib/loader-utils/get-data.js.map +1 -0
  78. package/dist/es5/lib/loader-utils/get-fetch-function.js +26 -0
  79. package/dist/es5/lib/loader-utils/get-fetch-function.js.map +1 -0
  80. package/dist/es5/lib/loader-utils/loader-context.js +41 -0
  81. package/dist/es5/lib/loader-utils/loader-context.js.map +1 -0
  82. package/dist/es5/lib/loader-utils/loggers.js +90 -0
  83. package/dist/es5/lib/loader-utils/loggers.js.map +1 -0
  84. package/dist/es5/lib/loader-utils/normalize-loader.js +44 -0
  85. package/dist/es5/lib/loader-utils/normalize-loader.js.map +1 -0
  86. package/dist/es5/lib/loader-utils/option-defaults.js +47 -0
  87. package/dist/es5/lib/loader-utils/option-defaults.js.map +1 -0
  88. package/dist/es5/lib/loader-utils/option-utils.js +132 -0
  89. package/dist/es5/lib/loader-utils/option-utils.js.map +1 -0
  90. package/dist/es5/lib/progress/fetch-progress.js +134 -0
  91. package/dist/es5/lib/progress/fetch-progress.js.map +1 -0
  92. package/dist/es5/lib/utils/log.js +12 -0
  93. package/dist/es5/lib/utils/log.js.map +1 -0
  94. package/dist/es5/lib/utils/mime-type-utils.js +24 -0
  95. package/dist/es5/lib/utils/mime-type-utils.js.map +1 -0
  96. package/dist/es5/lib/utils/resource-utils.js +58 -0
  97. package/dist/es5/lib/utils/resource-utils.js.map +1 -0
  98. package/dist/es5/lib/utils/response-utils.js +196 -0
  99. package/dist/es5/lib/utils/response-utils.js.map +1 -0
  100. package/dist/es5/null-loader.js +139 -0
  101. package/dist/es5/null-loader.js.map +1 -0
  102. package/dist/es5/workers/null-worker.js +6 -0
  103. package/dist/es5/workers/null-worker.js.map +1 -0
  104. package/dist/esm/bundle.js +4 -0
  105. package/dist/esm/bundle.js.map +1 -0
  106. package/dist/esm/core-addons/README.md +1 -0
  107. package/dist/esm/core-addons/write-file-browser.js +2 -0
  108. package/dist/esm/core-addons/write-file-browser.js.map +1 -0
  109. package/dist/esm/index.js +30 -0
  110. package/dist/esm/index.js.map +1 -0
  111. package/dist/esm/iterators/batch-iterators/timed-batch-iterator.js +16 -0
  112. package/dist/esm/iterators/batch-iterators/timed-batch-iterator.js.map +1 -0
  113. package/dist/esm/iterators/make-iterator/make-array-buffer-iterator.js +20 -0
  114. package/dist/esm/iterators/make-iterator/make-array-buffer-iterator.js.map +1 -0
  115. package/dist/esm/iterators/make-iterator/make-blob-iterator.js +12 -0
  116. package/dist/esm/iterators/make-iterator/make-blob-iterator.js.map +1 -0
  117. package/dist/esm/iterators/make-iterator/make-iterator.js +25 -0
  118. package/dist/esm/iterators/make-iterator/make-iterator.js.map +1 -0
  119. package/dist/esm/iterators/make-iterator/make-stream-iterator.js +32 -0
  120. package/dist/esm/iterators/make-iterator/make-stream-iterator.js.map +1 -0
  121. package/dist/esm/iterators/make-iterator/make-string-iterator.js +13 -0
  122. package/dist/esm/iterators/make-iterator/make-string-iterator.js.map +1 -0
  123. package/dist/esm/iterators/make-stream/make-dom-stream.js +29 -0
  124. package/dist/esm/iterators/make-stream/make-dom-stream.js.map +1 -0
  125. package/dist/esm/iterators/make-stream/make-node-stream.js +57 -0
  126. package/dist/esm/iterators/make-stream/make-node-stream.js.map +1 -0
  127. package/dist/esm/javascript-utils/is-type.js +19 -0
  128. package/dist/esm/javascript-utils/is-type.js.map +1 -0
  129. package/dist/esm/lib/api/encode-table.js +45 -0
  130. package/dist/esm/lib/api/encode-table.js.map +1 -0
  131. package/dist/esm/lib/api/encode.js +87 -0
  132. package/dist/esm/lib/api/encode.js.map +1 -0
  133. package/dist/esm/lib/api/load-in-batches.js +25 -0
  134. package/dist/esm/lib/api/load-in-batches.js.map +1 -0
  135. package/dist/esm/lib/api/load.js +26 -0
  136. package/dist/esm/lib/api/load.js.map +1 -0
  137. package/dist/esm/lib/api/loader-options.js +3 -0
  138. package/dist/esm/lib/api/loader-options.js.map +1 -0
  139. package/dist/esm/lib/api/parse-in-batches.js +85 -0
  140. package/dist/esm/lib/api/parse-in-batches.js.map +1 -0
  141. package/dist/esm/lib/api/parse-sync.js +47 -0
  142. package/dist/esm/lib/api/parse-sync.js.map +1 -0
  143. package/dist/esm/lib/api/parse.js +76 -0
  144. package/dist/esm/lib/api/parse.js.map +1 -0
  145. package/dist/esm/lib/api/register-loaders.js +25 -0
  146. package/dist/esm/lib/api/register-loaders.js.map +1 -0
  147. package/dist/esm/lib/api/save.js +11 -0
  148. package/dist/esm/lib/api/save.js.map +1 -0
  149. package/dist/esm/lib/api/select-loader.js +204 -0
  150. package/dist/esm/lib/api/select-loader.js.map +1 -0
  151. package/dist/esm/lib/common.js +2 -0
  152. package/dist/esm/lib/common.js.map +1 -0
  153. package/dist/esm/lib/fetch/fetch-error-message.js +18 -0
  154. package/dist/esm/lib/fetch/fetch-error-message.js.map +1 -0
  155. package/dist/esm/lib/fetch/fetch-file.js +14 -0
  156. package/dist/esm/lib/fetch/fetch-file.js.map +1 -0
  157. package/dist/esm/lib/fetch/read-array-buffer.js +23 -0
  158. package/dist/esm/lib/fetch/read-array-buffer.js.map +1 -0
  159. package/dist/esm/lib/fetch/read-file.js +15 -0
  160. package/dist/esm/lib/fetch/read-file.js.map +1 -0
  161. package/dist/esm/lib/fetch/write-file.js +21 -0
  162. package/dist/esm/lib/fetch/write-file.js.map +1 -0
  163. package/dist/esm/lib/filesystems/browser-filesystem.js +92 -0
  164. package/dist/esm/lib/filesystems/browser-filesystem.js.map +1 -0
  165. package/dist/esm/lib/filesystems/filesystem.js +2 -0
  166. package/dist/esm/lib/filesystems/filesystem.js.map +1 -0
  167. package/dist/esm/lib/filesystems/read-array-buffer.js +8 -0
  168. package/dist/esm/lib/filesystems/read-array-buffer.js.map +1 -0
  169. package/dist/esm/lib/init.js +11 -0
  170. package/dist/esm/lib/init.js.map +1 -0
  171. package/dist/esm/lib/loader-utils/check-errors.js +22 -0
  172. package/dist/esm/lib/loader-utils/check-errors.js.map +1 -0
  173. package/dist/esm/lib/loader-utils/get-data.js +103 -0
  174. package/dist/esm/lib/loader-utils/get-data.js.map +1 -0
  175. package/dist/esm/lib/loader-utils/get-fetch-function.js +18 -0
  176. package/dist/esm/lib/loader-utils/get-fetch-function.js.map +1 -0
  177. package/dist/esm/lib/loader-utils/loader-context.js +30 -0
  178. package/dist/esm/lib/loader-utils/loader-context.js.map +1 -0
  179. package/dist/esm/lib/loader-utils/loggers.js +50 -0
  180. package/dist/esm/lib/loader-utils/loggers.js.map +1 -0
  181. package/dist/esm/lib/loader-utils/normalize-loader.js +37 -0
  182. package/dist/esm/lib/loader-utils/normalize-loader.js.map +1 -0
  183. package/dist/esm/lib/loader-utils/option-defaults.js +39 -0
  184. package/dist/esm/lib/loader-utils/option-defaults.js.map +1 -0
  185. package/dist/esm/lib/loader-utils/option-utils.js +106 -0
  186. package/dist/esm/lib/loader-utils/option-utils.js.map +1 -0
  187. package/dist/esm/lib/progress/fetch-progress.js +52 -0
  188. package/dist/esm/lib/progress/fetch-progress.js.map +1 -0
  189. package/dist/esm/lib/utils/log.js +5 -0
  190. package/dist/esm/lib/utils/log.js.map +1 -0
  191. package/dist/esm/lib/utils/mime-type-utils.js +17 -0
  192. package/dist/esm/lib/utils/mime-type-utils.js.map +1 -0
  193. package/dist/esm/lib/utils/resource-utils.js +51 -0
  194. package/dist/esm/lib/utils/resource-utils.js.map +1 -0
  195. package/dist/esm/lib/utils/response-utils.js +91 -0
  196. package/dist/esm/lib/utils/response-utils.js.map +1 -0
  197. package/dist/esm/null-loader.js +45 -0
  198. package/dist/esm/null-loader.js.map +1 -0
  199. package/dist/esm/workers/null-worker.js +4 -0
  200. package/dist/esm/workers/null-worker.js.map +1 -0
  201. package/dist/index.d.ts +31 -0
  202. package/dist/index.d.ts.map +1 -0
  203. package/dist/index.js +108 -31
  204. package/dist/iterators/batch-iterators/timed-batch-iterator.d.ts +5 -0
  205. package/dist/iterators/batch-iterators/timed-batch-iterator.d.ts.map +1 -0
  206. package/dist/iterators/batch-iterators/timed-batch-iterator.js +20 -17
  207. package/dist/iterators/make-iterator/make-array-buffer-iterator.d.ts +9 -0
  208. package/dist/iterators/make-iterator/make-array-buffer-iterator.d.ts.map +1 -0
  209. package/dist/iterators/make-iterator/make-array-buffer-iterator.js +25 -16
  210. package/dist/iterators/make-iterator/make-blob-iterator.d.ts +9 -0
  211. package/dist/iterators/make-iterator/make-blob-iterator.d.ts.map +1 -0
  212. package/dist/iterators/make-iterator/make-blob-iterator.js +20 -12
  213. package/dist/iterators/make-iterator/make-iterator.d.ts +19 -0
  214. package/dist/iterators/make-iterator/make-iterator.d.ts.map +1 -0
  215. package/dist/iterators/make-iterator/make-iterator.js +36 -29
  216. package/dist/iterators/make-iterator/make-stream-iterator.d.ts +11 -0
  217. package/dist/iterators/make-iterator/make-stream-iterator.d.ts.map +1 -0
  218. package/dist/iterators/make-iterator/make-stream-iterator.js +89 -32
  219. package/dist/iterators/make-iterator/make-string-iterator.d.ts +9 -0
  220. package/dist/iterators/make-iterator/make-string-iterator.d.ts.map +1 -0
  221. package/dist/iterators/make-iterator/make-string-iterator.js +22 -12
  222. package/dist/iterators/make-stream/make-dom-stream.d.ts +14 -0
  223. package/dist/iterators/make-stream/make-dom-stream.d.ts.map +1 -0
  224. package/dist/iterators/make-stream/make-dom-stream.js +44 -32
  225. package/dist/iterators/make-stream/make-node-stream.d.ts +11 -0
  226. package/dist/iterators/make-stream/make-node-stream.d.ts.map +1 -0
  227. package/dist/iterators/make-stream/make-node-stream.js +75 -70
  228. package/dist/javascript-utils/is-type.d.ts +22 -0
  229. package/dist/javascript-utils/is-type.d.ts.map +1 -0
  230. package/dist/javascript-utils/is-type.js +41 -21
  231. package/dist/lib/api/encode-table.d.ts +6 -0
  232. package/dist/lib/api/encode-table.d.ts.map +1 -0
  233. package/dist/lib/api/encode-table.js +54 -0
  234. package/dist/lib/api/encode.d.ts +26 -0
  235. package/dist/lib/api/encode.d.ts.map +1 -0
  236. package/dist/lib/api/encode.js +111 -81
  237. package/dist/lib/api/load-in-batches.d.ts +13 -0
  238. package/dist/lib/api/load-in-batches.d.ts.map +1 -0
  239. package/dist/lib/api/load-in-batches.js +30 -27
  240. package/dist/lib/api/load.d.ts +14 -0
  241. package/dist/lib/api/load.d.ts.map +1 -0
  242. package/dist/lib/api/load.js +42 -24
  243. package/dist/lib/api/loader-options.d.ts +3 -0
  244. package/dist/lib/api/loader-options.d.ts.map +1 -0
  245. package/dist/lib/api/loader-options.js +7 -0
  246. package/dist/lib/api/parse-in-batches.d.ts +10 -0
  247. package/dist/lib/api/parse-in-batches.d.ts.map +1 -0
  248. package/dist/lib/api/parse-in-batches.js +113 -92
  249. package/dist/lib/api/parse-sync.d.ts +10 -0
  250. package/dist/lib/api/parse-sync.d.ts.map +1 -0
  251. package/dist/lib/api/parse-sync.js +56 -54
  252. package/dist/lib/api/parse.d.ts +6 -0
  253. package/dist/lib/api/parse.d.ts.map +1 -0
  254. package/dist/lib/api/parse.js +81 -61
  255. package/dist/lib/api/register-loaders.d.ts +7 -0
  256. package/dist/lib/api/register-loaders.d.ts.map +1 -0
  257. package/dist/lib/api/register-loaders.js +29 -23
  258. package/dist/lib/api/save.d.ts +4 -0
  259. package/dist/lib/api/save.d.ts.map +1 -0
  260. package/dist/lib/api/save.js +13 -9
  261. package/dist/lib/api/select-loader.d.ts +22 -0
  262. package/dist/lib/api/select-loader.d.ts.map +1 -0
  263. package/dist/lib/api/select-loader.js +216 -194
  264. package/dist/lib/common.d.ts +2 -0
  265. package/dist/lib/common.d.ts.map +1 -0
  266. package/dist/lib/common.js +2 -2
  267. package/dist/lib/fetch/fetch-error-message.d.ts +3 -0
  268. package/dist/lib/fetch/fetch-error-message.d.ts.map +1 -0
  269. package/dist/lib/fetch/fetch-error-message.js +21 -17
  270. package/dist/lib/fetch/fetch-file.d.ts +13 -0
  271. package/dist/lib/fetch/fetch-file.d.ts.map +1 -0
  272. package/dist/lib/fetch/fetch-file.js +25 -15
  273. package/dist/lib/fetch/read-array-buffer.d.ts +17 -0
  274. package/dist/lib/fetch/read-array-buffer.d.ts.map +1 -0
  275. package/dist/lib/fetch/read-array-buffer.js +39 -27
  276. package/dist/lib/fetch/read-file.d.ts +5 -0
  277. package/dist/lib/fetch/read-file.d.ts.map +1 -0
  278. package/dist/lib/fetch/read-file.js +28 -16
  279. package/dist/lib/fetch/write-file.d.ts +3 -0
  280. package/dist/lib/fetch/write-file.d.ts.map +1 -0
  281. package/dist/lib/fetch/write-file.js +20 -23
  282. package/dist/lib/filesystems/browser-filesystem.d.ts +58 -0
  283. package/dist/lib/filesystems/browser-filesystem.d.ts.map +1 -0
  284. package/dist/lib/filesystems/browser-filesystem.js +118 -107
  285. package/dist/lib/filesystems/filesystem.d.ts +46 -0
  286. package/dist/lib/filesystems/filesystem.d.ts.map +1 -0
  287. package/dist/lib/filesystems/filesystem.js +2 -2
  288. package/dist/lib/filesystems/read-array-buffer.d.ts +19 -0
  289. package/dist/lib/filesystems/read-array-buffer.d.ts.map +1 -0
  290. package/dist/lib/filesystems/read-array-buffer.js +28 -8
  291. package/dist/lib/init.d.ts +3 -0
  292. package/dist/lib/init.d.ts.map +1 -0
  293. package/dist/lib/init.js +16 -6
  294. package/dist/lib/loader-utils/check-errors.d.ts +3 -0
  295. package/dist/lib/loader-utils/check-errors.d.ts.map +1 -0
  296. package/dist/lib/loader-utils/check-errors.js +26 -22
  297. package/dist/lib/loader-utils/get-data.d.ts +6 -0
  298. package/dist/lib/loader-utils/get-data.d.ts.map +1 -0
  299. package/dist/lib/loader-utils/get-data.js +122 -122
  300. package/dist/lib/loader-utils/get-fetch-function.d.ts +9 -0
  301. package/dist/lib/loader-utils/get-fetch-function.d.ts.map +1 -0
  302. package/dist/lib/loader-utils/get-fetch-function.js +31 -0
  303. package/dist/lib/loader-utils/loader-context.d.ts +13 -0
  304. package/dist/lib/loader-utils/loader-context.d.ts.map +1 -0
  305. package/dist/lib/loader-utils/loader-context.js +47 -34
  306. package/dist/lib/loader-utils/loggers.d.ts +17 -0
  307. package/dist/lib/loader-utils/loggers.d.ts.map +1 -0
  308. package/dist/lib/loader-utils/loggers.js +39 -46
  309. package/dist/lib/loader-utils/normalize-loader.d.ts +4 -0
  310. package/dist/lib/loader-utils/normalize-loader.d.ts.map +1 -0
  311. package/dist/lib/loader-utils/normalize-loader.js +50 -41
  312. package/dist/lib/loader-utils/option-defaults.d.ts +20 -0
  313. package/dist/lib/loader-utils/option-defaults.d.ts.map +1 -0
  314. package/dist/lib/loader-utils/option-defaults.js +41 -35
  315. package/dist/lib/loader-utils/option-utils.d.ts +34 -0
  316. package/dist/lib/loader-utils/option-utils.d.ts.map +1 -0
  317. package/dist/lib/loader-utils/option-utils.js +140 -120
  318. package/dist/lib/progress/fetch-progress.d.ts +6 -0
  319. package/dist/lib/progress/fetch-progress.d.ts.map +1 -0
  320. package/dist/lib/progress/fetch-progress.js +54 -56
  321. package/dist/lib/utils/log.d.ts +3 -0
  322. package/dist/lib/utils/log.d.ts.map +1 -0
  323. package/dist/lib/utils/log.js +6 -0
  324. package/dist/lib/utils/mime-type-utils.d.ts +20 -0
  325. package/dist/lib/utils/mime-type-utils.d.ts.map +1 -0
  326. package/dist/lib/utils/mime-type-utils.js +38 -17
  327. package/dist/lib/utils/resource-utils.d.ts +21 -0
  328. package/dist/lib/utils/resource-utils.d.ts.map +1 -0
  329. package/dist/lib/utils/resource-utils.js +70 -52
  330. package/dist/lib/utils/response-utils.d.ts +18 -0
  331. package/dist/lib/utils/response-utils.d.ts.map +1 -0
  332. package/dist/lib/utils/response-utils.js +104 -105
  333. package/dist/null-loader.d.ts +10 -0
  334. package/dist/null-loader.d.ts.map +1 -0
  335. package/dist/null-loader.js +53 -31
  336. package/dist/null-worker.js +61 -21
  337. package/dist/workers/null-worker.d.ts +2 -0
  338. package/dist/workers/null-worker.d.ts.map +1 -0
  339. package/dist/workers/null-worker.js +5 -4
  340. package/package.json +16 -15
  341. package/src/index.ts +20 -4
  342. package/src/iterators/make-stream/make-dom-stream.ts +10 -5
  343. package/src/iterators/make-stream/make-node-stream.ts +10 -9
  344. package/src/lib/api/encode-table.ts +71 -0
  345. package/src/lib/api/encode.ts +15 -5
  346. package/src/lib/api/load-in-batches.ts +1 -1
  347. package/src/lib/api/load.ts +39 -8
  348. package/src/lib/api/loader-options.ts +2 -0
  349. package/src/lib/api/parse.ts +39 -2
  350. package/src/lib/api/register-loaders.ts +1 -1
  351. package/src/lib/api/select-loader.ts +16 -0
  352. package/src/lib/init.ts +17 -0
  353. package/src/lib/loader-utils/get-fetch-function.ts +38 -0
  354. package/src/lib/loader-utils/loader-context.ts +1 -1
  355. package/src/lib/loader-utils/loggers.ts +1 -1
  356. package/src/lib/loader-utils/option-defaults.ts +3 -1
  357. package/src/lib/loader-utils/option-utils.ts +22 -46
  358. package/src/lib/progress/fetch-progress.ts +2 -2
  359. package/src/lib/utils/log.ts +4 -0
  360. package/src/lib/utils/response-utils.ts +2 -2
  361. package/src/null-loader.ts +17 -5
  362. package/dist/bundle.js.map +0 -1
  363. package/dist/core-addons/write-file-browser.js.map +0 -1
  364. package/dist/index.js.map +0 -1
  365. package/dist/iterators/batch-iterators/timed-batch-iterator.js.map +0 -1
  366. package/dist/iterators/make-iterator/make-array-buffer-iterator.js.map +0 -1
  367. package/dist/iterators/make-iterator/make-blob-iterator.js.map +0 -1
  368. package/dist/iterators/make-iterator/make-iterator.js.map +0 -1
  369. package/dist/iterators/make-iterator/make-stream-iterator.js.map +0 -1
  370. package/dist/iterators/make-iterator/make-string-iterator.js.map +0 -1
  371. package/dist/iterators/make-stream/make-dom-stream.js.map +0 -1
  372. package/dist/iterators/make-stream/make-node-stream.js.map +0 -1
  373. package/dist/iterators/make-stream/make-stream.js +0 -7
  374. package/dist/iterators/make-stream/make-stream.js.map +0 -1
  375. package/dist/javascript-utils/is-type.js.map +0 -1
  376. package/dist/lib/api/encode.js.map +0 -1
  377. package/dist/lib/api/load-in-batches.js.map +0 -1
  378. package/dist/lib/api/load.js.map +0 -1
  379. package/dist/lib/api/parse-in-batches.js.map +0 -1
  380. package/dist/lib/api/parse-sync.js.map +0 -1
  381. package/dist/lib/api/parse.js.map +0 -1
  382. package/dist/lib/api/register-loaders.js.map +0 -1
  383. package/dist/lib/api/save.js.map +0 -1
  384. package/dist/lib/api/select-loader.js.map +0 -1
  385. package/dist/lib/api/set-loader-options.js +0 -5
  386. package/dist/lib/api/set-loader-options.js.map +0 -1
  387. package/dist/lib/common.js.map +0 -1
  388. package/dist/lib/fetch/fetch-error-message.js.map +0 -1
  389. package/dist/lib/fetch/fetch-file.js.map +0 -1
  390. package/dist/lib/fetch/read-array-buffer.js.map +0 -1
  391. package/dist/lib/fetch/read-file.js.map +0 -1
  392. package/dist/lib/fetch/write-file.js.map +0 -1
  393. package/dist/lib/filesystems/browser-filesystem.js.map +0 -1
  394. package/dist/lib/filesystems/filesystem.js.map +0 -1
  395. package/dist/lib/filesystems/read-array-buffer.js.map +0 -1
  396. package/dist/lib/init.js.map +0 -1
  397. package/dist/lib/loader-utils/check-errors.js.map +0 -1
  398. package/dist/lib/loader-utils/get-data.js.map +0 -1
  399. package/dist/lib/loader-utils/loader-context.js.map +0 -1
  400. package/dist/lib/loader-utils/loggers.js.map +0 -1
  401. package/dist/lib/loader-utils/normalize-loader.js.map +0 -1
  402. package/dist/lib/loader-utils/option-defaults.js.map +0 -1
  403. package/dist/lib/loader-utils/option-utils.js.map +0 -1
  404. package/dist/lib/progress/fetch-progress.js.map +0 -1
  405. package/dist/lib/utils/mime-type-utils.js.map +0 -1
  406. package/dist/lib/utils/resource-utils.js.map +0 -1
  407. package/dist/lib/utils/response-utils.js.map +0 -1
  408. package/dist/null-loader.js.map +0 -1
  409. package/dist/workers/null-worker.js.map +0 -1
  410. package/src/iterators/make-stream/make-stream.ts +0 -19
  411. package/src/lib/api/set-loader-options.ts +0 -9
  412. package/src/lib/init.js +0 -10
  413. /package/dist/{core-addons → es5/core-addons}/README.md +0 -0
@@ -0,0 +1,22 @@
1
+ import type { LoaderContext, LoaderOptions, Loader } from '@loaders.gl/loader-utils';
2
+ /**
3
+ * Find a loader that matches file extension and/or initial file content
4
+ * Search the loaders array argument for a loader that matches url extension or initial data
5
+ * Returns: a normalized loader
6
+ * @param data data to assist
7
+ * @param loaders
8
+ * @param options
9
+ * @param context used internally, applications should not provide this parameter
10
+ */
11
+ export declare function selectLoader(data: Response | Blob | ArrayBuffer | string, loaders?: Loader[] | Loader, options?: LoaderOptions, context?: LoaderContext): Promise<Loader | null>;
12
+ /**
13
+ * Find a loader that matches file extension and/or initial file content
14
+ * Search the loaders array argument for a loader that matches url extension or initial data
15
+ * Returns: a normalized loader
16
+ * @param data data to assist
17
+ * @param loaders
18
+ * @param options
19
+ * @param context used internally, applications should not provide this parameter
20
+ */
21
+ export declare function selectLoaderSync(data: Response | Blob | ArrayBuffer | string, loaders?: Loader[] | Loader, options?: LoaderOptions, context?: LoaderContext): Loader | null;
22
+ //# sourceMappingURL=select-loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"select-loader.d.ts","sourceRoot":"","sources":["../../../src/lib/api/select-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,aAAa,EAAE,aAAa,EAAE,MAAM,EAAC,MAAM,0BAA0B,CAAC;AAcnF;;;;;;;;GAQG;AACH,wBAAsB,YAAY,CAChC,IAAI,EAAE,QAAQ,GAAG,IAAI,GAAG,WAAW,GAAG,MAAM,EAC5C,OAAO,GAAE,MAAM,EAAE,GAAG,MAAW,EAC/B,OAAO,CAAC,EAAE,aAAa,EACvB,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAwBxB;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,QAAQ,GAAG,IAAI,GAAG,WAAW,GAAG,MAAM,EAC5C,OAAO,GAAE,MAAM,EAAE,GAAG,MAAW,EAC/B,OAAO,CAAC,EAAE,aAAa,EACvB,OAAO,CAAC,EAAE,aAAa,GACtB,MAAM,GAAG,IAAI,CAmCf"}
@@ -1,228 +1,250 @@
1
- import { compareArrayBuffers, path } from '@loaders.gl/loader-utils';
2
- import { normalizeLoader } from '../loader-utils/normalize-loader';
3
- import { getResourceUrlAndType } from '../utils/resource-utils';
4
- import { getRegisteredLoaders } from './register-loaders';
5
- import { isBlob } from '../../javascript-utils/is-type';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.selectLoaderSync = exports.selectLoader = void 0;
4
+ const loader_utils_1 = require("@loaders.gl/loader-utils");
5
+ const normalize_loader_1 = require("../loader-utils/normalize-loader");
6
+ const log_1 = require("../utils/log");
7
+ const resource_utils_1 = require("../utils/resource-utils");
8
+ const register_loaders_1 = require("./register-loaders");
9
+ const is_type_1 = require("../../javascript-utils/is-type");
6
10
  const EXT_PATTERN = /\.([^.]+)$/;
7
- export async function selectLoader(data, loaders = [], options, context) {
8
- if (!validHTTPResponse(data)) {
9
- return null;
10
- }
11
-
12
- let loader = selectLoaderSync(data, loaders, { ...options,
13
- nothrow: true
14
- }, context);
15
-
16
- if (loader) {
11
+ // TODO - Need a variant that peeks at streams for parseInBatches
12
+ // TODO - Detect multiple matching loaders? Use heuristics to grade matches?
13
+ // TODO - Allow apps to pass context to disambiguate between multiple matches (e.g. multiple .json formats)?
14
+ /**
15
+ * Find a loader that matches file extension and/or initial file content
16
+ * Search the loaders array argument for a loader that matches url extension or initial data
17
+ * Returns: a normalized loader
18
+ * @param data data to assist
19
+ * @param loaders
20
+ * @param options
21
+ * @param context used internally, applications should not provide this parameter
22
+ */
23
+ async function selectLoader(data, loaders = [], options, context) {
24
+ if (!validHTTPResponse(data)) {
25
+ return null;
26
+ }
27
+ // First make a sync attempt, disabling exceptions
28
+ let loader = selectLoaderSync(data, loaders, { ...options, nothrow: true }, context);
29
+ if (loader) {
30
+ return loader;
31
+ }
32
+ // For Blobs and Files, try to asynchronously read a small initial slice and test again with that
33
+ // to see if we can detect by initial content
34
+ if ((0, is_type_1.isBlob)(data)) {
35
+ data = await data.slice(0, 10).arrayBuffer();
36
+ loader = selectLoaderSync(data, loaders, options, context);
37
+ }
38
+ // no loader available
39
+ if (!loader && !options?.nothrow) {
40
+ throw new Error(getNoValidLoaderMessage(data));
41
+ }
17
42
  return loader;
18
- }
19
-
20
- if (isBlob(data)) {
21
- data = await data.slice(0, 10).arrayBuffer();
22
- loader = selectLoaderSync(data, loaders, options, context);
23
- }
24
-
25
- if (!loader && !(options !== null && options !== void 0 && options.nothrow)) {
26
- throw new Error(getNoValidLoaderMessage(data));
27
- }
28
-
29
- return loader;
30
43
  }
31
- export function selectLoaderSync(data, loaders = [], options, context) {
32
- if (!validHTTPResponse(data)) {
33
- return null;
34
- }
35
-
36
- if (loaders && !Array.isArray(loaders)) {
37
- return normalizeLoader(loaders);
38
- }
39
-
40
- let candidateLoaders = [];
41
-
42
- if (loaders) {
43
- candidateLoaders = candidateLoaders.concat(loaders);
44
- }
45
-
46
- if (!(options !== null && options !== void 0 && options.ignoreRegisteredLoaders)) {
47
- candidateLoaders.push(...getRegisteredLoaders());
48
- }
49
-
50
- normalizeLoaders(candidateLoaders);
51
- const loader = selectLoaderInternal(data, candidateLoaders, options, context);
52
-
53
- if (!loader && !(options !== null && options !== void 0 && options.nothrow)) {
54
- throw new Error(getNoValidLoaderMessage(data));
55
- }
56
-
57
- return loader;
44
+ exports.selectLoader = selectLoader;
45
+ /**
46
+ * Find a loader that matches file extension and/or initial file content
47
+ * Search the loaders array argument for a loader that matches url extension or initial data
48
+ * Returns: a normalized loader
49
+ * @param data data to assist
50
+ * @param loaders
51
+ * @param options
52
+ * @param context used internally, applications should not provide this parameter
53
+ */
54
+ function selectLoaderSync(data, loaders = [], options, context) {
55
+ if (!validHTTPResponse(data)) {
56
+ return null;
57
+ }
58
+ // eslint-disable-next-line complexity
59
+ // if only a single loader was provided (not as array), force its use
60
+ // TODO - Should this behavior be kept and documented?
61
+ if (loaders && !Array.isArray(loaders)) {
62
+ // TODO - remove support for legacy loaders
63
+ return (0, normalize_loader_1.normalizeLoader)(loaders);
64
+ }
65
+ // Build list of candidate loaders that will be searched in order for a match
66
+ let candidateLoaders = [];
67
+ // First search supplied loaders
68
+ if (loaders) {
69
+ candidateLoaders = candidateLoaders.concat(loaders);
70
+ }
71
+ // Then fall back to registered loaders
72
+ if (!options?.ignoreRegisteredLoaders) {
73
+ candidateLoaders.push(...(0, register_loaders_1.getRegisteredLoaders)());
74
+ }
75
+ // TODO - remove support for legacy loaders
76
+ normalizeLoaders(candidateLoaders);
77
+ const loader = selectLoaderInternal(data, candidateLoaders, options, context);
78
+ // no loader available
79
+ if (!loader && !options?.nothrow) {
80
+ throw new Error(getNoValidLoaderMessage(data));
81
+ }
82
+ return loader;
58
83
  }
59
-
84
+ exports.selectLoaderSync = selectLoaderSync;
85
+ /** Implements loaders selection logic */
86
+ // eslint-disable-next-line complexity
60
87
  function selectLoaderInternal(data, loaders, options, context) {
61
- const {
62
- url,
63
- type
64
- } = getResourceUrlAndType(data);
65
- const testUrl = url || (context === null || context === void 0 ? void 0 : context.url);
66
- let loader = null;
67
-
68
- if (options !== null && options !== void 0 && options.mimeType) {
69
- loader = findLoaderByMIMEType(loaders, options === null || options === void 0 ? void 0 : options.mimeType);
70
- }
71
-
72
- loader = loader || findLoaderByUrl(loaders, testUrl);
73
- loader = loader || findLoaderByMIMEType(loaders, type);
74
- loader = loader || findLoaderByInitialBytes(loaders, data);
75
- loader = loader || findLoaderByMIMEType(loaders, options === null || options === void 0 ? void 0 : options.fallbackMimeType);
76
- return loader;
88
+ const { url, type } = (0, resource_utils_1.getResourceUrlAndType)(data);
89
+ const testUrl = url || context?.url;
90
+ let loader = null;
91
+ let reason = '';
92
+ // if options.mimeType is supplied, it takes precedence
93
+ if (options?.mimeType) {
94
+ loader = findLoaderByMIMEType(loaders, options?.mimeType);
95
+ reason = `match forced by supplied MIME type ${options?.mimeType}`;
96
+ }
97
+ // Look up loader by url
98
+ loader = loader || findLoaderByUrl(loaders, testUrl);
99
+ reason = reason || (loader ? `matched url ${testUrl}` : '');
100
+ // Look up loader by mime type
101
+ loader = loader || findLoaderByMIMEType(loaders, type);
102
+ reason = reason || (loader ? `matched MIME type ${type}` : '');
103
+ // Look for loader via initial bytes (Note: not always accessible (e.g. Response, stream, async iterator)
104
+ loader = loader || findLoaderByInitialBytes(loaders, data);
105
+ reason = reason || (loader ? `matched initial data ${getFirstCharacters(data)}` : '');
106
+ // Look up loader by fallback mime type
107
+ loader = loader || findLoaderByMIMEType(loaders, options?.fallbackMimeType);
108
+ reason = reason || (loader ? `matched fallback MIME type ${type}` : '');
109
+ if (reason) {
110
+ log_1.log.log(1, `selectLoader selected ${loader?.name}: ${reason}.`);
111
+ }
112
+ return loader;
77
113
  }
78
-
114
+ /** Check HTTP Response */
79
115
  function validHTTPResponse(data) {
80
- if (data instanceof Response) {
81
- if (data.status === 204) {
82
- return false;
116
+ // HANDLE HTTP status
117
+ if (data instanceof Response) {
118
+ // 204 - NO CONTENT. This handles cases where e.g. a tile server responds with 204 for a missing tile
119
+ if (data.status === 204) {
120
+ return false;
121
+ }
83
122
  }
84
- }
85
-
86
- return true;
123
+ return true;
87
124
  }
88
-
125
+ /** Generate a helpful message to help explain why loader selection failed. */
89
126
  function getNoValidLoaderMessage(data) {
90
- const {
91
- url,
92
- type
93
- } = getResourceUrlAndType(data);
94
- let message = 'No valid loader found (';
95
- message += url ? "".concat(path.filename(url), ", ") : 'no url provided, ';
96
- message += "MIME type: ".concat(type ? "\"".concat(type, "\"") : 'not provided', ", ");
97
- const firstCharacters = data ? getFirstCharacters(data) : '';
98
- message += firstCharacters ? " first bytes: \"".concat(firstCharacters, "\"") : 'first bytes: not available';
99
- message += ')';
100
- return message;
127
+ const { url, type } = (0, resource_utils_1.getResourceUrlAndType)(data);
128
+ let message = 'No valid loader found (';
129
+ message += url ? `${loader_utils_1.path.filename(url)}, ` : 'no url provided, ';
130
+ message += `MIME type: ${type ? `"${type}"` : 'not provided'}, `;
131
+ // First characters are only accessible when called on data (string or arrayBuffer).
132
+ const firstCharacters = data ? getFirstCharacters(data) : '';
133
+ message += firstCharacters ? ` first bytes: "${firstCharacters}"` : 'first bytes: not available';
134
+ message += ')';
135
+ return message;
101
136
  }
102
-
103
137
  function normalizeLoaders(loaders) {
104
- for (const loader of loaders) {
105
- normalizeLoader(loader);
106
- }
138
+ for (const loader of loaders) {
139
+ (0, normalize_loader_1.normalizeLoader)(loader);
140
+ }
107
141
  }
108
-
142
+ // TODO - Would be nice to support http://example.com/file.glb?parameter=1
143
+ // E.g: x = new URL('http://example.com/file.glb?load=1'; x.pathname
109
144
  function findLoaderByUrl(loaders, url) {
110
- const match = url && EXT_PATTERN.exec(url);
111
- const extension = match && match[1];
112
- return extension ? findLoaderByExtension(loaders, extension) : null;
145
+ // Get extension
146
+ const match = url && EXT_PATTERN.exec(url);
147
+ const extension = match && match[1];
148
+ return extension ? findLoaderByExtension(loaders, extension) : null;
113
149
  }
114
-
115
150
  function findLoaderByExtension(loaders, extension) {
116
- extension = extension.toLowerCase();
117
-
118
- for (const loader of loaders) {
119
- for (const loaderExtension of loader.extensions) {
120
- if (loaderExtension.toLowerCase() === extension) {
121
- return loader;
122
- }
151
+ extension = extension.toLowerCase();
152
+ for (const loader of loaders) {
153
+ for (const loaderExtension of loader.extensions) {
154
+ if (loaderExtension.toLowerCase() === extension) {
155
+ return loader;
156
+ }
157
+ }
123
158
  }
124
- }
125
-
126
- return null;
159
+ return null;
127
160
  }
128
-
129
161
  function findLoaderByMIMEType(loaders, mimeType) {
130
- for (const loader of loaders) {
131
- if (loader.mimeTypes && loader.mimeTypes.includes(mimeType)) {
132
- return loader;
133
- }
134
-
135
- if (mimeType === "application/x.".concat(loader.id)) {
136
- return loader;
162
+ for (const loader of loaders) {
163
+ if (loader.mimeTypes && loader.mimeTypes.includes(mimeType)) {
164
+ return loader;
165
+ }
166
+ // Support referring to loaders using the "unregistered tree"
167
+ // https://en.wikipedia.org/wiki/Media_type#Unregistered_tree
168
+ if (mimeType === `application/x.${loader.id}`) {
169
+ return loader;
170
+ }
137
171
  }
138
- }
139
-
140
- return null;
172
+ return null;
141
173
  }
142
-
143
174
  function findLoaderByInitialBytes(loaders, data) {
144
- if (!data) {
145
- return null;
146
- }
147
-
148
- for (const loader of loaders) {
149
- if (typeof data === 'string') {
150
- if (testDataAgainstText(data, loader)) {
151
- return loader;
152
- }
153
- } else if (ArrayBuffer.isView(data)) {
154
- if (testDataAgainstBinary(data.buffer, data.byteOffset, loader)) {
155
- return loader;
156
- }
157
- } else if (data instanceof ArrayBuffer) {
158
- const byteOffset = 0;
159
-
160
- if (testDataAgainstBinary(data, byteOffset, loader)) {
161
- return loader;
162
- }
175
+ if (!data) {
176
+ return null;
177
+ }
178
+ for (const loader of loaders) {
179
+ if (typeof data === 'string') {
180
+ if (testDataAgainstText(data, loader)) {
181
+ return loader;
182
+ }
183
+ }
184
+ else if (ArrayBuffer.isView(data)) {
185
+ // Typed Arrays can have offsets into underlying buffer
186
+ if (testDataAgainstBinary(data.buffer, data.byteOffset, loader)) {
187
+ return loader;
188
+ }
189
+ }
190
+ else if (data instanceof ArrayBuffer) {
191
+ const byteOffset = 0;
192
+ if (testDataAgainstBinary(data, byteOffset, loader)) {
193
+ return loader;
194
+ }
195
+ }
196
+ // TODO Handle streaming case (requires creating a new AsyncIterator)
163
197
  }
164
- }
165
-
166
- return null;
198
+ return null;
167
199
  }
168
-
169
200
  function testDataAgainstText(data, loader) {
170
- if (loader.testText) {
171
- return loader.testText(data);
172
- }
173
-
174
- const tests = Array.isArray(loader.tests) ? loader.tests : [loader.tests];
175
- return tests.some(test => data.startsWith(test));
201
+ if (loader.testText) {
202
+ return loader.testText(data);
203
+ }
204
+ const tests = Array.isArray(loader.tests) ? loader.tests : [loader.tests];
205
+ return tests.some((test) => data.startsWith(test));
176
206
  }
177
-
178
207
  function testDataAgainstBinary(data, byteOffset, loader) {
179
- const tests = Array.isArray(loader.tests) ? loader.tests : [loader.tests];
180
- return tests.some(test => testBinary(data, byteOffset, loader, test));
208
+ const tests = Array.isArray(loader.tests) ? loader.tests : [loader.tests];
209
+ return tests.some((test) => testBinary(data, byteOffset, loader, test));
181
210
  }
182
-
183
211
  function testBinary(data, byteOffset, loader, test) {
184
- if (test instanceof ArrayBuffer) {
185
- return compareArrayBuffers(test, data, test.byteLength);
186
- }
187
-
188
- switch (typeof test) {
189
- case 'function':
190
- return test(data, loader);
191
-
192
- case 'string':
193
- const magic = getMagicString(data, byteOffset, test.length);
194
- return test === magic;
195
-
196
- default:
197
- return false;
198
- }
212
+ if (test instanceof ArrayBuffer) {
213
+ return (0, loader_utils_1.compareArrayBuffers)(test, data, test.byteLength);
214
+ }
215
+ switch (typeof test) {
216
+ case 'function':
217
+ return test(data, loader);
218
+ case 'string':
219
+ // Magic bytes check: If `test` is a string, check if binary data starts with that strings
220
+ const magic = getMagicString(data, byteOffset, test.length);
221
+ return test === magic;
222
+ default:
223
+ return false;
224
+ }
199
225
  }
200
-
201
226
  function getFirstCharacters(data, length = 5) {
202
- if (typeof data === 'string') {
203
- return data.slice(0, length);
204
- } else if (ArrayBuffer.isView(data)) {
205
- return getMagicString(data.buffer, data.byteOffset, length);
206
- } else if (data instanceof ArrayBuffer) {
207
- const byteOffset = 0;
208
- return getMagicString(data, byteOffset, length);
209
- }
210
-
211
- return '';
227
+ if (typeof data === 'string') {
228
+ return data.slice(0, length);
229
+ }
230
+ else if (ArrayBuffer.isView(data)) {
231
+ // Typed Arrays can have offsets into underlying buffer
232
+ return getMagicString(data.buffer, data.byteOffset, length);
233
+ }
234
+ else if (data instanceof ArrayBuffer) {
235
+ const byteOffset = 0;
236
+ return getMagicString(data, byteOffset, length);
237
+ }
238
+ return '';
212
239
  }
213
-
214
240
  function getMagicString(arrayBuffer, byteOffset, length) {
215
- if (arrayBuffer.byteLength < byteOffset + length) {
216
- return '';
217
- }
218
-
219
- const dataView = new DataView(arrayBuffer);
220
- let magic = '';
221
-
222
- for (let i = 0; i < length; i++) {
223
- magic += String.fromCharCode(dataView.getUint8(byteOffset + i));
224
- }
225
-
226
- return magic;
241
+ if (arrayBuffer.byteLength < byteOffset + length) {
242
+ return '';
243
+ }
244
+ const dataView = new DataView(arrayBuffer);
245
+ let magic = '';
246
+ for (let i = 0; i < length; i++) {
247
+ magic += String.fromCharCode(dataView.getUint8(byteOffset + i));
248
+ }
249
+ return magic;
227
250
  }
228
- //# sourceMappingURL=select-loader.js.map
@@ -0,0 +1,2 @@
1
+ export type { LoaderWithParser } from '@loaders.gl/loader-utils';
2
+ //# sourceMappingURL=common.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/lib/common.ts"],"names":[],"mappings":"AAAA,YAAY,EAAC,gBAAgB,EAAC,MAAM,0BAA0B,CAAC"}
@@ -1,2 +1,2 @@
1
- export {};
2
- //# sourceMappingURL=common.js.map
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ export declare function getErrorMessageFromResponseSync(response: Response): string;
2
+ export declare function getErrorMessageFromResponse(response: Response): Promise<string>;
3
+ //# sourceMappingURL=fetch-error-message.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch-error-message.d.ts","sourceRoot":"","sources":["../../../src/lib/fetch/fetch-error-message.ts"],"names":[],"mappings":"AAAA,wBAAgB,+BAA+B,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAE1E;AAED,wBAAsB,2BAA2B,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAcrF"}
@@ -1,21 +1,25 @@
1
- export function getErrorMessageFromResponseSync(response) {
2
- return "Failed to fetch resource ".concat(response.url, "(").concat(response.status, "): ").concat(response.statusText, " ");
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getErrorMessageFromResponse = exports.getErrorMessageFromResponseSync = void 0;
4
+ function getErrorMessageFromResponseSync(response) {
5
+ return `Failed to fetch resource ${response.url}(${response.status}): ${response.statusText} `;
3
6
  }
4
- export async function getErrorMessageFromResponse(response) {
5
- let message = "Failed to fetch resource ".concat(response.url, " (").concat(response.status, "): ");
6
-
7
- try {
8
- const contentType = response.headers.get('Content-Type') || '';
9
-
10
- if (contentType.includes('application/json')) {
11
- message += await response.text();
12
- } else {
13
- message += response.statusText;
7
+ exports.getErrorMessageFromResponseSync = getErrorMessageFromResponseSync;
8
+ async function getErrorMessageFromResponse(response) {
9
+ let message = `Failed to fetch resource ${response.url} (${response.status}): `;
10
+ try {
11
+ const contentType = response.headers.get('Content-Type') || '';
12
+ if (contentType.includes('application/json')) {
13
+ message += await response.text();
14
+ }
15
+ else {
16
+ message += response.statusText;
17
+ }
18
+ }
19
+ catch (error) {
20
+ // eslint forbids return in finally statement
21
+ return message;
14
22
  }
15
- } catch (error) {
16
23
  return message;
17
- }
18
-
19
- return message;
20
24
  }
21
- //# sourceMappingURL=fetch-error-message.js.map
25
+ exports.getErrorMessageFromResponse = getErrorMessageFromResponse;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * fetch compatible function
3
+ * Reads file data from:
4
+ * - http/http urls
5
+ * - data urls
6
+ * - File/Blob objects
7
+ * Leverages `@loaders.gl/polyfills` for Node.js support
8
+ * Respects pathPrefix and file aliases
9
+ */
10
+ export declare function fetchFile(url: string | Blob, options?: RequestInit & {
11
+ fetch?: RequestInit | Function;
12
+ }): Promise<Response>;
13
+ //# sourceMappingURL=fetch-file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch-file.d.ts","sourceRoot":"","sources":["../../../src/lib/fetch/fetch-file.ts"],"names":[],"mappings":"AAIA;;;;;;;;GAQG;AACH,wBAAsB,SAAS,CAC7B,GAAG,EAAE,MAAM,GAAG,IAAI,EAClB,OAAO,CAAC,EAAE,WAAW,GAAG;IAAC,KAAK,CAAC,EAAE,WAAW,GAAG,QAAQ,CAAA;CAAC,GACvD,OAAO,CAAC,QAAQ,CAAC,CAanB"}
@@ -1,17 +1,27 @@
1
- import { resolvePath } from '@loaders.gl/loader-utils';
2
- import { makeResponse } from '../utils/response-utils';
3
- export async function fetchFile(url, options) {
4
- if (typeof url === 'string') {
5
- url = resolvePath(url);
6
- let fetchOptions = options;
7
-
8
- if (options !== null && options !== void 0 && options.fetch && typeof (options === null || options === void 0 ? void 0 : options.fetch) !== 'function') {
9
- fetchOptions = options.fetch;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchFile = void 0;
4
+ const loader_utils_1 = require("@loaders.gl/loader-utils");
5
+ const response_utils_1 = require("../utils/response-utils");
6
+ // import {getErrorMessageFromResponse} from './fetch-error-message.js';
7
+ /**
8
+ * fetch compatible function
9
+ * Reads file data from:
10
+ * - http/http urls
11
+ * - data urls
12
+ * - File/Blob objects
13
+ * Leverages `@loaders.gl/polyfills` for Node.js support
14
+ * Respects pathPrefix and file aliases
15
+ */
16
+ async function fetchFile(url, options) {
17
+ if (typeof url === 'string') {
18
+ url = (0, loader_utils_1.resolvePath)(url);
19
+ let fetchOptions = options;
20
+ if (options?.fetch && typeof options?.fetch !== 'function') {
21
+ fetchOptions = options.fetch;
22
+ }
23
+ return await fetch(url, fetchOptions);
10
24
  }
11
-
12
- return await fetch(url, fetchOptions);
13
- }
14
-
15
- return await makeResponse(url);
25
+ return await (0, response_utils_1.makeResponse)(url);
16
26
  }
17
- //# sourceMappingURL=fetch-file.js.map
27
+ exports.fetchFile = fetchFile;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Reads a chunk from a random access file
3
+ * @param file
4
+ * @param start
5
+ * @param length
6
+ * @returns
7
+ */
8
+ export declare function readArrayBuffer(file: Blob | ArrayBuffer | string | number, start: number, length: number): Promise<ArrayBuffer>;
9
+ /**
10
+ * Read a slice of a Blob or File, without loading the entire file into memory
11
+ * The trick when reading File objects is to read successive "slices" of the File
12
+ * Per spec https://w3c.github.io/FileAPI/, slicing a File only updates the start and end fields
13
+ * Actually reading from file happens in `readAsArrayBuffer`
14
+ * @param blob to read
15
+ */
16
+ export declare function readBlob(blob: Blob): Promise<ArrayBuffer>;
17
+ //# sourceMappingURL=read-array-buffer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-array-buffer.d.ts","sourceRoot":"","sources":["../../../src/lib/fetch/read-array-buffer.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,wBAAsB,eAAe,CACnC,IAAI,EAAE,IAAI,GAAG,WAAW,GAAG,MAAM,GAAG,MAAM,EAC1C,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,WAAW,CAAC,CAUtB;AAED;;;;;;GAMG;AACH,wBAAsB,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC,CAS/D"}