@@ -165,9 +165,9 @@ filesStream.on('data', (file) => file.content.pipe(process.stdout))
165
165
const Exporter = require (' ipfs-unixfs-engine' ).Exporter
166
166
```
167
167
168
- ### new Exporter(<cid or ipfsPath >, <dag or ipld-resolver >)
168
+ ### new Exporter(<cid or ipfsPath >, <dag or ipld-resolver >, < options > )
169
169
170
- Uses the given [ dag API] or an [ ipld-resolver instance] [ ] to fetch an IPFS [ UnixFS] [ ] object(s) by their multiaddress.
170
+ Uses the given [ dag API] [ ] or an [ ipld-resolver instance] [ ] to fetch an IPFS [ UnixFS] [ ] object(s) by their multiaddress.
171
171
172
172
Creates a new readable stream in object mode that outputs objects of the form
173
173
@@ -178,57 +178,6 @@ Creates a new readable stream in object mode that outputs objects of the form
178
178
}
179
179
```
180
180
181
- Errors are received as with a normal stream, by listening on the ` 'error' ` event to be emitted.
182
-
183
-
184
- [ dag API ] : https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/DAG.md
185
- [ ipld-resolver instance ] : https://github.com/ipld/js-ipld-resolver
186
- [ UnixFS ] : https://github.com/ipfs/specs/tree/master/unixfs
187
-
188
- ## Reader
189
-
190
- The ` reader ` allows you to receive part or all of a file as a [ pull-stream] .
191
-
192
- #### Reader example
193
-
194
- ``` js
195
- const readable = require (' ipfs-unixfs-engine' ).readable
196
- const pull = require (' pull-stream' )
197
- const drain = require (' pull-stream/sinks/collect' )
198
-
199
- pull (
200
- readable (cid, ipldResolver)
201
- collect ((error , chunks ) => {
202
- // do something with the file chunks and/or handle errors
203
- })
204
- )
205
- ```
206
-
207
- #### Reader API
208
-
209
- ``` js
210
- const reader = require (' ipfs-unixfs-engine' ).reader
211
- ```
212
-
213
- ### reader(<cid or ipfsPath >, <dag or ipld-resolver >, <begin >, <end >)
214
-
215
- Uses the given [ dag API] [ ] or an [ ipld-resolver instance] [ ] to fetch an IPFS [ UnixFS] [ ] object by their multiaddress.
216
-
217
- Creates a new [ pull-stream] [ ] that sends the requested chunks of data as a series of [ Buffer] [ ] objects.
218
-
219
- ``` js
220
- const readable = require (' ipfs-unixfs-engine' ).readable
221
- const pull = require (' pull-stream' )
222
- const drain = require (' pull-stream/sinks/drain' )
223
-
224
- pull (
225
- readable (cid, ipldResolver),
226
- drain ((chunk ) => {
227
- // do something with the file chunk
228
- })
229
- )
230
- ```
231
-
232
181
#### ` begin ` and ` end `
233
182
234
183
` begin ` and ` end ` arguments can optionally be passed to the reader function. These follow the same semantics as the JavaScript [ ` Array.slice(begin, end) ` ] [ ] method.
@@ -240,14 +189,17 @@ A negative `begin` starts the slice from the end of the stream and a negative `e
240
189
See [ the tests] ( test/reader.js ) for examples of using these arguments.
241
190
242
191
``` js
243
- const readable = require (' ipfs-unixfs-engine' ).readable
192
+ const exporter = require (' ipfs-unixfs-engine' ).exporter
244
193
const pull = require (' pull-stream' )
245
194
const drain = require (' pull-stream/sinks/drain' )
246
195
247
196
pull (
248
- readable (cid, ipldResolver, 0 , 10 )
249
- drain ((chunk ) => {
250
- // chunk is a Buffer containing only the first 10 bytes of the stream
197
+ exporter (cid, ipldResolver, {
198
+ begin: 0 ,
199
+ end: 10
200
+ })
201
+ drain ((file ) => {
202
+ // file.content() is a pull stream containing only the first 10 bytes of the file
251
203
})
252
204
)
253
205
```
@@ -257,23 +209,22 @@ pull(
257
209
Errors are received by [ pull-stream] [ ] sinks.
258
210
259
211
``` js
260
- const readable = require (' ipfs-unixfs-engine' ).readable
212
+ const exporter = require (' ipfs-unixfs-engine' ).exporter
261
213
const pull = require (' pull-stream' )
262
214
const drain = require (' pull-stream/sinks/collect' )
263
215
264
216
pull (
265
- readable (cid, ipldResolver, 0 , 10 )
217
+ exporter (cid, ipldResolver)
266
218
collect ((error , chunks ) => {
267
219
// handle the error
268
220
})
269
221
)
270
222
```
271
223
272
- [ pull-stream ] : https://www.npmjs.com/package/pull-stream
273
- [ Buffer ] : https://www.npmjs.com/package/buffer
274
224
[ dag API ] : https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/DAG.md
275
225
[ ipld-resolver instance ] : https://github.com/ipld/js-ipld-resolver
276
226
[ UnixFS ] : https://github.com/ipfs/specs/tree/master/unixfs
227
+ [ pull-stream ] : https://www.npmjs.com/package/pull-stream
277
228
[ `Array.slice(begin, end)` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice
278
229
279
230
## Contribute
0 commit comments