(buffer: Buffer)
| 28 | * @param buffer A buffer to use for detecting encoding if system detection fails. |
| 29 | */ |
| 30 | export function getCachedEncodingForBuffer(buffer: Buffer): string { |
| 31 | // Cache system encoding detection since it's system-wide |
| 32 | if (cachedSystemEncoding === undefined) { |
| 33 | cachedSystemEncoding = getSystemEncoding(); |
| 34 | } |
| 35 | |
| 36 | // If we have a cached system encoding, use it |
| 37 | if (cachedSystemEncoding) { |
| 38 | return cachedSystemEncoding; |
| 39 | } |
| 40 | |
| 41 | // Otherwise, detect from this specific buffer (don't cache this result) |
| 42 | return detectEncodingFromBuffer(buffer) || 'utf-8'; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Detects the system encoding based on the platform. |
no test coverage detected