-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (38 loc) · 898 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
32
33
34
35
36
37
38
39
40
41
42
43
44
'use strict';
const SnappyJS = require('snappyjs');
const Hp = require('hemera-plugin');
const pluginName = require('./package.json').name;
module.exports = Hp(hemeraSnappy, {
hemera: '>=3',
name: pluginName,
options: {},
dependencies: []
});
function hemeraSnappy(hemera, opts, done) {
function uncompress(msg) {
try {
return {
value: SnappyJS.uncompress(msg)
};
} catch (error) {
return {
error
};
}
}
function compress(msg) {
try {
return {
value: SnappyJS.compress(Buffer.from(msg))
};
} catch (error) {
return {
error
};
}
}
hemera.encoder.add(compress);
// first uncompress then decode
hemera.decoder.first(uncompress);
done();
}