UNPKG

566 BJavaScriptView Raw
1'use strict'
2const EventEmitter = require('events');
3const StreamSnitch = require('stream-snitch');
4
5const BEGIN_READY_RE = /{begin(\d+)}([\s\S]*){ready(\d+)}/
6
7class BeginReadySnitch extends EventEmitter {
8 constructor(stream) {
9 super()
10 const snitch = new StreamSnitch(BEGIN_READY_RE)
11 snitch.on('match', (data) => {
12 this.emit('data', {
13 commandNumber: parseInt(data[1], 10),
14 data: data[2].trim(),
15 })
16 })
17 stream.pipe(snitch)
18 }
19}
20
21module.exports = BeginReadySnitch;