This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(breaking change): use stream on stats.bw (#686)
* feat(breaking change): use stream on stats.bw * add some type checking * readable stream and pull stream on bandwidth stats * fix bw pull stream * Bump interface-ipfs-core version
- Loading branch information
Showing
10 changed files
with
107 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict' | ||
|
||
const toPull = require('stream-to-pull-stream') | ||
const pull = require('pull-stream') | ||
const transformChunk = require('./bw-util') | ||
const deferred = require('pull-defer') | ||
|
||
module.exports = (send) => { | ||
return (hash, opts) => { | ||
opts = opts || {} | ||
|
||
const p = deferred.source() | ||
|
||
send({ | ||
path: 'stats/bw', | ||
qs: opts | ||
}, (err, stream) => { | ||
if (err) { | ||
return p.end(err) | ||
} | ||
|
||
p.resolve(pull( | ||
toPull.source(stream), | ||
pull.map(transformChunk) | ||
)) | ||
}) | ||
|
||
return p | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict' | ||
|
||
const Stream = require('readable-stream') | ||
const pump = require('pump') | ||
const transformChunk = require('./bw-util') | ||
|
||
module.exports = (send) => { | ||
return (hash, opts) => { | ||
opts = opts || {} | ||
|
||
const pt = new Stream.Transform({ | ||
objectMode: true, | ||
transform (chunk, encoding, cb) { | ||
cb(null, transformChunk(chunk)) | ||
} | ||
}) | ||
|
||
send({ | ||
path: 'stats/bw', | ||
qs: opts | ||
}, (err, stream) => { | ||
if (err) { | ||
return pt.destroy(err) | ||
} | ||
|
||
pump(stream, pt) | ||
}) | ||
|
||
return pt | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict' | ||
|
||
const Big = require('big.js') | ||
|
||
module.exports = (chunk) => { | ||
return { | ||
totalIn: new Big(chunk.TotalIn), | ||
totalOut: new Big(chunk.TotalOut), | ||
rateIn: new Big(chunk.RateIn), | ||
rateOut: new Big(chunk.RateOut) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters