From d3b334630772aa3c58e85f1a9a815928e4ff9791 Mon Sep 17 00:00:00 2001 From: Klaus Trainer Date: Sun, 22 Jan 2017 01:03:02 +0100 Subject: [PATCH] fix: browser compatibility --- index.js | 30 ++++++++++++++++++++---------- package.json | 4 ++-- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index 1e6916e..74a29fb 100644 --- a/index.js +++ b/index.js @@ -3,29 +3,39 @@ var snappy = require('snappyjs') var msgpack = require('msgpack-lite') var lpStream = require('length-prefixed-stream') -var stream = require('stream') -var pumpify = require('pumpify') +var Transform = require('readable-stream/transform') -var snappyCompressStream = new stream.Transform({ +var msgpackEncodeStream = new Transform({ + objectMode: true, + transform: function (chunk, encoding, next) { + next(null, msgpack.encode(chunk)) + } +}) + +var msgpackDecodeStream = new Transform({ + objectMode: true, + transform: function (chunk, encoding, callback) { + callback(null, msgpack.decode(chunk)) + } +}) + +var snappyCompressStream = new Transform({ transform: function (chunk, encoding, next) { next(null, snappy.compress(chunk)) } }) -var snappyUncompressStream = new stream.Transform({ +var snappyUncompressStream = new Transform({ transform: function (chunk, encoding, callback) { callback(null, snappy.uncompress(chunk)) } }) exports.createEncodeStream = function SnappyMsgpackEncodeStream () { - return pumpify.obj( - pumpify.obj(msgpack.createEncodeStream(), snappyCompressStream), - lpStream.encode()) + msgpackEncodeStream.pipe(snappyCompressStream).pipe(lpStream.encode()) + return msgpackEncodeStream } exports.createDecodeStream = function SnappyMsgpackDecodeStream () { - return pumpify.obj( - pumpify.obj(lpStream.decode(), snappyUncompressStream), - msgpack.createDecodeStream()) + return lpStream.decode().pipe(snappyUncompressStream).pipe(msgpackDecodeStream) } diff --git a/package.json b/package.json index c64796f..f01289f 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "dependencies": { "length-prefixed-stream": "^1.5.1", "msgpack-lite": "^0.1.26", - "pumpify": "^1.3.5", + "readable-stream": "^2.2.2", "snappyjs": "^0.5.0" }, "keywords": [ @@ -22,7 +22,7 @@ "author": "Klaus Trainer ", "license": "MIT", "devDependencies": { - "semantic-release": "^6.3.6", + "semantic-release": "^6.3.2", "standard": "^8.0.0", "tape": "^4.6.0" },