-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
31 lines (28 loc) · 1.12 KB
/
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
const path = require('path')
const Encoder = require(path.join(__dirname, 'lib', 'encoder'))
const PygmyLogReader = require(path.join(__dirname, 'lib', 'reader'))
const PygmyLogWriter = require(path.join(__dirname, 'lib', 'writer'))
let ProtobufJSEncoder
function _requireProtobufEncoder () {
if (ProtobufJSEncoder) return ProtobufJSEncoder
let resolves = false
try {
resolves = require.resolve('protobufjs')
} catch (err) {
throw new Error('default encoder protobufjs requires the `protobufjs` module available to work')
}
if (!resolves) throw new Error('default encoder protobufjs requires the `protobufjs` module available to work')
ProtobufJSEncoder = require(path.join(__dirname, 'lib', 'encoders', 'protobufjs'))
return ProtobufJSEncoder
}
module.exports = {
Encoder,
createReadStream: function (options = {}) {
if (!options.encoder) options.encoder = _requireProtobufEncoder()
return new PygmyLogReader(options)
},
createWriteStream: function (headers, options = {}) {
if (!options.encoder) options.encoder = _requireProtobufEncoder()
return new PygmyLogWriter(headers, options)
}
}