@helia/unixfs 0.0.0 → 1.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 (110) hide show
  1. package/README.md +10 -4
  2. package/dist/index.min.js +1 -1
  3. package/dist/src/commands/cat.d.ts +1 -1
  4. package/dist/src/commands/cat.d.ts.map +1 -1
  5. package/dist/src/commands/cat.js +1 -1
  6. package/dist/src/commands/cat.js.map +1 -1
  7. package/dist/src/commands/chmod.d.ts.map +1 -1
  8. package/dist/src/commands/chmod.js +12 -7
  9. package/dist/src/commands/chmod.js.map +1 -1
  10. package/dist/src/commands/cp.d.ts +1 -1
  11. package/dist/src/commands/cp.d.ts.map +1 -1
  12. package/dist/src/commands/cp.js +5 -2
  13. package/dist/src/commands/cp.js.map +1 -1
  14. package/dist/src/commands/ls.d.ts +2 -1
  15. package/dist/src/commands/ls.d.ts.map +1 -1
  16. package/dist/src/commands/ls.js +1 -1
  17. package/dist/src/commands/ls.js.map +1 -1
  18. package/dist/src/commands/mkdir.d.ts.map +1 -1
  19. package/dist/src/commands/mkdir.js +4 -2
  20. package/dist/src/commands/mkdir.js.map +1 -1
  21. package/dist/src/commands/rm.d.ts +1 -1
  22. package/dist/src/commands/rm.d.ts.map +1 -1
  23. package/dist/src/commands/rm.js +9 -3
  24. package/dist/src/commands/rm.js.map +1 -1
  25. package/dist/src/commands/stat.d.ts +1 -1
  26. package/dist/src/commands/stat.d.ts.map +1 -1
  27. package/dist/src/commands/stat.js +19 -15
  28. package/dist/src/commands/stat.js.map +1 -1
  29. package/dist/src/commands/touch.d.ts.map +1 -1
  30. package/dist/src/commands/touch.js +13 -8
  31. package/dist/src/commands/touch.js.map +1 -1
  32. package/dist/src/commands/utils/add-link.d.ts +4 -2
  33. package/dist/src/commands/utils/add-link.d.ts.map +1 -1
  34. package/dist/src/commands/utils/add-link.js +24 -24
  35. package/dist/src/commands/utils/add-link.js.map +1 -1
  36. package/dist/src/commands/utils/cid-to-directory.d.ts +3 -3
  37. package/dist/src/commands/utils/cid-to-directory.d.ts.map +1 -1
  38. package/dist/src/commands/utils/cid-to-directory.js +1 -1
  39. package/dist/src/commands/utils/cid-to-directory.js.map +1 -1
  40. package/dist/src/commands/utils/cid-to-pblink.d.ts +3 -3
  41. package/dist/src/commands/utils/cid-to-pblink.d.ts.map +1 -1
  42. package/dist/src/commands/utils/cid-to-pblink.js.map +1 -1
  43. package/dist/src/commands/utils/constants.d.ts +2 -0
  44. package/dist/src/commands/utils/constants.d.ts.map +1 -0
  45. package/dist/src/commands/utils/constants.js +2 -0
  46. package/dist/src/commands/utils/constants.js.map +1 -0
  47. package/dist/src/commands/utils/dir-sharded.d.ts +47 -41
  48. package/dist/src/commands/utils/dir-sharded.d.ts.map +1 -1
  49. package/dist/src/commands/utils/dir-sharded.js +99 -15
  50. package/dist/src/commands/utils/dir-sharded.js.map +1 -1
  51. package/dist/src/commands/utils/errors.d.ts +22 -6
  52. package/dist/src/commands/utils/errors.d.ts.map +1 -1
  53. package/dist/src/commands/utils/errors.js +34 -8
  54. package/dist/src/commands/utils/errors.js.map +1 -1
  55. package/dist/src/commands/utils/hamt-constants.d.ts +1 -1
  56. package/dist/src/commands/utils/hamt-constants.d.ts.map +1 -1
  57. package/dist/src/commands/utils/hamt-constants.js +1 -1
  58. package/dist/src/commands/utils/hamt-constants.js.map +1 -1
  59. package/dist/src/commands/utils/hamt-utils.d.ts +15 -12
  60. package/dist/src/commands/utils/hamt-utils.d.ts.map +1 -1
  61. package/dist/src/commands/utils/hamt-utils.js +40 -39
  62. package/dist/src/commands/utils/hamt-utils.js.map +1 -1
  63. package/dist/src/commands/utils/is-over-shard-threshold.d.ts +10 -0
  64. package/dist/src/commands/utils/is-over-shard-threshold.d.ts.map +1 -0
  65. package/dist/src/commands/utils/is-over-shard-threshold.js +62 -0
  66. package/dist/src/commands/utils/is-over-shard-threshold.js.map +1 -0
  67. package/dist/src/commands/utils/persist.d.ts +7 -6
  68. package/dist/src/commands/utils/persist.d.ts.map +1 -1
  69. package/dist/src/commands/utils/persist.js +6 -3
  70. package/dist/src/commands/utils/persist.js.map +1 -1
  71. package/dist/src/commands/utils/remove-link.d.ts +6 -2
  72. package/dist/src/commands/utils/remove-link.d.ts.map +1 -1
  73. package/dist/src/commands/utils/remove-link.js +143 -55
  74. package/dist/src/commands/utils/remove-link.js.map +1 -1
  75. package/dist/src/commands/utils/resolve.d.ts +6 -3
  76. package/dist/src/commands/utils/resolve.d.ts.map +1 -1
  77. package/dist/src/commands/utils/resolve.js +4 -4
  78. package/dist/src/commands/utils/resolve.js.map +1 -1
  79. package/dist/src/index.d.ts +14 -7
  80. package/dist/src/index.d.ts.map +1 -1
  81. package/dist/src/index.js +0 -7
  82. package/dist/src/index.js.map +1 -1
  83. package/dist/typedoc-urls.json +14 -0
  84. package/package.json +8 -7
  85. package/src/commands/cat.ts +3 -2
  86. package/src/commands/chmod.ts +12 -7
  87. package/src/commands/cp.ts +7 -4
  88. package/src/commands/ls.ts +4 -3
  89. package/src/commands/mkdir.ts +5 -3
  90. package/src/commands/rm.ts +9 -5
  91. package/src/commands/stat.ts +22 -17
  92. package/src/commands/touch.ts +14 -9
  93. package/src/commands/utils/add-link.ts +32 -31
  94. package/src/commands/utils/cid-to-directory.ts +4 -4
  95. package/src/commands/utils/cid-to-pblink.ts +3 -3
  96. package/src/commands/utils/constants.ts +2 -0
  97. package/src/commands/utils/dir-sharded.ts +162 -63
  98. package/src/commands/utils/errors.ts +42 -8
  99. package/src/commands/utils/hamt-constants.ts +1 -1
  100. package/src/commands/utils/hamt-utils.ts +59 -50
  101. package/src/commands/utils/is-over-shard-threshold.ts +78 -0
  102. package/src/commands/utils/persist.ts +13 -8
  103. package/src/commands/utils/remove-link.ts +178 -77
  104. package/src/commands/utils/resolve.ts +12 -7
  105. package/src/index.ts +15 -17
  106. package/dist/src/commands/add.d.ts +0 -6
  107. package/dist/src/commands/add.d.ts.map +0 -1
  108. package/dist/src/commands/add.js +0 -38
  109. package/dist/src/commands/add.js.map +0 -1
  110. package/src/commands/add.ts +0 -46
@@ -1,46 +0,0 @@
1
- import type { Blockstore } from 'interface-blockstore'
2
- import { ImportCandidate, importer, ImportResult, UserImporterOptions } from 'ipfs-unixfs-importer'
3
- import last from 'it-last'
4
- import type { CID } from 'multiformats/cid'
5
- import { UnknownError } from './utils/errors.js'
6
-
7
- function isIterable (obj: any): obj is Iterator<Uint8Array> {
8
- return obj[Symbol.iterator] != null
9
- }
10
-
11
- function isAsyncIterable (obj: any): obj is AsyncIterator<Uint8Array> {
12
- return obj[Symbol.asyncIterator] != null
13
- }
14
-
15
- export async function add (source: Uint8Array | Iterator<Uint8Array> | AsyncIterator<Uint8Array> | ImportCandidate, blockstore: Blockstore, options: UserImporterOptions = {}): Promise<CID> {
16
- let importCandidate: ImportCandidate
17
-
18
- if (source instanceof Uint8Array || isIterable(source) || isAsyncIterable(source)) {
19
- importCandidate = {
20
- // @ts-expect-error FIXME: work out types
21
- content: source
22
- }
23
- } else {
24
- importCandidate = source
25
- }
26
-
27
- const result = await last(importer(importCandidate, blockstore, {
28
- cidVersion: 1,
29
- rawLeaves: true,
30
- ...options
31
- }))
32
-
33
- if (result == null) {
34
- throw new UnknownError('Could not import')
35
- }
36
-
37
- return result.cid
38
- }
39
-
40
- export async function * addStream (source: Iterable<ImportCandidate> | AsyncIterable<ImportCandidate>, blockstore: Blockstore, options: UserImporterOptions = {}): AsyncGenerator<ImportResult> {
41
- yield * importer(source, blockstore, {
42
- cidVersion: 1,
43
- rawLeaves: true,
44
- ...options
45
- })
46
- }