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

Commit c9aedbf

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

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

Diff for: 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`

Diff for: js/src/stats.js

+40
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')
@@ -107,6 +127,26 @@ module.exports = (common) => {
107127
expect(res).to.have.a.property('totalOut')
108128
expect(res).to.have.a.property('rateIn')
109129
expect(res).to.have.a.property('rateOut')
130+
done()
131+
})
132+
})
133+
134+
it('.bw Promise Poll', (done) => {
135+
if (!withGo) {
136+
console.log('Not supported in js-ipfs yet')
137+
return
138+
}
139+
140+
return ipfs.stats.bw({poll: true}).then((res) => {
141+
expect(res).to.exist()
142+
143+
res.once('data', (data) => {
144+
expect(data).to.have.a.property('totalIn')
145+
expect(data).to.have.a.property('totalOut')
146+
expect(data).to.have.a.property('rateIn')
147+
expect(data).to.have.a.property('rateOut')
148+
done()
149+
})
110150
})
111151
})
112152

0 commit comments

Comments
 (0)