@fireproof/vendor 1.2.0 → 2.0.0

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 (302) hide show
  1. package/package.json +19 -109
  2. package/src/@web3-storage/pail/dist/src/batch/index.d.ts +1 -53
  3. package/src/@web3-storage/pail/dist/src/batch/index.d.ts.map +1 -1
  4. package/src/@web3-storage/pail/dist/src/batch/shard.d.ts +1 -1
  5. package/src/@web3-storage/pail/dist/src/batch/shard.d.ts.map +1 -1
  6. package/src/@web3-storage/pail/dist/src/block.d.ts +2 -2
  7. package/src/@web3-storage/pail/dist/src/block.d.ts.map +1 -1
  8. package/src/@web3-storage/pail/dist/src/clock/index.d.ts +2 -2
  9. package/src/@web3-storage/pail/dist/src/clock/index.d.ts.map +1 -1
  10. package/src/@web3-storage/pail/dist/src/crdt/batch/index.d.ts.map +1 -1
  11. package/src/@web3-storage/pail/dist/src/crdt/index.d.ts +2 -2
  12. package/src/@web3-storage/pail/dist/src/crdt/index.d.ts.map +1 -1
  13. package/src/@web3-storage/pail/dist/src/diff.d.ts +3 -3
  14. package/src/@web3-storage/pail/dist/src/diff.d.ts.map +1 -1
  15. package/src/@web3-storage/pail/dist/src/index.d.ts +1 -1
  16. package/src/@web3-storage/pail/dist/src/index.d.ts.map +1 -1
  17. package/src/@web3-storage/pail/dist/src/merge.d.ts.map +1 -1
  18. package/src/@web3-storage/pail/dist/src/shard.d.ts +4 -4
  19. package/src/@web3-storage/pail/dist/src/shard.d.ts.map +1 -1
  20. package/src/@web3-storage/pail/dist/tsconfig.tsbuildinfo +1 -1
  21. package/src/@web3-storage/pail/src/api.ts +1 -1
  22. package/src/@web3-storage/pail/src/clock/index.js +1 -1
  23. package/src/@web3-storage/pail/src/shard.js +1 -1
  24. package/src/@ipld/car/LICENSE +0 -4
  25. package/src/@ipld/car/README.md +0 -1132
  26. package/src/@ipld/car/dist/index.min.js +0 -5
  27. package/src/@ipld/car/dist/src/api.d.ts +0 -72
  28. package/src/@ipld/car/dist/src/api.d.ts.map +0 -1
  29. package/src/@ipld/car/dist/src/buffer-decoder.d.ts +0 -67
  30. package/src/@ipld/car/dist/src/buffer-decoder.d.ts.map +0 -1
  31. package/src/@ipld/car/dist/src/buffer-reader-browser.d.ts +0 -116
  32. package/src/@ipld/car/dist/src/buffer-reader-browser.d.ts.map +0 -1
  33. package/src/@ipld/car/dist/src/buffer-reader.d.ts +0 -31
  34. package/src/@ipld/car/dist/src/buffer-reader.d.ts.map +0 -1
  35. package/src/@ipld/car/dist/src/buffer-writer.d.ts +0 -86
  36. package/src/@ipld/car/dist/src/buffer-writer.d.ts.map +0 -1
  37. package/src/@ipld/car/dist/src/coding.d.ts +0 -49
  38. package/src/@ipld/car/dist/src/coding.d.ts.map +0 -1
  39. package/src/@ipld/car/dist/src/decoder-common.d.ts +0 -43
  40. package/src/@ipld/car/dist/src/decoder-common.d.ts.map +0 -1
  41. package/src/@ipld/car/dist/src/decoder.d.ts +0 -87
  42. package/src/@ipld/car/dist/src/decoder.d.ts.map +0 -1
  43. package/src/@ipld/car/dist/src/encoder.d.ts +0 -17
  44. package/src/@ipld/car/dist/src/encoder.d.ts.map +0 -1
  45. package/src/@ipld/car/dist/src/header-validator.d.ts +0 -5
  46. package/src/@ipld/car/dist/src/header-validator.d.ts.map +0 -1
  47. package/src/@ipld/car/dist/src/index-browser.d.ts +0 -10
  48. package/src/@ipld/car/dist/src/index-browser.d.ts.map +0 -1
  49. package/src/@ipld/car/dist/src/index.d.ts +0 -11
  50. package/src/@ipld/car/dist/src/index.d.ts.map +0 -1
  51. package/src/@ipld/car/dist/src/indexed-reader-browser.d.ts +0 -5
  52. package/src/@ipld/car/dist/src/indexed-reader-browser.d.ts.map +0 -1
  53. package/src/@ipld/car/dist/src/indexed-reader.d.ts +0 -152
  54. package/src/@ipld/car/dist/src/indexed-reader.d.ts.map +0 -1
  55. package/src/@ipld/car/dist/src/indexer.d.ts +0 -95
  56. package/src/@ipld/car/dist/src/indexer.d.ts.map +0 -1
  57. package/src/@ipld/car/dist/src/iterator-channel.d.ts +0 -7
  58. package/src/@ipld/car/dist/src/iterator-channel.d.ts.map +0 -1
  59. package/src/@ipld/car/dist/src/iterator.d.ts +0 -174
  60. package/src/@ipld/car/dist/src/iterator.d.ts.map +0 -1
  61. package/src/@ipld/car/dist/src/promise-fs-opts.d.ts +0 -28
  62. package/src/@ipld/car/dist/src/promise-fs-opts.d.ts.map +0 -1
  63. package/src/@ipld/car/dist/src/reader-browser.d.ts +0 -151
  64. package/src/@ipld/car/dist/src/reader-browser.d.ts.map +0 -1
  65. package/src/@ipld/car/dist/src/reader.d.ts +0 -40
  66. package/src/@ipld/car/dist/src/reader.d.ts.map +0 -1
  67. package/src/@ipld/car/dist/src/writer-browser.d.ts +0 -155
  68. package/src/@ipld/car/dist/src/writer-browser.d.ts.map +0 -1
  69. package/src/@ipld/car/dist/src/writer.d.ts +0 -45
  70. package/src/@ipld/car/dist/src/writer.d.ts.map +0 -1
  71. package/src/@ipld/car/src/api.ts +0 -90
  72. package/src/@ipld/car/src/buffer-decoder.js +0 -213
  73. package/src/@ipld/car/src/buffer-reader-browser.js +0 -144
  74. package/src/@ipld/car/src/buffer-reader.js +0 -51
  75. package/src/@ipld/car/src/buffer-writer.js +0 -286
  76. package/src/@ipld/car/src/coding.ts +0 -68
  77. package/src/@ipld/car/src/decoder-common.js +0 -82
  78. package/src/@ipld/car/src/decoder.js +0 -347
  79. package/src/@ipld/car/src/encoder.js +0 -76
  80. package/src/@ipld/car/src/header-validator.js +0 -214
  81. package/src/@ipld/car/src/header.ipldsch +0 -18
  82. package/src/@ipld/car/src/index-browser.js +0 -18
  83. package/src/@ipld/car/src/index.js +0 -21
  84. package/src/@ipld/car/src/indexed-reader-browser.js +0 -7
  85. package/src/@ipld/car/src/indexed-reader.js +0 -211
  86. package/src/@ipld/car/src/indexer.js +0 -130
  87. package/src/@ipld/car/src/iterator-channel.js +0 -91
  88. package/src/@ipld/car/src/iterator.js +0 -267
  89. package/src/@ipld/car/src/promise-fs-opts.js +0 -46
  90. package/src/@ipld/car/src/reader-browser.js +0 -194
  91. package/src/@ipld/car/src/reader.js +0 -54
  92. package/src/@ipld/car/src/writer-browser.js +0 -250
  93. package/src/@ipld/car/src/writer.js +0 -81
  94. package/src/@ipld/dag-cbor/LICENSE +0 -4
  95. package/src/@ipld/dag-cbor/README.md +0 -80
  96. package/src/@ipld/dag-cbor/dist/index.min.js +0 -3
  97. package/src/@ipld/dag-cbor/dist/src/index.d.ts +0 -67
  98. package/src/@ipld/dag-cbor/dist/src/index.d.ts.map +0 -1
  99. package/src/@ipld/dag-cbor/src/index.js +0 -147
  100. package/src/@ipld/dag-json/LICENSE +0 -4
  101. package/src/@ipld/dag-json/README.md +0 -58
  102. package/src/@ipld/dag-json/dist/index.min.js +0 -3
  103. package/src/@ipld/dag-json/dist/src/index.d.ts +0 -12
  104. package/src/@ipld/dag-json/dist/src/index.d.ts.map +0 -1
  105. package/src/@ipld/dag-json/src/index.js +0 -291
  106. package/src/cborg/.github/dependabot.yml +0 -16
  107. package/src/cborg/.github/workflows/test-and-release.yml +0 -52
  108. package/src/cborg/CHANGELOG.md +0 -513
  109. package/src/cborg/LICENSE +0 -13
  110. package/src/cborg/README.md +0 -515
  111. package/src/cborg/bench/bench.js +0 -117
  112. package/src/cborg/bench/json.js +0 -124
  113. package/src/cborg/bench/package.json +0 -8
  114. package/src/cborg/cborg/bin.js +0 -189
  115. package/src/cborg/cborg/common.js +0 -28
  116. package/src/cborg/cborg/decode.js +0 -211
  117. package/src/cborg/cborg/diagnostic.js +0 -158
  118. package/src/cborg/cborg/diagnostic_test.js +0 -117
  119. package/src/cborg/cborg/encode.js +0 -466
  120. package/src/cborg/cborg/index.js +0 -33
  121. package/src/cborg/cborg/is.js +0 -106
  122. package/src/cborg/cborg/length.js +0 -62
  123. package/src/cborg/example-bytestrings.js +0 -180
  124. package/src/cborg/example-json.js +0 -6
  125. package/src/cborg/example.js +0 -5
  126. package/src/cborg/interface.ts +0 -59
  127. package/src/cborg/json/decode.js +0 -462
  128. package/src/cborg/json/encode.js +0 -302
  129. package/src/cborg/json/json.js +0 -4
  130. package/src/cborg/taglib.js +0 -75
  131. package/src/cborg/test/appendix_a.js +0 -647
  132. package/src/cborg/test/common.js +0 -18
  133. package/src/cborg/test/node-test-bin.js +0 -402
  134. package/src/cborg/test/noop-bin-test.js +0 -3
  135. package/src/cborg/test/test-0uint.js +0 -103
  136. package/src/cborg/test/test-1negint.js +0 -96
  137. package/src/cborg/test/test-2bytes.js +0 -198
  138. package/src/cborg/test/test-3string.js +0 -136
  139. package/src/cborg/test/test-4array.js +0 -93
  140. package/src/cborg/test/test-5map.js +0 -284
  141. package/src/cborg/test/test-6tag.js +0 -84
  142. package/src/cborg/test/test-7float.js +0 -131
  143. package/src/cborg/test/test-bl.js +0 -37
  144. package/src/cborg/test/test-cbor-vectors.js +0 -107
  145. package/src/cborg/test/test-decode-errors.js +0 -65
  146. package/src/cborg/test/test-fuzz.js +0 -42
  147. package/src/cborg/test/test-json.js +0 -219
  148. package/src/cborg/test/test-length.js +0 -65
  149. package/src/cborg/test/test-partial.js +0 -111
  150. package/src/cborg/tsconfig.json +0 -48
  151. package/src/cborg/types/cborg/decode.d.ts +0 -43
  152. package/src/cborg/types/cborg/decode.d.ts.map +0 -1
  153. package/src/cborg/types/cborg/encode.d.ts +0 -51
  154. package/src/cborg/types/cborg/encode.d.ts.map +0 -1
  155. package/src/cborg/types/cborg/index.d.ts +0 -26
  156. package/src/cborg/types/cborg/index.d.ts.map +0 -1
  157. package/src/cborg/types/cborg/is.d.ts +0 -6
  158. package/src/cborg/types/cborg/is.d.ts.map +0 -1
  159. package/src/cborg/types/example.d.ts +0 -2
  160. package/src/cborg/types/example.d.ts.map +0 -1
  161. package/src/cborg/types/interface.d.ts +0 -49
  162. package/src/cborg/types/interface.d.ts.map +0 -1
  163. package/src/cborg/types/json/decode.d.ts +0 -67
  164. package/src/cborg/types/json/decode.d.ts.map +0 -1
  165. package/src/cborg/types/json/encode.d.ts +0 -11
  166. package/src/cborg/types/json/encode.d.ts.map +0 -1
  167. package/src/cborg/types/json/json.d.ts +0 -6
  168. package/src/cborg/types/json/json.d.ts.map +0 -1
  169. package/src/cborg/types/taglib.d.ts +0 -18
  170. package/src/cborg/types/taglib.d.ts.map +0 -1
  171. package/src/cborg/types/tsconfig.tsbuildinfo +0 -1
  172. package/src/cborg/types/utils/0uint.d.ts +0 -102
  173. package/src/cborg/types/utils/0uint.d.ts.map +0 -1
  174. package/src/cborg/types/utils/1negint.d.ts +0 -59
  175. package/src/cborg/types/utils/1negint.d.ts.map +0 -1
  176. package/src/cborg/types/utils/2bytes.d.ts +0 -69
  177. package/src/cborg/types/utils/2bytes.d.ts.map +0 -1
  178. package/src/cborg/types/utils/3string.d.ts +0 -46
  179. package/src/cborg/types/utils/3string.d.ts.map +0 -1
  180. package/src/cborg/types/utils/4array.d.ts +0 -66
  181. package/src/cborg/types/utils/4array.d.ts.map +0 -1
  182. package/src/cborg/types/utils/5map.d.ts +0 -66
  183. package/src/cborg/types/utils/5map.d.ts.map +0 -1
  184. package/src/cborg/types/utils/6tag.d.ts +0 -62
  185. package/src/cborg/types/utils/6tag.d.ts.map +0 -1
  186. package/src/cborg/types/utils/7float.d.ts +0 -60
  187. package/src/cborg/types/utils/7float.d.ts.map +0 -1
  188. package/src/cborg/types/utils/bl.d.ts +0 -26
  189. package/src/cborg/types/utils/bl.d.ts.map +0 -1
  190. package/src/cborg/types/utils/byte-utils.d.ts +0 -53
  191. package/src/cborg/types/utils/byte-utils.d.ts.map +0 -1
  192. package/src/cborg/types/utils/common.d.ts +0 -8
  193. package/src/cborg/types/utils/common.d.ts.map +0 -1
  194. package/src/cborg/types/utils/index.d.ts +0 -13
  195. package/src/cborg/types/utils/index.d.ts.map +0 -1
  196. package/src/cborg/types/utils/jump.d.ts +0 -16
  197. package/src/cborg/types/utils/jump.d.ts.map +0 -1
  198. package/src/cborg/types/utils/token.d.ts +0 -59
  199. package/src/cborg/types/utils/token.d.ts.map +0 -1
  200. package/src/cborg/utils/0uint.js +0 -229
  201. package/src/cborg/utils/1negint.js +0 -111
  202. package/src/cborg/utils/2bytes.js +0 -135
  203. package/src/cborg/utils/3string.js +0 -90
  204. package/src/cborg/utils/4array.js +0 -114
  205. package/src/cborg/utils/5map.js +0 -113
  206. package/src/cborg/utils/6tag.js +0 -81
  207. package/src/cborg/utils/7float.js +0 -310
  208. package/src/cborg/utils/bl.js +0 -124
  209. package/src/cborg/utils/byte-utils.js +0 -417
  210. package/src/cborg/utils/common.js +0 -11
  211. package/src/cborg/utils/index.js +0 -12
  212. package/src/cborg/utils/jump.js +0 -222
  213. package/src/cborg/utils/token.js +0 -76
  214. package/src/ipfs-unixfs-exporter/LICENSE +0 -4
  215. package/src/ipfs-unixfs-exporter/README.md +0 -105
  216. package/src/ipfs-unixfs-exporter/dist/index.min.js +0 -3
  217. package/src/ipfs-unixfs-exporter/dist/src/errors.d.ts +0 -57
  218. package/src/ipfs-unixfs-exporter/dist/src/errors.d.ts.map +0 -1
  219. package/src/ipfs-unixfs-exporter/dist/src/errors.js +0 -73
  220. package/src/ipfs-unixfs-exporter/dist/src/errors.js.map +0 -1
  221. package/src/ipfs-unixfs-exporter/dist/src/index.d.ts +0 -355
  222. package/src/ipfs-unixfs-exporter/dist/src/index.d.ts.map +0 -1
  223. package/src/ipfs-unixfs-exporter/dist/src/index.js +0 -197
  224. package/src/ipfs-unixfs-exporter/dist/src/index.js.map +0 -1
  225. package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-cbor.d.ts +0 -4
  226. package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-cbor.d.ts.map +0 -1
  227. package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-cbor.js +0 -9
  228. package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-cbor.js.map +0 -1
  229. package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-json.d.ts +0 -4
  230. package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-json.d.ts.map +0 -1
  231. package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-json.js +0 -9
  232. package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-json.js.map +0 -1
  233. package/src/ipfs-unixfs-exporter/dist/src/resolvers/identity.d.ts +0 -4
  234. package/src/ipfs-unixfs-exporter/dist/src/resolvers/identity.d.ts.map +0 -1
  235. package/src/ipfs-unixfs-exporter/dist/src/resolvers/identity.js +0 -38
  236. package/src/ipfs-unixfs-exporter/dist/src/resolvers/identity.js.map +0 -1
  237. package/src/ipfs-unixfs-exporter/dist/src/resolvers/index.d.ts +0 -4
  238. package/src/ipfs-unixfs-exporter/dist/src/resolvers/index.d.ts.map +0 -1
  239. package/src/ipfs-unixfs-exporter/dist/src/resolvers/index.js +0 -30
  240. package/src/ipfs-unixfs-exporter/dist/src/resolvers/index.js.map +0 -1
  241. package/src/ipfs-unixfs-exporter/dist/src/resolvers/json.d.ts +0 -4
  242. package/src/ipfs-unixfs-exporter/dist/src/resolvers/json.d.ts.map +0 -1
  243. package/src/ipfs-unixfs-exporter/dist/src/resolvers/json.js +0 -9
  244. package/src/ipfs-unixfs-exporter/dist/src/resolvers/json.js.map +0 -1
  245. package/src/ipfs-unixfs-exporter/dist/src/resolvers/raw.d.ts +0 -4
  246. package/src/ipfs-unixfs-exporter/dist/src/resolvers/raw.d.ts.map +0 -1
  247. package/src/ipfs-unixfs-exporter/dist/src/resolvers/raw.js +0 -37
  248. package/src/ipfs-unixfs-exporter/dist/src/resolvers/raw.js.map +0 -1
  249. package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/directory.d.ts +0 -4
  250. package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/directory.d.ts.map +0 -1
  251. package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/directory.js +0 -29
  252. package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/directory.js.map +0 -1
  253. package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/file.d.ts +0 -4
  254. package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/file.d.ts.map +0 -1
  255. package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/file.js +0 -153
  256. package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/file.js.map +0 -1
  257. package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/hamt-sharded-directory.d.ts +0 -4
  258. package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/hamt-sharded-directory.d.ts.map +0 -1
  259. package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/hamt-sharded-directory.js +0 -59
  260. package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/hamt-sharded-directory.js.map +0 -1
  261. package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/raw.d.ts +0 -4
  262. package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/raw.d.ts.map +0 -1
  263. package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/raw.js +0 -25
  264. package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/raw.js.map +0 -1
  265. package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/index.d.ts +0 -4
  266. package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/index.d.ts.map +0 -1
  267. package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/index.js +0 -104
  268. package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/index.js.map +0 -1
  269. package/src/ipfs-unixfs-exporter/dist/src/utils/extract-data-from-block.d.ts +0 -3
  270. package/src/ipfs-unixfs-exporter/dist/src/utils/extract-data-from-block.d.ts.map +0 -1
  271. package/src/ipfs-unixfs-exporter/dist/src/utils/extract-data-from-block.js +0 -20
  272. package/src/ipfs-unixfs-exporter/dist/src/utils/extract-data-from-block.js.map +0 -1
  273. package/src/ipfs-unixfs-exporter/dist/src/utils/find-cid-in-shard.d.ts +0 -6
  274. package/src/ipfs-unixfs-exporter/dist/src/utils/find-cid-in-shard.d.ts.map +0 -1
  275. package/src/ipfs-unixfs-exporter/dist/src/utils/find-cid-in-shard.js +0 -116
  276. package/src/ipfs-unixfs-exporter/dist/src/utils/find-cid-in-shard.js.map +0 -1
  277. package/src/ipfs-unixfs-exporter/dist/src/utils/resolve-object-path.d.ts +0 -4
  278. package/src/ipfs-unixfs-exporter/dist/src/utils/resolve-object-path.d.ts.map +0 -1
  279. package/src/ipfs-unixfs-exporter/dist/src/utils/resolve-object-path.js +0 -57
  280. package/src/ipfs-unixfs-exporter/dist/src/utils/resolve-object-path.js.map +0 -1
  281. package/src/ipfs-unixfs-exporter/dist/src/utils/validate-offset-and-length.d.ts +0 -6
  282. package/src/ipfs-unixfs-exporter/dist/src/utils/validate-offset-and-length.d.ts.map +0 -1
  283. package/src/ipfs-unixfs-exporter/dist/src/utils/validate-offset-and-length.js +0 -30
  284. package/src/ipfs-unixfs-exporter/dist/src/utils/validate-offset-and-length.js.map +0 -1
  285. package/src/ipfs-unixfs-exporter/dist/typedoc-urls.json +0 -58
  286. package/src/ipfs-unixfs-exporter/src/errors.ts +0 -87
  287. package/src/ipfs-unixfs-exporter/src/index.ts +0 -498
  288. package/src/ipfs-unixfs-exporter/src/resolvers/dag-cbor.ts +0 -12
  289. package/src/ipfs-unixfs-exporter/src/resolvers/dag-json.ts +0 -12
  290. package/src/ipfs-unixfs-exporter/src/resolvers/identity.ts +0 -49
  291. package/src/ipfs-unixfs-exporter/src/resolvers/index.ts +0 -35
  292. package/src/ipfs-unixfs-exporter/src/resolvers/json.ts +0 -12
  293. package/src/ipfs-unixfs-exporter/src/resolvers/raw.ts +0 -49
  294. package/src/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/directory.ts +0 -39
  295. package/src/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/file.ts +0 -198
  296. package/src/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/hamt-sharded-directory.ts +0 -76
  297. package/src/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/raw.ts +0 -37
  298. package/src/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/index.ts +0 -121
  299. package/src/ipfs-unixfs-exporter/src/utils/extract-data-from-block.ts +0 -24
  300. package/src/ipfs-unixfs-exporter/src/utils/find-cid-in-shard.ts +0 -149
  301. package/src/ipfs-unixfs-exporter/src/utils/resolve-object-path.ts +0 -62
  302. package/src/ipfs-unixfs-exporter/src/utils/validate-offset-and-length.ts +0 -38
@@ -1,213 +0,0 @@
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
- }
@@ -1,144 +0,0 @@
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
@@ -1,51 +0,0 @@
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
@@ -1,286 +0,0 @@
1
- import * as CBOR from "@fireproof/vendor/@ipld/dag-cbor"
2
- import { Token, Type } from "@fireproof/vendor/cborg"
3
- import { tokensToLength } from "@fireproof/vendor/cborg/length"
4
- import varint from 'varint'
5
-
6
- /**
7
- * @typedef {import('./api').CID} CID
8
- * @typedef {import('./api').Block} Block
9
- * @typedef {import('./api').CarBufferWriter} Writer
10
- * @typedef {import('./api').CarBufferWriterOptions} Options
11
- * @typedef {import('./coding').CarEncoder} CarEncoder
12
- */
13
-
14
- /**
15
- * A simple CAR writer that writes to a pre-allocated buffer.
16
- *
17
- * @class
18
- * @name CarBufferWriter
19
- * @implements {Writer}
20
- */
21
- class CarBufferWriter {
22
- /**
23
- * @param {Uint8Array} bytes
24
- * @param {number} headerSize
25
- */
26
- constructor (bytes, headerSize) {
27
- /** @readonly */
28
- this.bytes = bytes
29
- this.byteOffset = headerSize
30
-
31
- /**
32
- * @readonly
33
- * @type {CID[]}
34
- */
35
- this.roots = []
36
- this.headerSize = headerSize
37
- }
38
-
39
- /**
40
- * Add a root to this writer, to be used to create a header when the CAR is
41
- * finalized with {@link CarBufferWriter.close `close()`}
42
- *
43
- * @param {CID} root
44
- * @param {{resize?:boolean}} [options]
45
- * @returns {CarBufferWriter}
46
- */
47
- addRoot (root, options) {
48
- addRoot(this, root, options)
49
- return this
50
- }
51
-
52
- /**
53
- * Write a `Block` (a `{ cid:CID, bytes:Uint8Array }` pair) to the archive.
54
- * Throws if there is not enough capacity.
55
- *
56
- * @param {Block} block - A `{ cid:CID, bytes:Uint8Array }` pair.
57
- * @returns {CarBufferWriter}
58
- */
59
- write (block) {
60
- addBlock(this, block)
61
- return this
62
- }
63
-
64
- /**
65
- * Finalize the CAR and return it as a `Uint8Array`.
66
- *
67
- * @param {object} [options]
68
- * @param {boolean} [options.resize]
69
- * @returns {Uint8Array}
70
- */
71
- close (options) {
72
- return close(this, options)
73
- }
74
- }
75
-
76
- /**
77
- * @param {CarBufferWriter} writer
78
- * @param {CID} root
79
- * @param {{resize?:boolean}} [options]
80
- */
81
- export const addRoot = (writer, root, options = {}) => {
82
- const { resize = false } = options
83
- const { bytes, headerSize, byteOffset, roots } = writer
84
- writer.roots.push(root)
85
- const size = headerLength(writer)
86
- // If there is not enough space for the new root
87
- if (size > headerSize) {
88
- // Check if we root would fit if we were to resize the head.
89
- if (size - headerSize + byteOffset < bytes.byteLength) {
90
- // If resize is enabled resize head
91
- if (resize) {
92
- resizeHeader(writer, size)
93
- // otherwise remove head and throw an error suggesting to resize
94
- } else {
95
- roots.pop()
96
- throw new RangeError(`Header of size ${headerSize} has no capacity for new root ${root}.
97
- However there is a space in the buffer and you could call addRoot(root, { resize: root }) to resize header to make a space for this root.`)
98
- }
99
- // If head would not fit even with resize pop new root and throw error
100
- } else {
101
- roots.pop()
102
- throw new RangeError(`Buffer has no capacity for a new root ${root}`)
103
- }
104
- }
105
- }
106
-
107
- /**
108
- * Calculates number of bytes required for storing given block in CAR. Useful in
109
- * estimating size of an `ArrayBuffer` for the `CarBufferWriter`.
110
- *
111
- * @name CarBufferWriter.blockLength(Block)
112
- * @param {Block} block
113
- * @returns {number}
114
- */
115
- export const blockLength = ({ cid, bytes }) => {
116
- const size = cid.bytes.byteLength + bytes.byteLength
117
- return varint.encodingLength(size) + size
118
- }
119
-
120
- /**
121
- * @param {CarBufferWriter} writer
122
- * @param {Block} block
123
- */
124
- export const addBlock = (writer, { cid, bytes }) => {
125
- const byteLength = cid.bytes.byteLength + bytes.byteLength
126
- const size = varint.encode(byteLength)
127
- if (writer.byteOffset + size.length + byteLength > writer.bytes.byteLength) {
128
- throw new RangeError('Buffer has no capacity for this block')
129
- } else {
130
- writeBytes(writer, size)
131
- writeBytes(writer, cid.bytes)
132
- writeBytes(writer, bytes)
133
- }
134
- }
135
-
136
- /**
137
- * @param {CarBufferWriter} writer
138
- * @param {object} [options]
139
- * @param {boolean} [options.resize]
140
- */
141
- export const close = (writer, options = {}) => {
142
- const { resize = false } = options
143
- const { roots, bytes, byteOffset, headerSize } = writer
144
-
145
- const headerBytes = CBOR.encode({ version: 1, roots })
146
- const varintBytes = varint.encode(headerBytes.length)
147
-
148
- const size = varintBytes.length + headerBytes.byteLength
149
- const offset = headerSize - size
150
-
151
- // If header size estimate was accurate we just write header and return
152
- // view into buffer.
153
- if (offset === 0) {
154
- writeHeader(writer, varintBytes, headerBytes)
155
- return bytes.subarray(0, byteOffset)
156
- // If header was overestimated and `{resize: true}` is passed resize header
157
- } else if (resize) {
158
- resizeHeader(writer, size)
159
- writeHeader(writer, varintBytes, headerBytes)
160
- return bytes.subarray(0, writer.byteOffset)
161
- } else {
162
- throw new RangeError(`Header size was overestimated.
163
- You can use close({ resize: true }) to resize header`)
164
- }
165
- }
166
-
167
- /**
168
- * @param {CarBufferWriter} writer
169
- * @param {number} byteLength
170
- */
171
- export const resizeHeader = (writer, byteLength) => {
172
- const { bytes, headerSize } = writer
173
- // Move data section to a new offset
174
- bytes.set(bytes.subarray(headerSize, writer.byteOffset), byteLength)
175
- // Update header size & byteOffset
176
- writer.byteOffset += byteLength - headerSize
177
- writer.headerSize = byteLength
178
- }
179
-
180
- /**
181
- * @param {CarBufferWriter} writer
182
- * @param {number[]|Uint8Array} bytes
183
- */
184
-
185
- const writeBytes = (writer, bytes) => {
186
- writer.bytes.set(bytes, writer.byteOffset)
187
- writer.byteOffset += bytes.length
188
- }
189
- /**
190
- * @param {{bytes:Uint8Array}} writer
191
- * @param {number[]} varint
192
- * @param {Uint8Array} header
193
- */
194
- const writeHeader = ({ bytes }, varint, header) => {
195
- bytes.set(varint)
196
- bytes.set(header, varint.length)
197
- }
198
-
199
- const headerPreludeTokens = [
200
- new Token(Type.map, 2),
201
- new Token(Type.string, 'version'),
202
- new Token(Type.uint, 1),
203
- new Token(Type.string, 'roots')
204
- ]
205
-
206
- const CID_TAG = new Token(Type.tag, 42)
207
-
208
- /**
209
- * Calculates header size given the array of byteLength for roots.
210
- *
211
- * @name CarBufferWriter.calculateHeaderLength(rootLengths)
212
- * @param {number[]} rootLengths
213
- * @returns {number}
214
- */
215
- export const calculateHeaderLength = (rootLengths) => {
216
- const tokens = [...headerPreludeTokens]
217
- tokens.push(new Token(Type.array, rootLengths.length))
218
- for (const rootLength of rootLengths) {
219
- tokens.push(CID_TAG)
220
- tokens.push(new Token(Type.bytes, { length: rootLength + 1 }))
221
- }
222
- const length = tokensToLength(tokens) // no options needed here because we have simple tokens
223
- return varint.encodingLength(length) + length
224
- }
225
-
226
- /**
227
- * Calculates header size given the array of roots.
228
- *
229
- * @name CarBufferWriter.headerLength({ roots })
230
- * @param {object} options
231
- * @param {CID[]} options.roots
232
- * @returns {number}
233
- */
234
- export const headerLength = ({ roots }) =>
235
- calculateHeaderLength(roots.map(cid => cid.bytes.byteLength))
236
-
237
- /**
238
- * Estimates header size given a count of the roots and the expected byte length
239
- * of the root CIDs. The default length works for a standard CIDv1 with a
240
- * single-byte multihash code, such as SHA2-256 (i.e. the most common CIDv1).
241
- *
242
- * @name CarBufferWriter.estimateHeaderLength(rootCount[, rootByteLength])
243
- * @param {number} rootCount
244
- * @param {number} [rootByteLength]
245
- * @returns {number}
246
- */
247
- export const estimateHeaderLength = (rootCount, rootByteLength = 36) =>
248
- calculateHeaderLength(new Array(rootCount).fill(rootByteLength))
249
-
250
- /**
251
- * Creates synchronous CAR writer that can be used to encode blocks into a given
252
- * buffer. Optionally you could pass `byteOffset` and `byteLength` to specify a
253
- * range inside buffer to write into. If car file is going to have `roots` you
254
- * need to either pass them under `options.roots` (from which header size will
255
- * be calculated) or provide `options.headerSize` to allocate required space
256
- * in the buffer. You may also provide known `roots` and `headerSize` to
257
- * allocate space for the roots that may not be known ahead of time.
258
- *
259
- * Note: Incorrect `headerSize` may lead to copying bytes inside a buffer
260
- * which will have a negative impact on performance.
261
- *
262
- * @name CarBufferWriter.createWriter(buffer[, options])
263
- * @param {ArrayBuffer} buffer
264
- * @param {object} [options]
265
- * @param {CID[]} [options.roots]
266
- * @param {number} [options.byteOffset]
267
- * @param {number} [options.byteLength]
268
- * @param {number} [options.headerSize]
269
- * @returns {CarBufferWriter}
270
- */
271
- export const createWriter = (buffer, options = {}) => {
272
- const {
273
- roots = [],
274
- byteOffset = 0,
275
- byteLength = buffer.byteLength,
276
- headerSize = headerLength({ roots })
277
- } = options
278
- const bytes = new Uint8Array(buffer, byteOffset, byteLength)
279
-
280
- const writer = new CarBufferWriter(bytes, headerSize)
281
- for (const root of roots) {
282
- writer.addRoot(root)
283
- }
284
-
285
- return writer
286
- }