Skip to content

Commit

Permalink
fix: browser compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
KlausTrainer committed Jan 22, 2017
1 parent 56a6249 commit d3b3346
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
30 changes: 20 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -22,7 +22,7 @@
"author": "Klaus Trainer <[email protected]>",
"license": "MIT",
"devDependencies": {
"semantic-release": "^6.3.6",
"semantic-release": "^6.3.2",
"standard": "^8.0.0",
"tape": "^4.6.0"
},
Expand Down

0 comments on commit d3b3346

Please sign in to comment.