(absolute: string, displayPath: string)
| 374 | } |
| 375 | |
| 376 | async function readUtf8Text(absolute: string, displayPath: string): Promise<string> { |
| 377 | const bytes = await readFile(absolute); |
| 378 | let content: string; |
| 379 | try { |
| 380 | content = new TextDecoder("utf-8", { fatal: true }).decode(bytes); |
| 381 | } catch { |
| 382 | throw patchError(`file is not valid UTF-8 text: ${displayPath}`); |
| 383 | } |
| 384 | if (content.includes("\0")) throw patchError(`file appears to be binary: ${displayPath}`); |
| 385 | return content; |
| 386 | } |
| 387 | |
| 388 | async function writeTextFile(destination: string, content: string, mode?: number): Promise<void> { |
| 389 | await mkdir(dirname(destination), { recursive: true }); |
no test coverage detected