| 648 | } |
| 649 | |
| 650 | function decodeTextBuffer(buffer) { |
| 651 | const meta = detectTextMeta(buffer) |
| 652 | const body = buffer.slice(meta.bomLength) |
| 653 | if (meta.encoding === 'utf16le') { |
| 654 | return { text: body.toString('utf16le'), meta } |
| 655 | } |
| 656 | if (meta.encoding === 'utf16be') { |
| 657 | const swapped = Buffer.from(body) |
| 658 | if (swapped.length >= 2) swapped.swap16() |
| 659 | return { text: swapped.toString('utf16le'), meta } |
| 660 | } |
| 661 | return { text: body.toString('utf8'), meta } |
| 662 | } |
| 663 | |
| 664 | function detectEol(text) { |
| 665 | if (typeof text !== 'string' || text.length === 0) return '\n' |