1 | 'use strict'
|
2 |
|
3 | const stream = require('../lib/destroyable-stream')
|
4 |
|
5 | class SystemInfo {
|
6 | constructor (systemInfo) {
|
7 | this.clock = systemInfo.clock
|
8 |
|
9 | const hrtime = this.clock.hrtime
|
10 | const unixtime = this.clock.unixtime
|
11 |
|
12 |
|
13 | const hrtimeMS = (hrtime[0] * 1e3 + hrtime[1] * 1e-6)
|
14 | this.clockOffset = unixtime - hrtimeMS
|
15 | }
|
16 | }
|
17 |
|
18 | class SystemInfoDecoder extends stream.Transform {
|
19 | constructor () {
|
20 | super({
|
21 | readableObjectMode: true,
|
22 | writableObjectMode: false
|
23 | })
|
24 |
|
25 | this._data = []
|
26 | }
|
27 |
|
28 | _transform (chunk, encoding, callback) {
|
29 | this._data.push(chunk)
|
30 | callback(null)
|
31 | }
|
32 |
|
33 | _flush (callback) {
|
34 | this.push(
|
35 | new SystemInfo(JSON.parse(Buffer.concat(this._data).toString()))
|
36 | )
|
37 | callback(null)
|
38 | }
|
39 | }
|
40 | module.exports = SystemInfoDecoder
|