This repository was archived by the owner on Mar 10, 2020. It is now read-only.
File tree 2 files changed +21
-16
lines changed
2 files changed +21
-16
lines changed Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
3
const promisify = require ( 'promisify-es6' )
4
- const streamToValue = require ( '../utils/stream-to-value ' )
4
+ const { Transform } = require ( 'readable-stream ' )
5
5
6
6
const transform = function ( res , callback ) {
7
- streamToValue ( res , ( err , data ) => {
8
- if ( err ) {
9
- return callback ( err )
7
+ const output = new Transform ( {
8
+ objectMode : true ,
9
+ transform ( chunk , encoding , cb ) {
10
+ cb ( null , {
11
+ totalIn : chunk . TotalIn ,
12
+ totalOut : chunk . TotalOut ,
13
+ rateIn : chunk . RateIn ,
14
+ rateOut : chunk . RateOut
15
+ } )
10
16
}
11
-
12
- callback ( null , {
13
- totalIn : data [ 0 ] . TotalIn ,
14
- totalOut : data [ 0 ] . TotalOut ,
15
- rateIn : data [ 0 ] . RateIn ,
16
- rateOut : data [ 0 ] . RateOut
17
- } )
18
17
} )
18
+
19
+ res . pipe ( output )
20
+ callback ( null , output )
19
21
}
20
22
21
23
module . exports = ( send ) => {
Original file line number Diff line number Diff line change @@ -49,11 +49,14 @@ describe('stats', function () {
49
49
ipfs . stats . bw ( ( err , res ) => {
50
50
expect ( err ) . to . not . exist ( )
51
51
expect ( res ) . to . exist ( )
52
- expect ( res ) . to . have . a . property ( 'totalIn' )
53
- expect ( res ) . to . have . a . property ( 'totalOut' )
54
- expect ( res ) . to . have . a . property ( 'rateIn' )
55
- expect ( res ) . to . have . a . property ( 'rateOut' )
56
- done ( )
52
+
53
+ res . once ( 'data' , ( data ) => {
54
+ expect ( data ) . to . have . a . property ( 'totalIn' )
55
+ expect ( data ) . to . have . a . property ( 'totalOut' )
56
+ expect ( data ) . to . have . a . property ( 'rateIn' )
57
+ expect ( data ) . to . have . a . property ( 'rateOut' )
58
+ done ( )
59
+ } )
57
60
} )
58
61
} )
59
62
You can’t perform that action at this time.
0 commit comments