-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
31 lines (24 loc) · 931 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
'use strict'
var pumpify = require('pumpify')
var through = require('through2')
var lpStream = require('length-prefixed-stream')
var msgpack = require('msgpack-lite')
var snappy = require('snappyjs')
module.exports.createEncodeStream = function SnappyMsgpackEncodeStream (stream) {
var msgEncode = through.obj(function (data, enc, next) {
next(null, msgpack.encode(data))
})
var snappyCompress = through.obj(function (data, enc, next) {
next(null, snappy.compress(data))
})
return pumpify.obj(msgEncode, snappyCompress, lpStream.encode())
}
module.exports.createDecodeStream = function SnappyMsgpackDecodeStream (stream) {
var msgDecode = through.obj(function (data, enc, next) {
next(null, msgpack.decode(data))
})
var snappyUncompress = through.obj(function (data, enc, next) {
next(null, snappy.uncompress(data))
})
return pumpify.obj(lpStream.decode(), snappyUncompress, msgDecode)
}