This repository has been archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 300
feat(breaking change): use stream on stats.bw #686
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6ae5288
feat(breaking change): use stream on stats.bw
hacdias bcc3b0c
add some type checking
hacdias 30d5623
readable stream and pull stream on bandwidth stats
hacdias 9cc8af5
fix bw pull stream
hacdias 062ce4c
Bump interface-ipfs-core version
hacdias File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,36 @@ | ||
'use strict' | ||
|
||
const toPull = require('stream-to-pull-stream') | ||
const pull = require('pull-stream') | ||
const transformChunk = require('./bw-util') | ||
const deferred = require('pull-defer') | ||
|
||
const transform = () => (read) => (abort, cb) => { | ||
read(abort, (err, data) => { | ||
console.log(data) | ||
if (err) return cb(err) | ||
cb(null, transformChunk(data)) | ||
}) | ||
} | ||
|
||
module.exports = (send) => { | ||
return (hash, opts) => { | ||
opts = opts || {} | ||
|
||
const p = deferred.through() | ||
|
||
send({ | ||
path: 'stats/bw', | ||
qs: opts | ||
}, (err, stream) => { | ||
if (err) { | ||
return p.end(err) | ||
} | ||
|
||
pull(toPull(stream), p) | ||
p.resolve(transform) | ||
}) | ||
|
||
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could be simply
pull(pull.map(transformChunk), p)
if I understand it correct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks :D