ipfs-unixfs-importer 13.0.0 → 14.0.1
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.
- package/README.md +20 -51
- package/dist/index.min.js +1 -1
- package/dist/src/chunker/fixed-size.d.ts +5 -2
- package/dist/src/chunker/fixed-size.d.ts.map +1 -1
- package/dist/src/chunker/fixed-size.js +35 -0
- package/dist/src/chunker/fixed-size.js.map +1 -0
- package/dist/src/chunker/index.d.ts +6 -0
- package/dist/src/chunker/index.d.ts.map +1 -0
- package/dist/src/chunker/index.js +3 -0
- package/dist/src/chunker/index.js.map +1 -0
- package/dist/src/chunker/rabin.d.ts +8 -9
- package/dist/src/chunker/rabin.d.ts.map +1 -1
- package/dist/src/chunker/rabin.js +56 -0
- package/dist/src/chunker/rabin.js.map +1 -0
- package/dist/src/dag-builder/buffer-importer.d.ts +10 -0
- package/dist/src/dag-builder/buffer-importer.d.ts.map +1 -0
- package/dist/src/dag-builder/buffer-importer.js +38 -0
- package/dist/src/dag-builder/buffer-importer.js.map +1 -0
- package/dist/src/dag-builder/dir.d.ts +8 -9
- package/dist/src/dag-builder/dir.d.ts.map +1 -1
- package/dist/src/dag-builder/dir.js +21 -0
- package/dist/src/dag-builder/dir.js.map +1 -0
- package/dist/src/dag-builder/file.d.ts +19 -0
- package/dist/src/dag-builder/file.d.ts.map +1 -0
- package/dist/src/dag-builder/file.js +133 -0
- package/dist/src/dag-builder/file.js.map +1 -0
- package/dist/src/dag-builder/index.d.ts +16 -7
- package/dist/src/dag-builder/index.d.ts.map +1 -1
- package/dist/src/dag-builder/index.js +70 -0
- package/dist/src/dag-builder/index.js.map +1 -0
- package/dist/src/dag-builder/validate-chunks.d.ts +4 -3
- package/dist/src/dag-builder/validate-chunks.d.ts.map +1 -1
- package/dist/src/dag-builder/validate-chunks.js +24 -0
- package/dist/src/dag-builder/validate-chunks.js.map +1 -0
- package/dist/src/dir-flat.d.ts +14 -24
- package/dist/src/dir-flat.d.ts.map +1 -1
- package/dist/src/dir-flat.js +91 -0
- package/dist/src/dir-flat.js.map +1 -0
- package/dist/src/dir-sharded.d.ts +15 -22
- package/dist/src/dir-sharded.d.ts.map +1 -1
- package/dist/src/dir-sharded.js +210 -0
- package/dist/src/dir-sharded.js.map +1 -0
- package/dist/src/dir.d.ts +34 -76
- package/dist/src/dir.d.ts.map +1 -1
- package/dist/src/dir.js +23 -0
- package/dist/src/dir.js.map +1 -0
- package/dist/src/flat-to-shard.d.ts +4 -16
- package/dist/src/flat-to-shard.d.ts.map +1 -1
- package/dist/src/flat-to-shard.js +41 -0
- package/dist/src/flat-to-shard.js.map +1 -0
- package/dist/src/index.d.ts +278 -34
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +190 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/layout/balanced.d.ts +6 -0
- package/dist/src/layout/balanced.d.ts.map +1 -0
- package/dist/src/layout/balanced.js +16 -0
- package/dist/src/layout/balanced.js.map +1 -0
- package/dist/src/layout/flat.d.ts +3 -0
- package/dist/src/layout/flat.d.ts.map +1 -0
- package/dist/src/layout/flat.js +7 -0
- package/dist/src/layout/flat.js.map +1 -0
- package/dist/src/layout/index.d.ts +11 -0
- package/dist/src/layout/index.d.ts.map +1 -0
- package/dist/src/layout/index.js +4 -0
- package/dist/src/layout/index.js.map +1 -0
- package/dist/src/layout/trickle.d.ts +10 -0
- package/dist/src/layout/trickle.d.ts.map +1 -0
- package/dist/src/layout/trickle.js +121 -0
- package/dist/src/layout/trickle.js.map +1 -0
- package/dist/src/tree-builder.d.ts +9 -7
- package/dist/src/tree-builder.d.ts.map +1 -1
- package/dist/src/tree-builder.js +96 -0
- package/dist/src/tree-builder.js.map +1 -0
- package/dist/src/utils/persist.d.ts +10 -8
- package/dist/src/utils/persist.d.ts.map +1 -1
- package/dist/src/utils/persist.js +15 -0
- package/dist/src/utils/persist.js.map +1 -0
- package/dist/src/utils/to-path-components.d.ts +1 -2
- package/dist/src/utils/to-path-components.d.ts.map +1 -1
- package/dist/src/utils/to-path-components.js +8 -0
- package/dist/src/utils/to-path-components.js.map +1 -0
- package/dist/typedoc-urls.json +18 -9
- package/package.json +14 -6
- package/src/chunker/fixed-size.ts +47 -0
- package/src/chunker/index.ts +5 -0
- package/src/chunker/rabin.ts +79 -0
- package/src/dag-builder/buffer-importer.ts +50 -0
- package/src/dag-builder/dir.ts +31 -0
- package/src/dag-builder/{file/index.js → file.ts} +44 -81
- package/src/dag-builder/index.ts +90 -0
- package/src/dag-builder/validate-chunks.ts +24 -0
- package/src/{dir-flat.js → dir-flat.ts} +24 -49
- package/src/{dir-sharded.js → dir-sharded.ts} +69 -83
- package/src/dir.ts +64 -0
- package/src/{flat-to-shard.js → flat-to-shard.ts} +10 -26
- package/src/index.ts +383 -0
- package/src/layout/balanced.ts +27 -0
- package/src/layout/flat.ts +9 -0
- package/src/layout/index.ts +8 -0
- package/src/layout/trickle.ts +187 -0
- package/src/tree-builder.ts +124 -0
- package/src/utils/persist.ts +27 -0
- package/src/utils/to-path-components.ts +7 -0
- package/dist/src/dag-builder/file/balanced.d.ts +0 -4
- package/dist/src/dag-builder/file/balanced.d.ts.map +0 -1
- package/dist/src/dag-builder/file/buffer-importer.d.ts +0 -4
- package/dist/src/dag-builder/file/buffer-importer.d.ts.map +0 -1
- package/dist/src/dag-builder/file/flat.d.ts +0 -3
- package/dist/src/dag-builder/file/flat.d.ts.map +0 -1
- package/dist/src/dag-builder/file/index.d.ts +0 -9
- package/dist/src/dag-builder/file/index.d.ts.map +0 -1
- package/dist/src/dag-builder/file/trickle.d.ts +0 -9
- package/dist/src/dag-builder/file/trickle.d.ts.map +0 -1
- package/dist/src/options.d.ts +0 -5
- package/dist/src/options.d.ts.map +0 -1
- package/dist/src/types.d.ts +0 -145
- package/dist/src/types.d.ts.map +0 -1
- package/src/chunker/fixed-size.js +0 -42
- package/src/chunker/rabin.js +0 -86
- package/src/dag-builder/dir.js +0 -31
- package/src/dag-builder/file/balanced.js +0 -31
- package/src/dag-builder/file/buffer-importer.js +0 -51
- package/src/dag-builder/file/flat.js +0 -10
- package/src/dag-builder/file/trickle.js +0 -199
- package/src/dag-builder/index.js +0 -121
- package/src/dag-builder/validate-chunks.js +0 -29
- package/src/dir.js +0 -86
- package/src/index.js +0 -68
- package/src/options.js +0 -65
- package/src/tree-builder.js +0 -118
- package/src/types.ts +0 -135
- package/src/utils/persist.js +0 -39
- package/src/utils/to-path-components.js +0 -9
package/README.md
CHANGED
|
@@ -14,7 +14,10 @@
|
|
|
14
14
|
- [Example](#example)
|
|
15
15
|
- [API](#api)
|
|
16
16
|
- [const stream = importer(source, blockstore \[, options\])](#const-stream--importersource-blockstore--options)
|
|
17
|
-
- [
|
|
17
|
+
- [const result = await importFile(content, blockstore \[, options\])](#const-result--await-importfilecontent-blockstore--options)
|
|
18
|
+
- [const result = await importDirectory(content, blockstore \[, options\])](#const-result--await-importdirectorycontent-blockstore--options)
|
|
19
|
+
- [const result = await importBytes(buf, blockstore \[, options\])](#const-result--await-importbytesbuf-blockstore--options)
|
|
20
|
+
- [const result = await importByteStream(source, blockstore \[, options\])](#const-result--await-importbytestreamsource-blockstore--options)
|
|
18
21
|
- [API Docs](#api-docs)
|
|
19
22
|
- [License](#license)
|
|
20
23
|
- [Contribute](#contribute)
|
|
@@ -95,7 +98,7 @@ When run, metadata about DAGNodes in the created tree is printed until the root:
|
|
|
95
98
|
## API
|
|
96
99
|
|
|
97
100
|
```js
|
|
98
|
-
import { importer } from 'ipfs-unixfs-importer'
|
|
101
|
+
import { importer, importFile, importDir, importBytes, importByteStream } from 'ipfs-unixfs-importer'
|
|
99
102
|
```
|
|
100
103
|
|
|
101
104
|
### const stream = importer(source, blockstore \[, options])
|
|
@@ -117,55 +120,21 @@ The `importer` function returns an async iterator takes a source async iterator
|
|
|
117
120
|
|
|
118
121
|
The input's file paths and directory structure will be preserved in the [`dag-pb`](https://github.com/ipld/js-dag-pb) created nodes.
|
|
119
122
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
- `layerRepeat` (positive integer, defaults to 4): (only applicable to the `trickle` DAG builder strategy). The maximum repetition of parent nodes for each layer of the tree.
|
|
136
|
-
- `reduceSingleLeafToSelf` (boolean, defaults to `true`): optimization for, when reducing a set of nodes with one node, reduce it to that node.
|
|
137
|
-
- `hamtHashFn` (async function(string) Buffer): a function that hashes file names to create HAMT shards
|
|
138
|
-
- `hamtBucketBits` (positive integer, defaults to `8`): the number of bits at each bucket of the HAMT
|
|
139
|
-
- `progress` (function): a function that will be called with the byte length of chunks as a file is added to ipfs.
|
|
140
|
-
- `onlyHash` (boolean, defaults to false): Only chunk and hash - do not write to disk
|
|
141
|
-
- `hashAlg` (string): multihash hashing algorithm to use
|
|
142
|
-
- `cidVersion` (integer, default 0): the CID version to use when storing the data (storage keys are based on the CID, *including* it's version)
|
|
143
|
-
- `rawLeaves` (boolean, defaults to false): When a file would span multiple DAGNodes, if this is true the leaf nodes will not be wrapped in `UnixFS` protobufs and will instead contain the raw file bytes
|
|
144
|
-
- `leafType` (string, defaults to `'file'`) what type of UnixFS node leaves should be - can be `'file'` or `'raw'` (ignored when `rawLeaves` is `true`)
|
|
145
|
-
- `blockWriteConcurrency` (positive integer, defaults to 10) How many blocks to hash and write to the block store concurrently. For small numbers of large files this should be high (e.g. 50).
|
|
146
|
-
- `fileImportConcurrency` (number, defaults to 50) How many files to import concurrently. For large numbers of small files this should be high (e.g. 50).
|
|
147
|
-
|
|
148
|
-
## Overriding internals
|
|
149
|
-
|
|
150
|
-
Several aspects of the importer are overridable by specifying functions as part of the options object with these keys:
|
|
151
|
-
|
|
152
|
-
- `chunkValidator` (function): Optional function that supports the signature `async function * (source, options)`
|
|
153
|
-
- This function takes input from the `content` field of imported entries. It should transform them into `Buffer`s, throwing an error if it cannot.
|
|
154
|
-
- It should yield `Buffer` objects constructed from the `source` or throw an `Error`
|
|
155
|
-
- `chunker` (function): Optional function that supports the signature `async function * (source, options)` where `source` is an async generator and `options` is an options object
|
|
156
|
-
- It should yield `Buffer` objects.
|
|
157
|
-
- `bufferImporter` (function): Optional function that supports the signature `async function * (entry, blockstore, options)`
|
|
158
|
-
- This function should read `Buffer`s from `source` and persist them using `blockstore.put` or similar
|
|
159
|
-
- `entry` is the `{ path, content }` entry, where `entry.content` is an async generator that yields Buffers
|
|
160
|
-
- It should yield functions that return a Promise that resolves to an object with the properties `{ cid, unixfs, size }` where `cid` is a [CID], `unixfs` is a [UnixFS] entry and `size` is a `Number` that represents the serialized size of the [IPLD] node that holds the buffer data.
|
|
161
|
-
- Values will be pulled from this generator in parallel - the amount of parallelisation is controlled by the `blockWriteConcurrency` option (default: 10)
|
|
162
|
-
- `dagBuilder` (function): Optional function that supports the signature `async function * (source, blockstore, options)`
|
|
163
|
-
- This function should read `{ path, content }` entries from `source` and turn them into DAGs
|
|
164
|
-
- It should yield a `function` that returns a `Promise` that resolves to `{ cid, path, unixfs, node }` where `cid` is a `CID`, `path` is a string, `unixfs` is a UnixFS entry and `node` is a `DAGNode`.
|
|
165
|
-
- Values will be pulled from this generator in parallel - the amount of parallelisation is controlled by the `fileImportConcurrency` option (default: 50)
|
|
166
|
-
- `treeBuilder` (function): Optional function that supports the signature `async function * (source, blockstore, options)`
|
|
167
|
-
- This function should read `{ cid, path, unixfs, node }` entries from `source` and place them in a directory structure
|
|
168
|
-
- It should yield an object with the properties `{ cid, path, unixfs, size }` where `cid` is a `CID`, `path` is a string, `unixfs` is a UnixFS entry and `size` is a `Number`.
|
|
123
|
+
### const result = await importFile(content, blockstore \[, options])
|
|
124
|
+
|
|
125
|
+
A convenience function for importing a single file or directory.
|
|
126
|
+
|
|
127
|
+
### const result = await importDirectory(content, blockstore \[, options])
|
|
128
|
+
|
|
129
|
+
A convenience function for importing a directory - note this is non-recursive, to import recursively use the [importer](#const-stream--importersource-blockstore--options) function.
|
|
130
|
+
|
|
131
|
+
### const result = await importBytes(buf, blockstore \[, options])
|
|
132
|
+
|
|
133
|
+
A convenience function for importing a single Uint8Array.
|
|
134
|
+
|
|
135
|
+
### const result = await importByteStream(source, blockstore \[, options])
|
|
136
|
+
|
|
137
|
+
A convenience function for importing a single stream of Uint8Arrays.
|
|
169
138
|
|
|
170
139
|
## API Docs
|
|
171
140
|
|