MCPcopy Index your code
hub / github.com/cncjs/gcode-parser / _transform

Method _transform

src/index.js:350–396  ·  view source on GitHub ↗
(chunk, encoding, next)

Source from the content-addressed store, hash-verified

348 }
349
350 _transform(chunk, encoding, next) {
351 // decode binary chunks as UTF-8
352 encoding = encoding || 'utf8';
353
354 if (Buffer.isBuffer(chunk)) {
355 if (encoding === 'buffer') {
356 encoding = 'utf8';
357 }
358 chunk = chunk.toString(encoding);
359 }
360
361 this.lineBuffer += chunk;
362
363 if (!containsLineEnd(chunk)) {
364 next();
365 return;
366 }
367
368 const lines = this.lineBuffer.match(this.re);
369 if (!lines || lines.length === 0) {
370 next();
371 return;
372 }
373
374 // Do not split CRLF which spans chunks
375 if (this.state.lastChunkEndedWithCR && lines[0] === '\n') {
376 lines.shift();
377 }
378
379 this.state.lastChunkEndedWithCR = (this.lineBuffer[this.lineBuffer.length - 1] === '\r');
380
381 if ((this.lineBuffer[this.lineBuffer.length - 1] === '\r') ||
382 (this.lineBuffer[this.lineBuffer.length - 1] === '\n')) {
383 this.lineBuffer = '';
384 } else {
385 const line = lines.pop() || '';
386 this.lineBuffer = line;
387 }
388
389 iterateArray(lines, { batchSize: this.options.batchSize }, (line) => {
390 line = line.trim();
391 if (line.length > 0) {
392 const result = parseLine(line, this.options);
393 this.push(result);
394 }
395 }, next);
396 }
397
398 _flush(done) {
399 if (this.lineBuffer) {

Callers

nothing calls this directly

Calls 1

iterateArrayFunction · 0.85

Tested by

no test coverage detected