diff options
author | Dan <danjm.com@gmail.com> | 2018-04-20 23:53:17 +0800 |
---|---|---|
committer | Dan <danjm.com@gmail.com> | 2018-04-20 23:53:17 +0800 |
commit | 71b0de76ffdbdfc0ae696a009d5ee34971541e0b (patch) | |
tree | d0f2f4fd891a20eb7cbe5e7bfb82a375286fbc43 /app/scripts/lib/stream-utils.js | |
parent | 9f12c26d44a0d78f28af25056857b993f80bbd95 (diff) | |
parent | 00efcf9e8ba34d448b628c98d32ad12d5be2ffc9 (diff) | |
download | tangerine-wallet-browser-71b0de76ffdbdfc0ae696a009d5ee34971541e0b.tar.gz tangerine-wallet-browser-71b0de76ffdbdfc0ae696a009d5ee34971541e0b.tar.zst tangerine-wallet-browser-71b0de76ffdbdfc0ae696a009d5ee34971541e0b.zip |
Merge branch 'master' into dm-docs-2
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( |