@@ -165,9 +165,9 @@ filesStream.on('data', (file) => file.content.pipe(process.stdout))
165165const Exporter = require (' ipfs-unixfs-engine' ).Exporter
166166```
167167
168- ### new Exporter(<cid or ipfsPath >, <dag or ipld-resolver >)
168+ ### new Exporter(<cid or ipfsPath >, <dag or ipld-resolver >, < options > )
169169
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.
171171
172172Creates a new readable stream in object mode that outputs objects of the form
173173
@@ -178,57 +178,6 @@ Creates a new readable stream in object mode that outputs objects of the form
178178}
179179```
180180
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-
232181#### ` begin ` and ` end `
233182
234183` 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
240189See [ the tests] ( test/reader.js ) for examples of using these arguments.
241190
242191``` js
243- const readable = require (' ipfs-unixfs-engine' ).readable
192+ const exporter = require (' ipfs-unixfs-engine' ).exporter
244193const pull = require (' pull-stream' )
245194const drain = require (' pull-stream/sinks/drain' )
246195
247196pull (
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
251203 })
252204)
253205```
@@ -257,23 +209,22 @@ pull(
257209Errors are received by [ pull-stream] [ ] sinks.
258210
259211``` js
260- const readable = require (' ipfs-unixfs-engine' ).readable
212+ const exporter = require (' ipfs-unixfs-engine' ).exporter
261213const pull = require (' pull-stream' )
262214const drain = require (' pull-stream/sinks/collect' )
263215
264216pull (
265- readable (cid, ipldResolver, 0 , 10 )
217+ exporter (cid, ipldResolver)
266218 collect ((error , chunks ) => {
267219 // handle the error
268220 })
269221)
270222```
271223
272- [ pull-stream ] : https://www.npmjs.com/package/pull-stream
273- [ Buffer ] : https://www.npmjs.com/package/buffer
274224[ dag API ] : https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/DAG.md
275225[ ipld-resolver instance ] : https://github.com/ipld/js-ipld-resolver
276226[ UnixFS ] : https://github.com/ipfs/specs/tree/master/unixfs
227+ [ pull-stream ] : https://www.npmjs.com/package/pull-stream
277228[ `Array.slice(begin, end)` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice
278229
279230## Contribute
0 commit comments