You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 12, 2020. It is now read-only.
The `unixfs-engine` exports the [`unixfs-importer`](https://npmjs.com/packages/ipfs-unixfs-importer) and [`unixfs-exporter`](https://npmjs.com/packages/ipfs-unixfs-exporter) modules. Please see those modules for for full documentation.
43
38
44
-
#### Importer example
39
+
###Importing a file
45
40
46
-
Let's create a little directory to import:
41
+
The importer is a [pull-stream through](https://github.com/pull-stream/pull-stream#through) which takes objects of the form `{ path, content }` where `path` is a string path and `content` can be a `Buffer`, a `ReadableStream` or a `pull-stream` that emits `Buffer`s.
// Calling write on the importer to filesAddStream the file/object tuples
82
-
filesAddStream.write(input)
83
-
filesAddStream.write(input2)
84
-
filesAddStream.end()
85
-
```
43
+
It requires an [ipld](https://npmjs.com/packages/ipld) resolver to persist [DAGNodes](https://npmjs.com/packages/ipld-dag-pb) and make them available over IPFS.
86
44
87
-
When run, the stat of DAG Node is outputted for each file on data event until the root:
45
+
See the [`unixfs-importer`](https://npmjs.com/packages/ipfs-unixfs-importer) module for full documentation.
The `import` object is a duplex pull stream that takes objects of the form:
117
-
118
-
```js
119
-
{
120
-
path:'a name',
121
-
content: (Buffer or Readable stream)
122
-
}
123
-
```
124
-
125
-
`import` will output file info objects as files get stored in IPFS. When stats on a node are emitted they are guaranteed to have been written.
126
-
127
-
`dag` is an instance of the [`IPLD Resolver`](https://github.com/ipld/js-ipld-resolver) or the [`js-ipfs``dag api`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/DAG.md)
128
-
129
-
The input's file paths and directory structure will be preserved in the [`dag-pb`](https://github.com/ipld/js-ipld-dag-pb) created nodes.
130
-
131
-
`options` is an JavaScript option that might include the following keys:
132
-
133
-
-`wrap` (boolean, defaults to false): if true, a wrapping node will be created
134
-
-`shardSplitThreshold` (positive integer, defaults to 1000): the number of directory entries above which we decide to use a sharding directory builder (instead of the default flat one)
135
-
-`chunker` (string, defaults to `"fixed"`): the chunking strategy. Now only supports `"fixed"`
136
-
-`chunkerOptions` (object, optional): the options for the chunker. Defaults to an object with the following properties:
137
-
-`maxChunkSize` (positive integer, defaults to `262144`): the maximum chunk size for the `fixed` chunker.
138
-
-`strategy` (string, defaults to `"balanced"`): the DAG builder strategy name. Supports:
-`maxChildrenPerNode` (positive integer, defaults to `174`): the maximum children per node for the `balanced` and `trickle` DAG builder strategies
143
-
-`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.
144
-
-`reduceSingleLeafToSelf` (boolean, defaults to `true`): optimization for, when reducing a set of nodes with one node, reduce it to that node.
145
-
-`dirBuilder` (object): the options for the directory builder
146
-
-`hamt` (object): the options for the HAMT sharded directory builder
147
-
- bits (positive integer, defaults to `8`): the number of bits at each bucket of the HAMT
148
-
-`progress` (function): a function that will be called with the byte length of chunks as a file is added to ipfs.
149
-
-`onlyHash` (boolean, defaults to false): Only chunk and hash - do not write to disk
150
-
-`hashAlg` (string): multihash hashing algorithm to use
151
-
-`cidVersion` (integer, default 0): the CID version to use when storing the data (storage keys are based on the CID, _including_ it's version)
152
-
-`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
153
-
-`leafType` (string, defaults to `'file'`) what type of UnixFS node leaves should be - can be `'file'` or `'raw'` (ignored when `rawLeaves` is `true`)
154
-
155
-
### Exporter
156
-
157
-
#### Exporter example
158
-
159
-
```js
160
-
// Create an export source pull-stream cid or ipfs path you want to export and a
161
-
// <dag or ipld-resolver instance> to fetch the file from
162
-
constfilesStream=Exporter(<cid or ipfsPath>, <dag or ipld-resolver instance>)
### new Exporter(<cidoripfsPath>, <dagoripld-resolver>, <options>)
175
-
176
-
Uses the given [dag API][] or an [ipld-resolver instance][] to fetch an IPFS [UnixFS][] object(s) by their multiaddress.
177
-
178
-
Creates a new readable stream in object mode that outputs objects of the form
179
-
180
-
```js
181
-
{
182
-
path:'a name',
183
-
content: (Buffer or Readable stream)
184
-
}
185
-
```
186
-
187
-
#### `offset` and `length`
188
-
189
-
`offset` and `length` arguments can optionally be passed to the reader function. These will cause the returned stream to only emit bytes starting at `offset` and with length of `length`.
190
-
191
-
See [the tests](test/reader.js) for examples of using these arguments.
// file.content is a pull stream containing only the first 10 bytes of the file
55
+
pull.values([{
56
+
path:'/tmp/foo/bar',
57
+
content:fs.createReadStream(file)
58
+
}]),
59
+
60
+
// You need to create and pass an ipld resolver instance
61
+
// https://npmjs.com/packages/ipld
62
+
importer(<ipld-resolver instance>, <options>),
63
+
64
+
// Handle the error and do something with the results
65
+
pull.collect((err, files) => {
66
+
console.info(files)
205
67
})
206
68
)
207
69
```
208
70
209
-
#### Errors
71
+
### Exporting a file
72
+
73
+
The exporter is a [pull-stream source](https://github.com/pull-stream/pull-stream#through) which takes a [cid](https://npmjs.com/packages/cids) and an [ipld](https://npmjs.com/packages/ipld) resolver.
210
74
211
-
Errors are received by [pull-stream][] sinks.
75
+
See the [`unixfs-exporter`](https://npmjs.com/packages/ipfs-unixfs-exporter) module for full documentation.
0 commit comments