(chunk: Bytes)
| 384 | } |
| 385 | |
| 386 | decode(chunk: Bytes): string[] { |
| 387 | let text = this.decodeText(chunk); |
| 388 | |
| 389 | if (this.trailingCR) { |
| 390 | text = '\r' + text; |
| 391 | this.trailingCR = false; |
| 392 | } |
| 393 | if (text.endsWith('\r')) { |
| 394 | this.trailingCR = true; |
| 395 | text = text.slice(0, -1); |
| 396 | } |
| 397 | |
| 398 | if (!text) { |
| 399 | return []; |
| 400 | } |
| 401 | |
| 402 | const trailingNewline = LineDecoder.NEWLINE_CHARS.has( |
| 403 | text[text.length - 1] || '' |
| 404 | ); |
| 405 | let lines = text.split(LineDecoder.NEWLINE_REGEXP); |
| 406 | |
| 407 | // if there is a trailing new line then the last entry will be an empty |
| 408 | // string which we don't care about |
| 409 | if (trailingNewline) { |
| 410 | lines.pop(); |
| 411 | } |
| 412 | |
| 413 | if (lines.length === 1 && !trailingNewline) { |
| 414 | this.buffer.push(lines[0]!); |
| 415 | return []; |
| 416 | } |
| 417 | |
| 418 | if (this.buffer.length > 0) { |
| 419 | lines = [this.buffer.join('') + lines[0], ...lines.slice(1)]; |
| 420 | this.buffer = []; |
| 421 | } |
| 422 | |
| 423 | if (!trailingNewline) { |
| 424 | this.buffer = [lines.pop() || '']; |
| 425 | } |
| 426 | |
| 427 | return lines; |
| 428 | } |
| 429 | |
| 430 | decodeText(bytes: Bytes): string { |
| 431 | if (bytes == null) return ''; |
no test coverage detected