MCPcopy
hub / github.com/Waishnav/devspace / readUtf8Text

Function readUtf8Text

src/apply-patch.ts:376–386  ·  view source on GitHub ↗
(absolute: string, displayPath: string)

Source from the content-addressed store, hash-verified

374}
375
376async 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
388async function writeTextFile(destination: string, content: string, mode?: number): Promise<void> {
389 await mkdir(dirname(destination), { recursive: true });

Callers 2

readRequiredTextFileFunction · 0.85
readOptionalTextFileFunction · 0.85

Calls 1

patchErrorFunction · 0.85

Tested by

no test coverage detected