(chunk: Bytes)
| 401 | } |
| 402 | |
| 403 | decode(chunk: Bytes): string[] { |
| 404 | let text = this.decodeText(chunk); |
| 405 | |
| 406 | if (this.trailingCR) { |
| 407 | text = '\r' + text; |
| 408 | this.trailingCR = false; |
| 409 | } |
| 410 | if (text.endsWith('\r')) { |
| 411 | this.trailingCR = true; |
| 412 | text = text.slice(0, -1); |
| 413 | } |
| 414 | |
| 415 | if (!text) { |
| 416 | return []; |
| 417 | } |
| 418 | |
| 419 | const trailingNewline = LineDecoder.NEWLINE_CHARS.has(text[text.length - 1] || ''); |
| 420 | let lines = text.split(LineDecoder.NEWLINE_REGEXP); |
| 421 | |
| 422 | // if there is a trailing new line then the last entry will be an empty |
| 423 | // string which we don't care about |
| 424 | if (trailingNewline) { |
| 425 | lines.pop(); |
| 426 | } |
| 427 | |
| 428 | if (lines.length === 1 && !trailingNewline) { |
| 429 | this.buffer.push(lines[0]!); |
| 430 | return []; |
| 431 | } |
| 432 | |
| 433 | if (this.buffer.length > 0) { |
| 434 | lines = [this.buffer.join('') + lines[0], ...lines.slice(1)]; |
| 435 | this.buffer = []; |
| 436 | } |
| 437 | |
| 438 | if (!trailingNewline) { |
| 439 | this.buffer = [lines.pop() || '']; |
| 440 | } |
| 441 | |
| 442 | return lines; |
| 443 | } |
| 444 | |
| 445 | decodeText(bytes: Bytes): string { |
| 446 | if (bytes == null) return ''; |
no test coverage detected