Skip to content
This repository was archived by the owner on Aug 12, 2020. It is now read-only.

Commit 73ddf53

Browse files
committed
docs: update readme, fix #168
1 parent ed62755 commit 73ddf53

File tree

1 file changed

+39
-34
lines changed

1 file changed

+39
-34
lines changed

README.md

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ IPFS unixFS Engine
1212
![](https://img.shields.io/badge/npm-%3E%3D3.0.0-orange.svg?style=flat-square)
1313
![](https://img.shields.io/badge/Node.js-%3E%3D4.0.0-orange.svg?style=flat-square)
1414

15-
> JavaScript implementation of the layout and chunking mechanisms used by IPFS
15+
> JavaScript implementation of the layout and chunking mechanisms used by IPFS to handle Files
1616
1717
## Table of Contents
1818

@@ -35,9 +35,12 @@ IPFS unixFS Engine
3535

3636
## Usage
3737

38-
### Example Importer
38+
### Importer
39+
40+
#### Importer example
3941

4042
Let's create a little directory to import:
43+
4144
```sh
4245
> cd /tmp
4346
> mkdir foo
@@ -46,6 +49,7 @@ Let's create a little directory to import:
4649
```
4750

4851
And write the importing logic:
52+
4953
```js
5054
const Importer = require('ipfs-unixfs-engine').Importer
5155
const filesAddStream = new Importer(<dag or ipld-resolver instance)
@@ -74,7 +78,8 @@ filesAddStream.end()
7478
```
7579

7680
When run, the stat of DAG Node is outputted for each file on data event until the root:
77-
```
81+
82+
```js
7883
{ multihash: <Buffer 12 20 bd e2 2b 57 3f 6f bd 7c cc 5a 11 7f 28 6c a2 9a 9f c0 90 e1 d4 16 d0 5f 42 81 ec 0c 2a 7f 7f 93>,
7984
size: 39243,
8085
path: '/tmp/foo/bar' }
@@ -93,15 +98,15 @@ When run, the stat of DAG Node is outputted for each file on data event until th
9398

9499
```
95100

96-
### Importer API
101+
#### Importer API
97102

98103
```js
99104
const Importer = require('ipfs-unixfs-engine').Importer
100105
```
101106

102-
#### const add = new Importer(dag)
107+
#### const import = new Importer(dag [, options])
103108

104-
The importer is a object Transform stream that accepts objects of the form
109+
The `import` object is a duplex pull stream that takes objects of the form:
105110

106111
```js
107112
{
@@ -110,50 +115,50 @@ The importer is a object Transform stream that accepts objects of the form
110115
}
111116
```
112117

113-
The stream will output IPFS DAG Node stats for the nodes as they are added to
114-
the DAG Service. When stats on a node are emitted they are guaranteed to have
115-
been written into the [DAG Service][]'s storage mechanism.
118+
`import` will outoyt file info objects as files get stored in IPFS. When stats on a node are emitted they are guaranteed to have been written.
116119

117-
The input's file paths and directory structure will be preserved in the DAG
118-
Nodes.
120+
`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/tree/master/API/dag)
119121

120-
### Importer options
122+
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.
121123

122-
In the second argument of the importer constructor you can specify the following options:
124+
`options` is an JavaScript option that might include the following keys:
123125

124-
* `wrap` (boolean, defaults to false): if true, a wrapping node will be created
125-
* `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)
126-
* `chunker` (string, defaults to `"fixed"`): the chunking strategy. Now only supports `"fixed"`
127-
* `chunkerOptions` (object, optional): the options for the chunker. Defaults to an object with the following properties:
128-
* `maxChunkSize` (positive integer, defaults to `262144`): the maximum chunk size for the `fixed` chunker.
129-
* `strategy` (string, defaults to `"balanced"`): the DAG builder strategy name. Supports:
130-
* `flat`: flat list of chunks
131-
* `balanced`: builds a balanced tree
132-
* `trickle`: builds [a trickle tree](https://github.com/ipfs/specs/pull/57#issuecomment-265205384)
133-
* `maxChildrenPerNode` (positive integer, defaults to `174`): the maximum children per node for the `balanced` and `trickle` DAG builder strategies
134-
* `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.
135-
* `reduceSingleLeafToSelf` (boolean, defaults to `false`): optimization for, when reducing a set of nodes with one node, reduce it to that node.
136-
* `dirBuilder` (object): the options for the directory builder
137-
* `hamt` (object): the options for the HAMT sharded directory builder
138-
* bits (positive integer, defaults to `5`): the number of bits at each bucket of the HAMT
126+
- `wrap` (boolean, defaults to false): if true, a wrapping node will be created
127+
- `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)
128+
- `chunker` (string, defaults to `"fixed"`): the chunking strategy. Now only supports `"fixed"`
129+
- `chunkerOptions` (object, optional): the options for the chunker. Defaults to an object with the following properties:
130+
- `maxChunkSize` (positive integer, defaults to `262144`): the maximum chunk size for the `fixed` chunker.
131+
- `strategy` (string, defaults to `"balanced"`): the DAG builder strategy name. Supports:
132+
- `flat`: flat list of chunks
133+
- `balanced`: builds a balanced tree
134+
- `trickle`: builds [a trickle tree](https://github.com/ipfs/specs/pull/57#issuecomment-265205384)
135+
- `maxChildrenPerNode` (positive integer, defaults to `174`): the maximum children per node for the `balanced` and `trickle` DAG builder strategies
136+
- `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.
137+
- `reduceSingleLeafToSelf` (boolean, defaults to `false`): optimization for, when reducing a set of nodes with one node, reduce it to that node.
138+
- `dirBuilder` (object): the options for the directory builder
139+
- `hamt` (object): the options for the HAMT sharded directory builder
140+
- bits (positive integer, defaults to `5`): the number of bits at each bucket of the HAMT
139141

140-
### Example Exporter
142+
### Exporter
141143

142-
```
143-
// Create an export readable object stream with the hash you want to export and a dag service
144-
const filesStream = Exporter(<multihash>, <dag or ipld-resolver instance>)
144+
#### Exporter example
145+
146+
```js
147+
// Create an export source pull-stream cid or ipfs path you want to export and a
148+
// <dag or ipld-resolver instance> to fetch the file from
149+
const filesStream = Exporter(<cid or ipfsPath>, <dag or ipld-resolver instance>)
145150

146151
// Pipe the return stream to console
147152
filesStream.on('data', (file) => file.content.pipe(process.stdout))
148153
```
149154

150-
### Exporter: API
155+
#### Exporter API
151156

152157
```js
153158
const Exporter = require('ipfs-unixfs-engine').Exporter
154159
```
155160

156-
### new Exporter(<hash>, <dag or ipld-resolver>)
161+
### new Exporter(<cid or ipfsPath>, <dag or ipld-resolver>)
157162

158163
Uses the given [dag API or an ipld-resolver instance][] to fetch an IPFS [UnixFS][] object(s) by their multiaddress.
159164

0 commit comments

Comments
 (0)