(stream, options, callback = noop)
| 244 | // @param {options} options The options object |
| 245 | // @param {function} callback The callback function |
| 246 | const parseStream = (stream, options, callback = noop) => { |
| 247 | if (typeof options === 'function') { |
| 248 | callback = options; |
| 249 | options = {}; |
| 250 | } |
| 251 | |
| 252 | const emitter = new events.EventEmitter(); |
| 253 | |
| 254 | try { |
| 255 | const results = []; |
| 256 | stream |
| 257 | .pipe(new GCodeLineStream(options)) |
| 258 | .on('data', (data) => { |
| 259 | emitter.emit('data', data); |
| 260 | results.push(data); |
| 261 | }) |
| 262 | .on('end', () => { |
| 263 | emitter.emit('end', results); |
| 264 | callback && callback(null, results); |
| 265 | }) |
| 266 | .on('error', callback); |
| 267 | } catch (err) { |
| 268 | callback(err); |
| 269 | } |
| 270 | |
| 271 | return emitter; |
| 272 | }; |
| 273 | |
| 274 | // @param {string} file The G-code path name |
| 275 | // @param {options} options The options object |
no outgoing calls
no test coverage detected