-
-
Notifications
You must be signed in to change notification settings - Fork 525
/
index.js
38 lines (33 loc) · 858 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
const { KafkaJSNotImplemented } = require('../../../errors')
const COMPRESSION_CODEC_MASK = 0x07
const Types = {
None: 0,
GZIP: 1,
Snappy: 2,
LZ4: 3,
ZSTD: 4,
}
const Codecs = {
[Types.GZIP]: () => require('./gzip'),
[Types.Snappy]: () => {
throw new KafkaJSNotImplemented('Snappy compression not implemented')
},
[Types.LZ4]: () => {
throw new KafkaJSNotImplemented('LZ4 compression not implemented')
},
[Types.ZSTD]: () => {
throw new KafkaJSNotImplemented('ZSTD compression not implemented')
},
}
const lookupCodec = type => (Codecs[type] ? Codecs[type]() : null)
const lookupCodecByAttributes = attributes => {
const codec = Codecs[attributes & COMPRESSION_CODEC_MASK]
return codec ? codec() : null
}
module.exports = {
Types,
Codecs,
lookupCodec,
lookupCodecByAttributes,
COMPRESSION_CODEC_MASK,
}