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

Commit 17aebbf

Browse files
committed
feat(breaking change): use stream on stats.bw
1 parent 9d91267 commit 17aebbf

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

SPEC/STATS.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ Where:
2525
- `poll` is used to print bandwidth at an interval.
2626
- `interval` is the time interval to wait between updating output, if `poll` is true.
2727

28-
`callback` must follow `function (err, stats) {}` signature, where `err` is an error if the operation was not successful. `stats` is an Object containing the following keys:
28+
If `poll` is `true`, then `callback` must follow `function (err, stream) {}` signature, where `err` is an error if the operation was not successful and `stream` is a Readable Stream where you can listen to the event `data` with a listener that must follow `function (stat) {}` signature.
29+
30+
Otherwise, `callback` must follow `function (err, stat) {}` signature, where `err` is an error and `stat` is an Object containing the following keys:
2931

3032
- `totalIn`
3133
- `totalOut`

js/src/stats.js

+42
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,26 @@ module.exports = (common) => {
9595
})
9696
})
9797

98+
it('.bw Poll', (done) => {
99+
if (!withGo) {
100+
console.log('Not supported in js-ipfs yet')
101+
return done()
102+
}
103+
104+
ipfs.stats.bw({poll: true}, (err, res) => {
105+
expect(err).to.not.exist()
106+
expect(res).to.exist()
107+
108+
res.once('data', (data) => {
109+
expect(data).to.have.a.property('totalIn')
110+
expect(data).to.have.a.property('totalOut')
111+
expect(data).to.have.a.property('rateIn')
112+
expect(data).to.have.a.property('rateOut')
113+
done()
114+
})
115+
})
116+
})
117+
98118
it('.bw Promise', () => {
99119
if (!withGo) {
100120
console.log('Not supported in js-ipfs yet')
@@ -110,6 +130,28 @@ module.exports = (common) => {
110130
})
111131
})
112132

133+
it('.bw Promise Poll', (done) => {
134+
if (!withGo) {
135+
console.log('Not supported in js-ipfs yet')
136+
return
137+
}
138+
139+
ipfs.stats.bw({poll: true}).then((res) => {
140+
expect(res).to.exist()
141+
142+
res.once('data', (data) => {
143+
expect(data).to.have.a.property('totalIn')
144+
expect(data).to.have.a.property('totalOut')
145+
expect(data).to.have.a.property('rateIn')
146+
expect(data).to.have.a.property('rateOut')
147+
done()
148+
})
149+
}).catch(err => {
150+
expect(err).to.not.exist()
151+
done()
152+
})
153+
})
154+
113155
it('.repo', (done) => {
114156
if (!withGo) {
115157
console.log('Not supported in js-ipfs yet')

0 commit comments

Comments
 (0)