diff options
author | Thomas <tmashuang@gmail.com> | 2018-04-24 02:22:24 +0800 |
---|---|---|
committer | Thomas <tmashuang@gmail.com> | 2018-04-24 02:22:24 +0800 |
commit | 010092312998e90688e1bfb004eb55c67a337429 (patch) | |
tree | 93a174b2eb7074283d6e43bcc98bc1f2c7925d57 /app/scripts/lib/stream-utils.js | |
parent | ddece0cc11215b323df96287f39e6758aa559f77 (diff) | |
parent | 74c419f9b65841c2966d1fe3b7414bf11e09e0d8 (diff) | |
download | tangerine-wallet-browser-010092312998e90688e1bfb004eb55c67a337429.tar.gz tangerine-wallet-browser-010092312998e90688e1bfb004eb55c67a337429.tar.zst tangerine-wallet-browser-010092312998e90688e1bfb004eb55c67a337429.zip |
Merge branch 'master' into testing
Diffstat (limited to 'app/scripts/lib/stream-utils.js')
-rw-r--r-- | app/scripts/lib/stream-utils.js | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/app/scripts/lib/stream-utils.js b/app/scripts/lib/stream-utils.js index 8bb0b4f3c..3dbc064b5 100644 --- a/app/scripts/lib/stream-utils.js +++ b/app/scripts/lib/stream-utils.js @@ -8,20 +8,34 @@ module.exports = { setupMultiplex: setupMultiplex, } +/** + * Returns a stream transform that parses JSON strings passing through + * @return {stream.Transform} + */ function jsonParseStream () { - return Through.obj(function (serialized, encoding, cb) { + return Through.obj(function (serialized, _, cb) { this.push(JSON.parse(serialized)) cb() }) } +/** + * Returns a stream transform that calls {@code JSON.stringify} + * on objects passing through + * @return {stream.Transform} the stream transform + */ function jsonStringifyStream () { - return Through.obj(function (obj, encoding, cb) { + return Through.obj(function (obj, _, cb) { this.push(JSON.stringify(obj)) cb() }) } +/** + * Sets up stream multiplexing for the given stream + * @param {any} connectionStream - the stream to mux + * @return {stream.Stream} the multiplexed stream + */ function setupMultiplex (connectionStream) { const mux = new ObjectMultiplex() pump( |