-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
24 additions
and
33 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,31 @@ | ||
'use strict' | ||
|
||
var snappy = require('snappyjs') | ||
var msgpack = require('msgpack-lite') | ||
var pumpify = require('pumpify') | ||
var through = require('through2') | ||
var lpStream = require('length-prefixed-stream') | ||
var Transform = require('readable-stream/transform') | ||
var msgpack = require('msgpack-lite') | ||
var snappy = require('snappyjs') | ||
|
||
var msgpackEncodeStream = new Transform({ | ||
objectMode: true, | ||
transform: function (chunk, encoding, next) { | ||
next(null, msgpack.encode(chunk)) | ||
} | ||
}) | ||
module.exports.createEncodeStream = function SnappyMsgpackEncodeStream (stream) { | ||
var msgEncode = through.obj(function (data, enc, next) { | ||
next(null, msgpack.encode(data)) | ||
}) | ||
|
||
var msgpackDecodeStream = new Transform({ | ||
objectMode: true, | ||
transform: function (chunk, encoding, callback) { | ||
callback(null, msgpack.decode(chunk)) | ||
} | ||
}) | ||
var snappyCompress = through.obj(function (data, enc, next) { | ||
next(null, snappy.compress(data)) | ||
}) | ||
|
||
var snappyCompressStream = new Transform({ | ||
transform: function (chunk, encoding, next) { | ||
next(null, snappy.compress(chunk)) | ||
} | ||
}) | ||
return pumpify.obj(msgEncode, snappyCompress, lpStream.encode()) | ||
} | ||
|
||
var snappyUncompressStream = new Transform({ | ||
transform: function (chunk, encoding, callback) { | ||
callback(null, snappy.uncompress(chunk)) | ||
} | ||
}) | ||
module.exports.createDecodeStream = function SnappyMsgpackDecodeStream (stream) { | ||
var msgDecode = through.obj(function (data, enc, next) { | ||
next(null, msgpack.decode(data)) | ||
}) | ||
|
||
exports.createEncodeStream = function SnappyMsgpackEncodeStream () { | ||
msgpackEncodeStream.pipe(snappyCompressStream).pipe(lpStream.encode()) | ||
return msgpackEncodeStream | ||
} | ||
var snappyUncompress = through.obj(function (data, enc, next) { | ||
next(null, snappy.uncompress(data)) | ||
}) | ||
|
||
exports.createDecodeStream = function SnappyMsgpackDecodeStream () { | ||
return lpStream.decode().pipe(snappyUncompressStream).pipe(msgpackDecodeStream) | ||
return pumpify.obj(lpStream.decode(), snappyUncompress, msgDecode) | ||
} |
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