@fireproof/vendor 0.0.0-smoke

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 (480) hide show
  1. package/package.json +29 -0
  2. package/patched/@ipld/dag-json/.github/dependabot.yml +11 -0
  3. package/patched/@ipld/dag-json/.github/workflows/js-test-and-release.yml +28 -0
  4. package/patched/@ipld/dag-json/CHANGELOG.md +202 -0
  5. package/patched/@ipld/dag-json/LICENSE +4 -0
  6. package/patched/@ipld/dag-json/LICENSE-APACHE +5 -0
  7. package/patched/@ipld/dag-json/LICENSE-MIT +19 -0
  8. package/patched/@ipld/dag-json/README.md +58 -0
  9. package/patched/@ipld/dag-json/ipld-dag-json-10.2.3.tgz +0 -0
  10. package/patched/@ipld/dag-json/package.json +173 -0
  11. package/patched/@ipld/dag-json/src/index.js +291 -0
  12. package/patched/@ipld/dag-json/test/test-basics.spec.js +290 -0
  13. package/patched/@ipld/dag-json/test/ts-use/package.json +11 -0
  14. package/patched/@ipld/dag-json/test/ts-use/src/main.ts +54 -0
  15. package/patched/@ipld/dag-json/test/ts-use/tsconfig.json +9 -0
  16. package/patched/@ipld/dag-json/tsconfig.json +14 -0
  17. package/patched/cborg/.github/dependabot.yml +16 -0
  18. package/patched/cborg/.github/workflows/test-and-release.yml +52 -0
  19. package/patched/cborg/CHANGELOG.md +513 -0
  20. package/patched/cborg/LICENSE +13 -0
  21. package/patched/cborg/README.md +515 -0
  22. package/patched/cborg/bench/bench.js +117 -0
  23. package/patched/cborg/bench/json.js +124 -0
  24. package/patched/cborg/bench/package.json +8 -0
  25. package/patched/cborg/cborg-4.2.7.tgz +0 -0
  26. package/patched/cborg/cborg.js +31 -0
  27. package/patched/cborg/example-bytestrings.js +180 -0
  28. package/patched/cborg/example-json.js +6 -0
  29. package/patched/cborg/example.js +5 -0
  30. package/patched/cborg/interface.ts +56 -0
  31. package/patched/cborg/lib/0uint.js +227 -0
  32. package/patched/cborg/lib/1negint.js +111 -0
  33. package/patched/cborg/lib/2bytes.js +133 -0
  34. package/patched/cborg/lib/3string.js +90 -0
  35. package/patched/cborg/lib/4array.js +113 -0
  36. package/patched/cborg/lib/5map.js +113 -0
  37. package/patched/cborg/lib/6tag.js +80 -0
  38. package/patched/cborg/lib/7float.js +308 -0
  39. package/patched/cborg/lib/bin.js +189 -0
  40. package/patched/cborg/lib/bl.js +124 -0
  41. package/patched/cborg/lib/byte-utils.js +417 -0
  42. package/patched/cborg/lib/common.js +27 -0
  43. package/patched/cborg/lib/decode.js +209 -0
  44. package/patched/cborg/lib/diagnostic.js +156 -0
  45. package/patched/cborg/lib/diagnostic_test.js +117 -0
  46. package/patched/cborg/lib/encode.js +464 -0
  47. package/patched/cborg/lib/is.js +106 -0
  48. package/patched/cborg/lib/json/decode.js +462 -0
  49. package/patched/cborg/lib/json/encode.js +299 -0
  50. package/patched/cborg/lib/json/json.js +4 -0
  51. package/patched/cborg/lib/jump.js +209 -0
  52. package/patched/cborg/lib/length.js +61 -0
  53. package/patched/cborg/lib/token.js +76 -0
  54. package/patched/cborg/package.json +169 -0
  55. package/patched/cborg/pnpm-lock.yaml +6096 -0
  56. package/patched/cborg/taglib.js +73 -0
  57. package/patched/cborg/test/appendix_a.js +647 -0
  58. package/patched/cborg/test/common.js +18 -0
  59. package/patched/cborg/test/node-test-bin.js +402 -0
  60. package/patched/cborg/test/noop-bin-test.js +3 -0
  61. package/patched/cborg/test/test-0uint.js +103 -0
  62. package/patched/cborg/test/test-1negint.js +96 -0
  63. package/patched/cborg/test/test-2bytes.js +198 -0
  64. package/patched/cborg/test/test-3string.js +136 -0
  65. package/patched/cborg/test/test-4array.js +93 -0
  66. package/patched/cborg/test/test-5map.js +284 -0
  67. package/patched/cborg/test/test-6tag.js +85 -0
  68. package/patched/cborg/test/test-7float.js +131 -0
  69. package/patched/cborg/test/test-bl.js +37 -0
  70. package/patched/cborg/test/test-cbor-vectors.js +107 -0
  71. package/patched/cborg/test/test-decode-errors.js +65 -0
  72. package/patched/cborg/test/test-fuzz.js +42 -0
  73. package/patched/cborg/test/test-json.js +219 -0
  74. package/patched/cborg/test/test-length.js +65 -0
  75. package/patched/cborg/test/test-partial.js +111 -0
  76. package/patched/cborg/tsconfig.json +45 -0
  77. package/patched/cborg/types/cborg.d.ts +28 -0
  78. package/patched/cborg/types/cborg.d.ts.map +1 -0
  79. package/patched/cborg/types/example.d.ts +2 -0
  80. package/patched/cborg/types/example.d.ts.map +1 -0
  81. package/patched/cborg/types/interface.d.ts +47 -0
  82. package/patched/cborg/types/interface.d.ts.map +1 -0
  83. package/patched/cborg/types/lib/0uint.d.ts +100 -0
  84. package/patched/cborg/types/lib/0uint.d.ts.map +1 -0
  85. package/patched/cborg/types/lib/1negint.d.ts +58 -0
  86. package/patched/cborg/types/lib/1negint.d.ts.map +1 -0
  87. package/patched/cborg/types/lib/2bytes.d.ts +68 -0
  88. package/patched/cborg/types/lib/2bytes.d.ts.map +1 -0
  89. package/patched/cborg/types/lib/3string.d.ts +46 -0
  90. package/patched/cborg/types/lib/3string.d.ts.map +1 -0
  91. package/patched/cborg/types/lib/4array.d.ts +65 -0
  92. package/patched/cborg/types/lib/4array.d.ts.map +1 -0
  93. package/patched/cborg/types/lib/5map.d.ts +65 -0
  94. package/patched/cborg/types/lib/5map.d.ts.map +1 -0
  95. package/patched/cborg/types/lib/6tag.d.ts +61 -0
  96. package/patched/cborg/types/lib/6tag.d.ts.map +1 -0
  97. package/patched/cborg/types/lib/7float.d.ts +60 -0
  98. package/patched/cborg/types/lib/7float.d.ts.map +1 -0
  99. package/patched/cborg/types/lib/bin.d.ts +4 -0
  100. package/patched/cborg/types/lib/bin.d.ts.map +1 -0
  101. package/patched/cborg/types/lib/bl.d.ts +26 -0
  102. package/patched/cborg/types/lib/bl.d.ts.map +1 -0
  103. package/patched/cborg/types/lib/byte-utils.d.ts +53 -0
  104. package/patched/cborg/types/lib/byte-utils.d.ts.map +1 -0
  105. package/patched/cborg/types/lib/common.d.ts +10 -0
  106. package/patched/cborg/types/lib/common.d.ts.map +1 -0
  107. package/patched/cborg/types/lib/decode.d.ts +41 -0
  108. package/patched/cborg/types/lib/decode.d.ts.map +1 -0
  109. package/patched/cborg/types/lib/diagnostic.d.ts +12 -0
  110. package/patched/cborg/types/lib/diagnostic.d.ts.map +1 -0
  111. package/patched/cborg/types/lib/diagnostic_test.d.ts +2 -0
  112. package/patched/cborg/types/lib/diagnostic_test.d.ts.map +1 -0
  113. package/patched/cborg/types/lib/encode.d.ts +50 -0
  114. package/patched/cborg/types/lib/encode.d.ts.map +1 -0
  115. package/patched/cborg/types/lib/is.d.ts +6 -0
  116. package/patched/cborg/types/lib/is.d.ts.map +1 -0
  117. package/patched/cborg/types/lib/json/decode.d.ts +67 -0
  118. package/patched/cborg/types/lib/json/decode.d.ts.map +1 -0
  119. package/patched/cborg/types/lib/json/encode.d.ts +11 -0
  120. package/patched/cborg/types/lib/json/encode.d.ts.map +1 -0
  121. package/patched/cborg/types/lib/json/forward-cborg.d.ts +6 -0
  122. package/patched/cborg/types/lib/json/forward-cborg.d.ts.map +1 -0
  123. package/patched/cborg/types/lib/json/json.d.ts +6 -0
  124. package/patched/cborg/types/lib/json/json.d.ts.map +1 -0
  125. package/patched/cborg/types/lib/jump.d.ts +12 -0
  126. package/patched/cborg/types/lib/jump.d.ts.map +1 -0
  127. package/patched/cborg/types/lib/length.d.ts +27 -0
  128. package/patched/cborg/types/lib/length.d.ts.map +1 -0
  129. package/patched/cborg/types/lib/token.d.ts +59 -0
  130. package/patched/cborg/types/lib/token.d.ts.map +1 -0
  131. package/patched/cborg/types/taglib.d.ts +18 -0
  132. package/patched/cborg/types/taglib.d.ts.map +1 -0
  133. package/patched/cborg/types/tsconfig.tsbuildinfo +1 -0
  134. package/src/@ipld/car/car/LICENSE +4 -0
  135. package/src/@ipld/car/car/README.md +1078 -0
  136. package/src/@ipld/car/car/dist/index.min.js +5 -0
  137. package/src/@ipld/car/car/dist/src/api.d.ts +72 -0
  138. package/src/@ipld/car/car/dist/src/api.d.ts.map +1 -0
  139. package/src/@ipld/car/car/dist/src/buffer-decoder.d.ts +67 -0
  140. package/src/@ipld/car/car/dist/src/buffer-decoder.d.ts.map +1 -0
  141. package/src/@ipld/car/car/dist/src/buffer-reader-browser.d.ts +116 -0
  142. package/src/@ipld/car/car/dist/src/buffer-reader-browser.d.ts.map +1 -0
  143. package/src/@ipld/car/car/dist/src/buffer-reader.d.ts +31 -0
  144. package/src/@ipld/car/car/dist/src/buffer-reader.d.ts.map +1 -0
  145. package/src/@ipld/car/car/dist/src/buffer-writer.d.ts +86 -0
  146. package/src/@ipld/car/car/dist/src/buffer-writer.d.ts.map +1 -0
  147. package/src/@ipld/car/car/dist/src/coding.d.ts +49 -0
  148. package/src/@ipld/car/car/dist/src/coding.d.ts.map +1 -0
  149. package/src/@ipld/car/car/dist/src/decoder-common.d.ts +43 -0
  150. package/src/@ipld/car/car/dist/src/decoder-common.d.ts.map +1 -0
  151. package/src/@ipld/car/car/dist/src/decoder.d.ts +87 -0
  152. package/src/@ipld/car/car/dist/src/decoder.d.ts.map +1 -0
  153. package/src/@ipld/car/car/dist/src/encoder.d.ts +17 -0
  154. package/src/@ipld/car/car/dist/src/encoder.d.ts.map +1 -0
  155. package/src/@ipld/car/car/dist/src/header-validator.d.ts +5 -0
  156. package/src/@ipld/car/car/dist/src/header-validator.d.ts.map +1 -0
  157. package/src/@ipld/car/car/dist/src/index-browser.d.ts +10 -0
  158. package/src/@ipld/car/car/dist/src/index-browser.d.ts.map +1 -0
  159. package/src/@ipld/car/car/dist/src/index.d.ts +11 -0
  160. package/src/@ipld/car/car/dist/src/index.d.ts.map +1 -0
  161. package/src/@ipld/car/car/dist/src/indexed-reader-browser.d.ts +5 -0
  162. package/src/@ipld/car/car/dist/src/indexed-reader-browser.d.ts.map +1 -0
  163. package/src/@ipld/car/car/dist/src/indexed-reader.d.ts +152 -0
  164. package/src/@ipld/car/car/dist/src/indexed-reader.d.ts.map +1 -0
  165. package/src/@ipld/car/car/dist/src/indexer.d.ts +95 -0
  166. package/src/@ipld/car/car/dist/src/indexer.d.ts.map +1 -0
  167. package/src/@ipld/car/car/dist/src/iterator-channel.d.ts +7 -0
  168. package/src/@ipld/car/car/dist/src/iterator-channel.d.ts.map +1 -0
  169. package/src/@ipld/car/car/dist/src/iterator.d.ts +174 -0
  170. package/src/@ipld/car/car/dist/src/iterator.d.ts.map +1 -0
  171. package/src/@ipld/car/car/dist/src/reader-browser.d.ts +151 -0
  172. package/src/@ipld/car/car/dist/src/reader-browser.d.ts.map +1 -0
  173. package/src/@ipld/car/car/dist/src/reader.d.ts +35 -0
  174. package/src/@ipld/car/car/dist/src/reader.d.ts.map +1 -0
  175. package/src/@ipld/car/car/dist/src/writer-browser.d.ts +155 -0
  176. package/src/@ipld/car/car/dist/src/writer-browser.d.ts.map +1 -0
  177. package/src/@ipld/car/car/dist/src/writer.d.ts +45 -0
  178. package/src/@ipld/car/car/dist/src/writer.d.ts.map +1 -0
  179. package/src/@ipld/car/car/node_modules/.bin/cborg +17 -0
  180. package/src/@ipld/car/car/package.json +235 -0
  181. package/src/@ipld/car/car/src/api.ts +90 -0
  182. package/src/@ipld/car/car/src/buffer-decoder.js +213 -0
  183. package/src/@ipld/car/car/src/buffer-reader-browser.js +144 -0
  184. package/src/@ipld/car/car/src/buffer-reader.js +51 -0
  185. package/src/@ipld/car/car/src/buffer-writer.js +286 -0
  186. package/src/@ipld/car/car/src/coding.ts +68 -0
  187. package/src/@ipld/car/car/src/decoder-common.js +82 -0
  188. package/src/@ipld/car/car/src/decoder.js +347 -0
  189. package/src/@ipld/car/car/src/encoder.js +76 -0
  190. package/src/@ipld/car/car/src/header-validator.js +214 -0
  191. package/src/@ipld/car/car/src/header.ipldsch +18 -0
  192. package/src/@ipld/car/car/src/index-browser.js +18 -0
  193. package/src/@ipld/car/car/src/index.js +21 -0
  194. package/src/@ipld/car/car/src/indexed-reader-browser.js +7 -0
  195. package/src/@ipld/car/car/src/indexed-reader.js +211 -0
  196. package/src/@ipld/car/car/src/indexer.js +130 -0
  197. package/src/@ipld/car/car/src/iterator-channel.js +91 -0
  198. package/src/@ipld/car/car/src/iterator.js +267 -0
  199. package/src/@ipld/car/car/src/reader-browser.js +194 -0
  200. package/src/@ipld/car/car/src/reader.js +56 -0
  201. package/src/@ipld/car/car/src/writer-browser.js +250 -0
  202. package/src/@ipld/car/car/src/writer.js +84 -0
  203. package/src/@ipld/dag-cbor/dag-cbor/LICENSE +4 -0
  204. package/src/@ipld/dag-cbor/dag-cbor/README.md +80 -0
  205. package/src/@ipld/dag-cbor/dag-cbor/dist/index.min.js +3 -0
  206. package/src/@ipld/dag-cbor/dag-cbor/dist/src/index.d.ts +67 -0
  207. package/src/@ipld/dag-cbor/dag-cbor/dist/src/index.d.ts.map +1 -0
  208. package/src/@ipld/dag-cbor/dag-cbor/node_modules/.bin/cborg +17 -0
  209. package/src/@ipld/dag-cbor/dag-cbor/package.json +171 -0
  210. package/src/@ipld/dag-cbor/dag-cbor/src/index.js +147 -0
  211. package/src/@ipld/dag-json/dag-json/LICENSE +4 -0
  212. package/src/@ipld/dag-json/dag-json/README.md +58 -0
  213. package/src/@ipld/dag-json/dag-json/dist/index.min.js +3 -0
  214. package/src/@ipld/dag-json/dag-json/dist/src/index.d.ts +12 -0
  215. package/src/@ipld/dag-json/dag-json/dist/src/index.d.ts.map +1 -0
  216. package/src/@ipld/dag-json/dag-json/node_modules/.bin/cborg +17 -0
  217. package/src/@ipld/dag-json/dag-json/package.json +173 -0
  218. package/src/@ipld/dag-json/dag-json/src/index.js +291 -0
  219. package/src/@web3-storage/pail/pail/LICENSE.md +232 -0
  220. package/src/@web3-storage/pail/pail/README.md +84 -0
  221. package/src/@web3-storage/pail/pail/cli.js +218 -0
  222. package/src/@web3-storage/pail/pail/dist/src/api.d.ts +59 -0
  223. package/src/@web3-storage/pail/pail/dist/src/api.d.ts.map +1 -0
  224. package/src/@web3-storage/pail/pail/dist/src/batch/api.d.ts +31 -0
  225. package/src/@web3-storage/pail/pail/dist/src/batch/api.d.ts.map +1 -0
  226. package/src/@web3-storage/pail/pail/dist/src/batch/index.d.ts +75 -0
  227. package/src/@web3-storage/pail/pail/dist/src/batch/index.d.ts.map +1 -0
  228. package/src/@web3-storage/pail/pail/dist/src/batch/shard.d.ts +3 -0
  229. package/src/@web3-storage/pail/pail/dist/src/batch/shard.d.ts.map +1 -0
  230. package/src/@web3-storage/pail/pail/dist/src/block.d.ts +35 -0
  231. package/src/@web3-storage/pail/pail/dist/src/block.d.ts.map +1 -0
  232. package/src/@web3-storage/pail/pail/dist/src/clock/api.d.ts +10 -0
  233. package/src/@web3-storage/pail/pail/dist/src/clock/api.d.ts.map +1 -0
  234. package/src/@web3-storage/pail/pail/dist/src/clock/index.d.ts +48 -0
  235. package/src/@web3-storage/pail/pail/dist/src/clock/index.d.ts.map +1 -0
  236. package/src/@web3-storage/pail/pail/dist/src/crdt/api.d.ts +26 -0
  237. package/src/@web3-storage/pail/pail/dist/src/crdt/api.d.ts.map +1 -0
  238. package/src/@web3-storage/pail/pail/dist/src/crdt/batch/api.d.ts +11 -0
  239. package/src/@web3-storage/pail/pail/dist/src/crdt/batch/api.d.ts.map +1 -0
  240. package/src/@web3-storage/pail/pail/dist/src/crdt/batch/index.d.ts +5 -0
  241. package/src/@web3-storage/pail/pail/dist/src/crdt/batch/index.d.ts.map +1 -0
  242. package/src/@web3-storage/pail/pail/dist/src/crdt/index.d.ts +9 -0
  243. package/src/@web3-storage/pail/pail/dist/src/crdt/index.d.ts.map +1 -0
  244. package/src/@web3-storage/pail/pail/dist/src/diff.d.ts +13 -0
  245. package/src/@web3-storage/pail/pail/dist/src/diff.d.ts.map +1 -0
  246. package/src/@web3-storage/pail/pail/dist/src/index.d.ts +10 -0
  247. package/src/@web3-storage/pail/pail/dist/src/index.d.ts.map +1 -0
  248. package/src/@web3-storage/pail/pail/dist/src/merge.d.ts +5 -0
  249. package/src/@web3-storage/pail/pail/dist/src/merge.d.ts.map +1 -0
  250. package/src/@web3-storage/pail/pail/dist/src/shard.d.ts +43 -0
  251. package/src/@web3-storage/pail/pail/dist/src/shard.d.ts.map +1 -0
  252. package/src/@web3-storage/pail/pail/dist/tsconfig.tsbuildinfo +1 -0
  253. package/src/@web3-storage/pail/pail/node_modules/.bin/pail +17 -0
  254. package/src/@web3-storage/pail/pail/package.json +173 -0
  255. package/src/@web3-storage/pail/pail/src/api.js +1 -0
  256. package/src/@web3-storage/pail/pail/src/api.ts +90 -0
  257. package/src/@web3-storage/pail/pail/src/batch/api.js +1 -0
  258. package/src/@web3-storage/pail/pail/src/batch/api.ts +59 -0
  259. package/src/@web3-storage/pail/pail/src/batch/index.js +258 -0
  260. package/src/@web3-storage/pail/pail/src/batch/shard.js +13 -0
  261. package/src/@web3-storage/pail/pail/src/block.js +75 -0
  262. package/src/@web3-storage/pail/pail/src/clock/api.js +1 -0
  263. package/src/@web3-storage/pail/pail/src/clock/api.ts +12 -0
  264. package/src/@web3-storage/pail/pail/src/clock/index.js +182 -0
  265. package/src/@web3-storage/pail/pail/src/crdt/api.js +1 -0
  266. package/src/@web3-storage/pail/pail/src/crdt/api.ts +33 -0
  267. package/src/@web3-storage/pail/pail/src/crdt/batch/api.js +1 -0
  268. package/src/@web3-storage/pail/pail/src/crdt/batch/api.ts +30 -0
  269. package/src/@web3-storage/pail/pail/src/crdt/batch/index.js +155 -0
  270. package/src/@web3-storage/pail/pail/src/crdt/index.js +354 -0
  271. package/src/@web3-storage/pail/pail/src/diff.js +151 -0
  272. package/src/@web3-storage/pail/pail/src/index.js +406 -0
  273. package/src/@web3-storage/pail/pail/src/merge.js +43 -0
  274. package/src/@web3-storage/pail/pail/src/shard.js +180 -0
  275. package/src/cborg/cborg/.github/dependabot.yml +16 -0
  276. package/src/cborg/cborg/.github/workflows/test-and-release.yml +52 -0
  277. package/src/cborg/cborg/CHANGELOG.md +513 -0
  278. package/src/cborg/cborg/LICENSE +13 -0
  279. package/src/cborg/cborg/README.md +515 -0
  280. package/src/cborg/cborg/bench/bench.js +117 -0
  281. package/src/cborg/cborg/bench/json.js +124 -0
  282. package/src/cborg/cborg/bench/package.json +8 -0
  283. package/src/cborg/cborg/cborg.js +31 -0
  284. package/src/cborg/cborg/example-bytestrings.js +180 -0
  285. package/src/cborg/cborg/example-json.js +6 -0
  286. package/src/cborg/cborg/example.js +5 -0
  287. package/src/cborg/cborg/interface.ts +56 -0
  288. package/src/cborg/cborg/lib/0uint.js +227 -0
  289. package/src/cborg/cborg/lib/1negint.js +111 -0
  290. package/src/cborg/cborg/lib/2bytes.js +133 -0
  291. package/src/cborg/cborg/lib/3string.js +90 -0
  292. package/src/cborg/cborg/lib/4array.js +113 -0
  293. package/src/cborg/cborg/lib/5map.js +113 -0
  294. package/src/cborg/cborg/lib/6tag.js +80 -0
  295. package/src/cborg/cborg/lib/7float.js +308 -0
  296. package/src/cborg/cborg/lib/bin.js +189 -0
  297. package/src/cborg/cborg/lib/bl.js +124 -0
  298. package/src/cborg/cborg/lib/byte-utils.js +417 -0
  299. package/src/cborg/cborg/lib/common.js +27 -0
  300. package/src/cborg/cborg/lib/decode.js +209 -0
  301. package/src/cborg/cborg/lib/diagnostic.js +156 -0
  302. package/src/cborg/cborg/lib/diagnostic_test.js +117 -0
  303. package/src/cborg/cborg/lib/encode.js +464 -0
  304. package/src/cborg/cborg/lib/is.js +106 -0
  305. package/src/cborg/cborg/lib/json/decode.js +462 -0
  306. package/src/cborg/cborg/lib/json/encode.js +299 -0
  307. package/src/cborg/cborg/lib/json/json.js +4 -0
  308. package/src/cborg/cborg/lib/jump.js +209 -0
  309. package/src/cborg/cborg/lib/length.js +61 -0
  310. package/src/cborg/cborg/lib/token.js +76 -0
  311. package/src/cborg/cborg/node_modules/.bin/cborg +17 -0
  312. package/src/cborg/cborg/package.json +168 -0
  313. package/src/cborg/cborg/taglib.js +73 -0
  314. package/src/cborg/cborg/test/appendix_a.js +647 -0
  315. package/src/cborg/cborg/test/common.js +18 -0
  316. package/src/cborg/cborg/test/node-test-bin.js +402 -0
  317. package/src/cborg/cborg/test/noop-bin-test.js +3 -0
  318. package/src/cborg/cborg/test/test-0uint.js +103 -0
  319. package/src/cborg/cborg/test/test-1negint.js +96 -0
  320. package/src/cborg/cborg/test/test-2bytes.js +198 -0
  321. package/src/cborg/cborg/test/test-3string.js +136 -0
  322. package/src/cborg/cborg/test/test-4array.js +93 -0
  323. package/src/cborg/cborg/test/test-5map.js +284 -0
  324. package/src/cborg/cborg/test/test-6tag.js +85 -0
  325. package/src/cborg/cborg/test/test-7float.js +131 -0
  326. package/src/cborg/cborg/test/test-bl.js +37 -0
  327. package/src/cborg/cborg/test/test-cbor-vectors.js +107 -0
  328. package/src/cborg/cborg/test/test-decode-errors.js +65 -0
  329. package/src/cborg/cborg/test/test-fuzz.js +42 -0
  330. package/src/cborg/cborg/test/test-json.js +219 -0
  331. package/src/cborg/cborg/test/test-length.js +65 -0
  332. package/src/cborg/cborg/test/test-partial.js +111 -0
  333. package/src/cborg/cborg/tsconfig.json +45 -0
  334. package/src/cborg/cborg/types/cborg.d.ts +28 -0
  335. package/src/cborg/cborg/types/cborg.d.ts.map +1 -0
  336. package/src/cborg/cborg/types/example.d.ts +2 -0
  337. package/src/cborg/cborg/types/example.d.ts.map +1 -0
  338. package/src/cborg/cborg/types/interface.d.ts +47 -0
  339. package/src/cborg/cborg/types/interface.d.ts.map +1 -0
  340. package/src/cborg/cborg/types/lib/0uint.d.ts +100 -0
  341. package/src/cborg/cborg/types/lib/0uint.d.ts.map +1 -0
  342. package/src/cborg/cborg/types/lib/1negint.d.ts +58 -0
  343. package/src/cborg/cborg/types/lib/1negint.d.ts.map +1 -0
  344. package/src/cborg/cborg/types/lib/2bytes.d.ts +68 -0
  345. package/src/cborg/cborg/types/lib/2bytes.d.ts.map +1 -0
  346. package/src/cborg/cborg/types/lib/3string.d.ts +46 -0
  347. package/src/cborg/cborg/types/lib/3string.d.ts.map +1 -0
  348. package/src/cborg/cborg/types/lib/4array.d.ts +65 -0
  349. package/src/cborg/cborg/types/lib/4array.d.ts.map +1 -0
  350. package/src/cborg/cborg/types/lib/5map.d.ts +65 -0
  351. package/src/cborg/cborg/types/lib/5map.d.ts.map +1 -0
  352. package/src/cborg/cborg/types/lib/6tag.d.ts +61 -0
  353. package/src/cborg/cborg/types/lib/6tag.d.ts.map +1 -0
  354. package/src/cborg/cborg/types/lib/7float.d.ts +60 -0
  355. package/src/cborg/cborg/types/lib/7float.d.ts.map +1 -0
  356. package/src/cborg/cborg/types/lib/bin.d.ts +4 -0
  357. package/src/cborg/cborg/types/lib/bin.d.ts.map +1 -0
  358. package/src/cborg/cborg/types/lib/bl.d.ts +26 -0
  359. package/src/cborg/cborg/types/lib/bl.d.ts.map +1 -0
  360. package/src/cborg/cborg/types/lib/byte-utils.d.ts +53 -0
  361. package/src/cborg/cborg/types/lib/byte-utils.d.ts.map +1 -0
  362. package/src/cborg/cborg/types/lib/common.d.ts +10 -0
  363. package/src/cborg/cborg/types/lib/common.d.ts.map +1 -0
  364. package/src/cborg/cborg/types/lib/decode.d.ts +41 -0
  365. package/src/cborg/cborg/types/lib/decode.d.ts.map +1 -0
  366. package/src/cborg/cborg/types/lib/diagnostic.d.ts +12 -0
  367. package/src/cborg/cborg/types/lib/diagnostic.d.ts.map +1 -0
  368. package/src/cborg/cborg/types/lib/diagnostic_test.d.ts +2 -0
  369. package/src/cborg/cborg/types/lib/diagnostic_test.d.ts.map +1 -0
  370. package/src/cborg/cborg/types/lib/encode.d.ts +50 -0
  371. package/src/cborg/cborg/types/lib/encode.d.ts.map +1 -0
  372. package/src/cborg/cborg/types/lib/is.d.ts +6 -0
  373. package/src/cborg/cborg/types/lib/is.d.ts.map +1 -0
  374. package/src/cborg/cborg/types/lib/json/decode.d.ts +67 -0
  375. package/src/cborg/cborg/types/lib/json/decode.d.ts.map +1 -0
  376. package/src/cborg/cborg/types/lib/json/encode.d.ts +11 -0
  377. package/src/cborg/cborg/types/lib/json/encode.d.ts.map +1 -0
  378. package/src/cborg/cborg/types/lib/json/forward-cborg.d.ts +6 -0
  379. package/src/cborg/cborg/types/lib/json/forward-cborg.d.ts.map +1 -0
  380. package/src/cborg/cborg/types/lib/json/json.d.ts +6 -0
  381. package/src/cborg/cborg/types/lib/json/json.d.ts.map +1 -0
  382. package/src/cborg/cborg/types/lib/jump.d.ts +12 -0
  383. package/src/cborg/cborg/types/lib/jump.d.ts.map +1 -0
  384. package/src/cborg/cborg/types/lib/length.d.ts +27 -0
  385. package/src/cborg/cborg/types/lib/length.d.ts.map +1 -0
  386. package/src/cborg/cborg/types/lib/token.d.ts +59 -0
  387. package/src/cborg/cborg/types/lib/token.d.ts.map +1 -0
  388. package/src/cborg/cborg/types/taglib.d.ts +18 -0
  389. package/src/cborg/cborg/types/taglib.d.ts.map +1 -0
  390. package/src/cborg/cborg/types/tsconfig.tsbuildinfo +1 -0
  391. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/LICENSE +4 -0
  392. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/README.md +105 -0
  393. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/index.min.js +3 -0
  394. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/errors.d.ts +57 -0
  395. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/errors.d.ts.map +1 -0
  396. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/errors.js +73 -0
  397. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/errors.js.map +1 -0
  398. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/index.d.ts +355 -0
  399. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/index.d.ts.map +1 -0
  400. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/index.js +197 -0
  401. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/index.js.map +1 -0
  402. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/dag-cbor.d.ts +4 -0
  403. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/dag-cbor.d.ts.map +1 -0
  404. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/dag-cbor.js +9 -0
  405. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/dag-cbor.js.map +1 -0
  406. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/dag-json.d.ts +4 -0
  407. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/dag-json.d.ts.map +1 -0
  408. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/dag-json.js +9 -0
  409. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/dag-json.js.map +1 -0
  410. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/identity.d.ts +4 -0
  411. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/identity.d.ts.map +1 -0
  412. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/identity.js +38 -0
  413. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/identity.js.map +1 -0
  414. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/index.d.ts +4 -0
  415. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/index.d.ts.map +1 -0
  416. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/index.js +30 -0
  417. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/index.js.map +1 -0
  418. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/json.d.ts +4 -0
  419. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/json.d.ts.map +1 -0
  420. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/json.js +9 -0
  421. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/json.js.map +1 -0
  422. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/raw.d.ts +4 -0
  423. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/raw.d.ts.map +1 -0
  424. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/raw.js +37 -0
  425. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/raw.js.map +1 -0
  426. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/directory.d.ts +4 -0
  427. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/directory.d.ts.map +1 -0
  428. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/directory.js +29 -0
  429. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/directory.js.map +1 -0
  430. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/file.d.ts +4 -0
  431. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/file.d.ts.map +1 -0
  432. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/file.js +153 -0
  433. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/file.js.map +1 -0
  434. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/hamt-sharded-directory.d.ts +4 -0
  435. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/hamt-sharded-directory.d.ts.map +1 -0
  436. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/hamt-sharded-directory.js +59 -0
  437. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/hamt-sharded-directory.js.map +1 -0
  438. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/raw.d.ts +4 -0
  439. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/raw.d.ts.map +1 -0
  440. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/raw.js +25 -0
  441. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/raw.js.map +1 -0
  442. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/index.d.ts +4 -0
  443. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/index.d.ts.map +1 -0
  444. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/index.js +104 -0
  445. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/index.js.map +1 -0
  446. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/extract-data-from-block.d.ts +3 -0
  447. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/extract-data-from-block.d.ts.map +1 -0
  448. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/extract-data-from-block.js +20 -0
  449. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/extract-data-from-block.js.map +1 -0
  450. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/find-cid-in-shard.d.ts +6 -0
  451. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/find-cid-in-shard.d.ts.map +1 -0
  452. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/find-cid-in-shard.js +116 -0
  453. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/find-cid-in-shard.js.map +1 -0
  454. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/resolve-object-path.d.ts +4 -0
  455. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/resolve-object-path.d.ts.map +1 -0
  456. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/resolve-object-path.js +57 -0
  457. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/resolve-object-path.js.map +1 -0
  458. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/validate-offset-and-length.d.ts +6 -0
  459. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/validate-offset-and-length.d.ts.map +1 -0
  460. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/validate-offset-and-length.js +30 -0
  461. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/validate-offset-and-length.js.map +1 -0
  462. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/typedoc-urls.json +58 -0
  463. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/package.json +180 -0
  464. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/errors.ts +87 -0
  465. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/index.ts +498 -0
  466. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/resolvers/dag-cbor.ts +12 -0
  467. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/resolvers/dag-json.ts +12 -0
  468. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/resolvers/identity.ts +49 -0
  469. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/resolvers/index.ts +35 -0
  470. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/resolvers/json.ts +12 -0
  471. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/resolvers/raw.ts +49 -0
  472. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/directory.ts +39 -0
  473. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/file.ts +198 -0
  474. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/hamt-sharded-directory.ts +76 -0
  475. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/raw.ts +37 -0
  476. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/index.ts +121 -0
  477. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/utils/extract-data-from-block.ts +24 -0
  478. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/utils/find-cid-in-shard.ts +149 -0
  479. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/utils/resolve-object-path.ts +62 -0
  480. package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/utils/validate-offset-and-length.ts +38 -0
@@ -0,0 +1,90 @@
1
+ import type { CID } from 'multiformats/cid'
2
+
3
+ /**
4
+ * Literally any `Iterable` (async or regular).
5
+ */
6
+ export type AwaitIterable<T> = Iterable<T> | AsyncIterable<T>
7
+
8
+ export type { CID }
9
+ /* Generic types for interfacing with block storage */
10
+
11
+ export interface Block {
12
+ cid: CID
13
+ bytes: Uint8Array
14
+ }
15
+
16
+ export interface BlockHeader {
17
+ cid: CID
18
+ length: number
19
+ blockLength: number
20
+ }
21
+
22
+ export interface BlockIndex extends BlockHeader {
23
+ offset: number
24
+ blockOffset: number
25
+ }
26
+
27
+ export interface RootsReader {
28
+ version: number
29
+ getRoots(): Promise<CID[]>
30
+ }
31
+
32
+ export interface RootsBufferReader {
33
+ version: number
34
+ getRoots(): CID[]
35
+ }
36
+
37
+ export interface BlockIterator extends AsyncIterable<Block> {}
38
+
39
+ export interface CIDIterator extends AsyncIterable<CID> {}
40
+
41
+ export interface BlockReader {
42
+ has(key: CID): Promise<boolean>
43
+ get(key: CID): Promise<Block | undefined>
44
+ blocks(): BlockIterator
45
+ cids(): CIDIterator
46
+ }
47
+
48
+ export interface BlockBufferReader {
49
+ has(key: CID): boolean
50
+ get(key: CID): Block | undefined
51
+ blocks(): Iterable<Block>
52
+ cids(): Iterable<CID>
53
+ }
54
+
55
+ export interface BlockWriter {
56
+ put(block: Block): Promise<void>
57
+ close(): Promise<void>
58
+ version(): number
59
+ }
60
+
61
+ export interface CarBufferWriter {
62
+ addRoot(root: CID, options?: { resize?: boolean }): CarBufferWriter
63
+ write(block: Block): CarBufferWriter
64
+ close(options?: { resize?: boolean }): Uint8Array
65
+ }
66
+
67
+ export interface CarBufferWriterOptions {
68
+ roots?: CID[] // defaults to []
69
+ byteOffset?: number // defaults to 0
70
+ byteLength?: number // defaults to buffer.byteLength
71
+
72
+ headerSize?: number // defaults to size needed for provided roots
73
+ }
74
+
75
+ export interface WriterChannel {
76
+ writer: BlockWriter
77
+ out: AsyncIterable<Uint8Array>
78
+ }
79
+
80
+ export interface CarReader extends BlockReader, RootsReader {}
81
+ export interface CarBufferReader extends BlockBufferReader, RootsBufferReader {}
82
+
83
+ /* Specific implementations for CAR block storage */
84
+
85
+ /*
86
+ export interface CarBlockIterator extends BlockIterator, RootsReader {}
87
+ export interface CarCIDIterator extends CIDIterator, RootsReader {}
88
+ export interface CarIndexer extends AsyncIterable<BlockIndex>, RootsReader {}
89
+ export interface CarWriter extends BlockWriter {}
90
+ */
@@ -0,0 +1,213 @@
1
+ import { decode as decodeDagCbor } from "@fireproof/vendor/@ipld/dag-cbor"
2
+ import { CID } from 'multiformats/cid'
3
+ import * as Digest from 'multiformats/hashes/digest'
4
+ import { CIDV0_BYTES, decodeV2Header, decodeVarint, getMultihashLength, V2_HEADER_LENGTH } from './decoder-common.js'
5
+ import { CarV1HeaderOrV2Pragma } from './header-validator.js'
6
+
7
+ /**
8
+ * @typedef {import('./api').Block} Block
9
+ * @typedef {import('./api').BlockHeader} BlockHeader
10
+ * @typedef {import('./api').BlockIndex} BlockIndex
11
+ * @typedef {import('./coding').BytesBufferReader} BytesBufferReader
12
+ * @typedef {import('./coding').CarHeader} CarHeader
13
+ * @typedef {import('./coding').CarV2Header} CarV2Header
14
+ * @typedef {import('./coding').CarV2FixedHeader} CarV2FixedHeader
15
+ */
16
+
17
+ /**
18
+ * Reads header data from a `BytesReader`. The header may either be in the form
19
+ * of a `CarHeader` or `CarV2Header` depending on the CAR being read.
20
+ *
21
+ * @name decoder.readHeader(reader)
22
+ * @param {BytesBufferReader} reader
23
+ * @param {number} [strictVersion]
24
+ * @returns {CarHeader | CarV2Header}
25
+ */
26
+ export function readHeader (reader, strictVersion) {
27
+ const length = decodeVarint(reader.upTo(8), reader)
28
+ if (length === 0) {
29
+ throw new Error('Invalid CAR header (zero length)')
30
+ }
31
+ const header = reader.exactly(length, true)
32
+ const block = decodeDagCbor(header)
33
+ if (CarV1HeaderOrV2Pragma.toTyped(block) === undefined) {
34
+ throw new Error('Invalid CAR header format')
35
+ }
36
+ if ((block.version !== 1 && block.version !== 2) || (strictVersion !== undefined && block.version !== strictVersion)) {
37
+ throw new Error(`Invalid CAR version: ${block.version}${strictVersion !== undefined ? ` (expected ${strictVersion})` : ''}`)
38
+ }
39
+ if (block.version === 1) {
40
+ // CarV1HeaderOrV2Pragma makes roots optional, let's make it mandatory
41
+ if (!Array.isArray(block.roots)) {
42
+ throw new Error('Invalid CAR header format')
43
+ }
44
+ return block
45
+ }
46
+ // version 2
47
+ if (block.roots !== undefined) {
48
+ throw new Error('Invalid CAR header format')
49
+ }
50
+ const v2Header = decodeV2Header(reader.exactly(V2_HEADER_LENGTH, true))
51
+ reader.seek(v2Header.dataOffset - reader.pos)
52
+ const v1Header = readHeader(reader, 1)
53
+ return Object.assign(v1Header, v2Header)
54
+ }
55
+
56
+ /**
57
+ * Reads CID sync
58
+ *
59
+ * @param {BytesBufferReader} reader
60
+ * @returns {CID}
61
+ */
62
+ function readCid (reader) {
63
+ const first = reader.exactly(2, false)
64
+ if (first[0] === CIDV0_BYTES.SHA2_256 && first[1] === CIDV0_BYTES.LENGTH) {
65
+ // cidv0 32-byte sha2-256
66
+ const bytes = reader.exactly(34, true)
67
+ const multihash = Digest.decode(bytes)
68
+ return CID.create(0, CIDV0_BYTES.DAG_PB, multihash)
69
+ }
70
+
71
+ const version = decodeVarint(reader.upTo(8), reader)
72
+ if (version !== 1) {
73
+ throw new Error(`Unexpected CID version (${version})`)
74
+ }
75
+ const codec = decodeVarint(reader.upTo(8), reader)
76
+ const bytes = reader.exactly(getMultihashLength(reader.upTo(8)), true)
77
+ const multihash = Digest.decode(bytes)
78
+ return CID.create(version, codec, multihash)
79
+ }
80
+
81
+ /**
82
+ * Reads the leading data of an individual block from CAR data from a
83
+ * `BytesBufferReader`. Returns a `BlockHeader` object which contains
84
+ * `{ cid, length, blockLength }` which can be used to either index the block
85
+ * or read the block binary data.
86
+ *
87
+ * @name async decoder.readBlockHead(reader)
88
+ * @param {BytesBufferReader} reader
89
+ * @returns {BlockHeader}
90
+ */
91
+ export function readBlockHead (reader) {
92
+ // length includes a CID + Binary, where CID has a variable length
93
+ // we have to deal with
94
+ const start = reader.pos
95
+ let length = decodeVarint(reader.upTo(8), reader)
96
+ if (length === 0) {
97
+ throw new Error('Invalid CAR section (zero length)')
98
+ }
99
+ length += (reader.pos - start)
100
+ const cid = readCid(reader)
101
+ const blockLength = length - Number(reader.pos - start) // subtract CID length
102
+
103
+ return { cid, length, blockLength }
104
+ }
105
+
106
+ /**
107
+ * Returns Car header and blocks from a Uint8Array
108
+ *
109
+ * @param {Uint8Array} bytes
110
+ * @returns {{ header : CarHeader | CarV2Header , blocks: Block[]}}
111
+ */
112
+ export function fromBytes (bytes) {
113
+ let reader = bytesReader(bytes)
114
+ const header = readHeader(reader)
115
+ if (header.version === 2) {
116
+ const v1length = reader.pos - header.dataOffset
117
+ reader = limitReader(reader, header.dataSize - v1length)
118
+ }
119
+
120
+ const blocks = []
121
+ while (reader.upTo(8).length > 0) {
122
+ const { cid, blockLength } = readBlockHead(reader)
123
+
124
+ blocks.push({ cid, bytes: reader.exactly(blockLength, true) })
125
+ }
126
+
127
+ return {
128
+ header, blocks
129
+ }
130
+ }
131
+
132
+ /**
133
+ * Creates a `BytesBufferReader` from a `Uint8Array`.
134
+ *
135
+ * @name decoder.bytesReader(bytes)
136
+ * @param {Uint8Array} bytes
137
+ * @returns {BytesBufferReader}
138
+ */
139
+ export function bytesReader (bytes) {
140
+ let pos = 0
141
+
142
+ /** @type {BytesBufferReader} */
143
+ return {
144
+ upTo (length) {
145
+ return bytes.subarray(pos, pos + Math.min(length, bytes.length - pos))
146
+ },
147
+
148
+ exactly (length, seek = false) {
149
+ if (length > bytes.length - pos) {
150
+ throw new Error('Unexpected end of data')
151
+ }
152
+
153
+ const out = bytes.subarray(pos, pos + length)
154
+ if (seek) {
155
+ pos += length
156
+ }
157
+ return out
158
+ },
159
+
160
+ seek (length) {
161
+ pos += length
162
+ },
163
+
164
+ get pos () {
165
+ return pos
166
+ }
167
+ }
168
+ }
169
+
170
+ /**
171
+ * Wraps a `BytesBufferReader` in a limiting `BytesBufferReader` which limits maximum read
172
+ * to `byteLimit` bytes. It _does not_ update `pos` of the original
173
+ * `BytesBufferReader`.
174
+ *
175
+ * @name decoder.limitReader(reader, byteLimit)
176
+ * @param {BytesBufferReader} reader
177
+ * @param {number} byteLimit
178
+ * @returns {BytesBufferReader}
179
+ */
180
+ export function limitReader (reader, byteLimit) {
181
+ let bytesRead = 0
182
+
183
+ /** @type {BytesBufferReader} */
184
+ return {
185
+ upTo (length) {
186
+ let bytes = reader.upTo(length)
187
+ if (bytes.length + bytesRead > byteLimit) {
188
+ bytes = bytes.subarray(0, byteLimit - bytesRead)
189
+ }
190
+ return bytes
191
+ },
192
+
193
+ exactly (length, seek = false) {
194
+ const bytes = reader.exactly(length, seek)
195
+ if (bytes.length + bytesRead > byteLimit) {
196
+ throw new Error('Unexpected end of data')
197
+ }
198
+ if (seek) {
199
+ bytesRead += length
200
+ }
201
+ return bytes
202
+ },
203
+
204
+ seek (length) {
205
+ bytesRead += length
206
+ reader.seek(length)
207
+ },
208
+
209
+ get pos () {
210
+ return reader.pos
211
+ }
212
+ }
213
+ }
@@ -0,0 +1,144 @@
1
+ import * as BufferDecoder from './buffer-decoder.js'
2
+
3
+ /**
4
+ * @typedef {import('multiformats').CID} CID
5
+ * @typedef {import('./api').Block} Block
6
+ * @typedef {import('./api').CarBufferReader} ICarBufferReader
7
+ * @typedef {import('./coding').CarHeader} CarHeader
8
+ * @typedef {import('./coding').CarV2Header} CarV2Header
9
+ */
10
+
11
+ /**
12
+ * Provides blockstore-like access to a CAR.
13
+ *
14
+ * Implements the `RootsBufferReader` interface:
15
+ * {@link ICarBufferReader.getRoots `getRoots()`}. And the `BlockBufferReader` interface:
16
+ * {@link ICarBufferReader.get `get()`}, {@link ICarBufferReader.has `has()`},
17
+ * {@link ICarBufferReader.blocks `blocks()`} and
18
+ * {@link ICarBufferReader.cids `cids()`}.
19
+ *
20
+ * Load this class with either `import { CarBufferReader } from '@ipld/car/buffer-reader'`
21
+ * (`const { CarBufferReader } = require('@ipld/car/buffer-reader')`). Or
22
+ * `import { CarBufferReader } from '@ipld/car'` (`const { CarBufferReader } = require('@ipld/car')`).
23
+ * The former will likely result in smaller bundle sizes where this is
24
+ * important.
25
+ *
26
+ * @name CarBufferReader
27
+ * @class
28
+ * @implements {ICarBufferReader}
29
+ * @property {number} version The version number of the CAR referenced by this
30
+ * reader (should be `1` or `2`).
31
+ */
32
+ export class CarBufferReader {
33
+ /**
34
+ * @constructs CarBufferReader
35
+ * @param {CarHeader|CarV2Header} header
36
+ * @param {Block[]} blocks
37
+ */
38
+ constructor (header, blocks) {
39
+ this._header = header
40
+ this._blocks = blocks
41
+ this._cids = undefined
42
+ }
43
+
44
+ /**
45
+ * @property version
46
+ * @memberof CarBufferReader
47
+ * @instance
48
+ */
49
+ get version () {
50
+ return this._header.version
51
+ }
52
+
53
+ /**
54
+ * Get the list of roots defined by the CAR referenced by this reader. May be
55
+ * zero or more `CID`s.
56
+ *
57
+ * @function
58
+ * @memberof CarBufferReader
59
+ * @instance
60
+ * @returns {CID[]}
61
+ */
62
+ getRoots () {
63
+ return this._header.roots
64
+ }
65
+
66
+ /**
67
+ * Check whether a given `CID` exists within the CAR referenced by this
68
+ * reader.
69
+ *
70
+ * @function
71
+ * @memberof CarBufferReader
72
+ * @instance
73
+ * @param {CID} key
74
+ * @returns {boolean}
75
+ */
76
+ has (key) {
77
+ return this._blocks.some(b => b.cid.equals(key))
78
+ }
79
+
80
+ /**
81
+ * Fetch a `Block` (a `{ cid:CID, bytes:Uint8Array }` pair) from the CAR
82
+ * referenced by this reader matching the provided `CID`. In the case where
83
+ * the provided `CID` doesn't exist within the CAR, `undefined` will be
84
+ * returned.
85
+ *
86
+ * @function
87
+ * @memberof CarBufferReader
88
+ * @instance
89
+ * @param {CID} key
90
+ * @returns {Block | undefined}
91
+ */
92
+ get (key) {
93
+ return this._blocks.find(b => b.cid.equals(key))
94
+ }
95
+
96
+ /**
97
+ * Returns a `Block[]` of the `Block`s (`{ cid:CID, bytes:Uint8Array }` pairs) contained within
98
+ * the CAR referenced by this reader.
99
+ *
100
+ * @function
101
+ * @memberof CarBufferReader
102
+ * @instance
103
+ * @returns {Block[]}
104
+ */
105
+ blocks () {
106
+ return this._blocks
107
+ }
108
+
109
+ /**
110
+ * Returns a `CID[]` of the `CID`s contained within the CAR referenced by this reader.
111
+ *
112
+ * @function
113
+ * @memberof CarBufferReader
114
+ * @instance
115
+ * @returns {CID[]}
116
+ */
117
+ cids () {
118
+ if (!this._cids) {
119
+ this._cids = this._blocks.map(b => b.cid)
120
+ }
121
+ return this._cids
122
+ }
123
+
124
+ /**
125
+ * Instantiate a {@link CarBufferReader} from a `Uint8Array` blob. This performs a
126
+ * decode fully in memory and maintains the decoded state in memory for full
127
+ * access to the data via the `CarReader` API.
128
+ *
129
+ * @static
130
+ * @memberof CarBufferReader
131
+ * @param {Uint8Array} bytes
132
+ * @returns {CarBufferReader}
133
+ */
134
+ static fromBytes (bytes) {
135
+ if (!(bytes instanceof Uint8Array)) {
136
+ throw new TypeError('fromBytes() requires a Uint8Array')
137
+ }
138
+
139
+ const { header, blocks } = BufferDecoder.fromBytes(bytes)
140
+ return new CarBufferReader(header, blocks)
141
+ }
142
+ }
143
+
144
+ export const __browser = true
@@ -0,0 +1,51 @@
1
+ import fs from 'fs'
2
+ import { CarBufferReader as BrowserCarBufferReader } from './buffer-reader-browser.js'
3
+
4
+ /**
5
+ * @typedef {import('./api').Block} Block
6
+ * @typedef {import('./api').BlockIndex} BlockIndex
7
+ * @typedef {import('./api').CarBufferReader} ICarBufferReader
8
+ */
9
+
10
+ const fsread = fs.readSync
11
+
12
+ /**
13
+ * @class
14
+ * @implements {ICarBufferReader}
15
+ */
16
+ export class CarBufferReader extends BrowserCarBufferReader {
17
+ /**
18
+ * Reads a block directly from a file descriptor for an open CAR file. This
19
+ * function is **only available in Node.js** and not a browser environment.
20
+ *
21
+ * This function can be used in connection with {@link CarIndexer} which emits
22
+ * the `BlockIndex` objects that are required by this function.
23
+ *
24
+ * The user is responsible for opening and closing the file used in this call.
25
+ *
26
+ * @static
27
+ * @memberof CarBufferReader
28
+ * @param {number} fd - A file descriptor from the
29
+ * Node.js `fs` module. An integer, from `fs.open()`.
30
+ * @param {BlockIndex} blockIndex - An index pointing to the location of the
31
+ * Block required. This `BlockIndex` should take the form:
32
+ * `{cid:CID, blockLength:number, blockOffset:number}`.
33
+ * @returns {Block} A `{ cid:CID, bytes:Uint8Array }` pair.
34
+ */
35
+ static readRaw (fd, blockIndex) {
36
+ const { cid, blockLength, blockOffset } = blockIndex
37
+ const bytes = new Uint8Array(blockLength)
38
+ let read
39
+ if (typeof fd === 'number') {
40
+ read = fsread(fd, bytes, 0, blockLength, blockOffset)
41
+ } else {
42
+ throw new TypeError('Bad fd')
43
+ }
44
+ if (read !== blockLength) {
45
+ throw new Error(`Failed to read entire block (${read} instead of ${blockLength})`)
46
+ }
47
+ return { cid, bytes }
48
+ }
49
+ }
50
+
51
+ export const __browser = false