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

Commit ed6a280

Browse files
committed
update test and readme whoops
1 parent f5b9e63 commit ed6a280

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ add.on('end', () => {
6666
// Calling write on the importer to add the file/object tuples
6767

6868
add.write(input)
69+
add.write(input2)
6970
add.end()
7071
```
7172

@@ -121,13 +122,13 @@ const repo = new ipfsRepo('', { stores: memStore })
121122
const blocks = new ipfsBlockService(repo)
122123
const dag = new ipfsMerkleDag.DAGService(blocks)
123124
124-
// Create an export event with the hash you want to export and a dag service
125+
// Create an export readable object stream with the hash you want to export and a dag service
125126
126127
const exportEvent = Exporter(hash, dag)
127128
128129
// Pipe the return stream to console
129130
130-
exportEvent.on('file', (result) => {
131+
exportEvent.on('data', (result) => {
131132
result.stream.pipe(process.stdout)
132133
}
133134
```
@@ -137,8 +138,7 @@ exportEvent.on('file', (result) => {
137138
const Importer = require('ipfs-unixfs-engine').exporter
138139
```
139140

140-
The exporter is an event emitter that returns a stream of the file found
141-
by the multihash of the file from the dag service.
141+
The exporter is a readable stream in object mode that returns an object ```{ stream: stream, path: 'path' }``` by the multihash of the file from the dag service.
142142

143143

144144
## install

test/test-exporter.js

+28-3
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,40 @@ module.exports = function (repo) {
8888
}, 1000)
8989
})
9090

91-
it('expect a dag service error over stream', (done) => {
91+
it('returns a null stream for dir', (done) => {
92+
const hash = 'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn' // This hash doesn't exist in the repo
93+
const bs = new BlockService(repo)
94+
const ds = new DAGService(bs)
95+
const testExport = exporter(hash, ds)
96+
testExport.on('data', (dir) => {
97+
expect(dir.stream).to.equal(null)
98+
done()
99+
})
100+
})
101+
102+
it('fails on non existent hash', (done) => {
92103
const hash = 'QmWChcSFMNcFkfeJtNd8Yru1rE6PhtCRfewi1tMwjkwKj3' // This hash doesn't exist in the repo
93104
const bs = new BlockService(repo)
94105
const ds = new DAGService(bs)
95106
const testExport = exporter(hash, ds)
96107
testExport.on('error', (err) => {
108+
const error = err.toString()
97109
expect(err).to.exist
98-
expect(err.code).to.equal('ENOENT')
99-
done()
110+
const browser = error.includes('Error: key not found:')
111+
const node = error.includes('no such file or directory')
112+
// the browser and node js return different errors
113+
if (browser) {
114+
expect(error).to.contain('Error: key not found:')
115+
done()
116+
}
117+
if (node) {
118+
expect(error).to.contain('no such file or directory')
119+
done()
120+
}
121+
if (!node && !browser) {
122+
expect(node).to.equal(true)
123+
done()
124+
}
100125
})
101126
})
102127
})

0 commit comments

Comments
 (0)