MCPcopy Create free account
hub / github.com/denoland/std / writeTextFile

Function writeTextFile

fs/unstable_write_text_file.ts:27–57  ·  view source on GitHub ↗
(
  path: string | URL,
  data: string | ReadableStream<string>,
  options?: WriteFileOptions,
)

Source from the content-addressed store, hash-verified

25 * @param options Options for writing files. See {@linkcode WriteFileOptions}.
26 */
27export async function writeTextFile(
28 path: string | URL,
29 data: string | ReadableStream<string>,
30 options?: WriteFileOptions,
31): Promise<void> {
32 if (isDeno) {
33 await Deno.writeTextFile(path, data, { ...options });
34 } else {
35 const {
36 append = false,
37 create = true,
38 createNew = false,
39 mode,
40 signal,
41 } = options ?? {};
42
43 const flag = getWriteFsFlag({ append, create, createNew });
44 try {
45 await getNodeFs().promises.writeFile(path, data, {
46 encoding: "utf-8",
47 flag,
48 signal,
49 });
50 if (mode != null) {
51 await getNodeFs().promises.chmod(path, mode);
52 }
53 } catch (error) {
54 throw mapError(error);
55 }
56 }
57}
58
59/**
60 * Synchronously write string `data` to the given `path`, by default creating

Callers 3

makeTempFileFunction · 0.90

Calls 3

getWriteFsFlagFunction · 0.90
getNodeFsFunction · 0.90
mapErrorFunction · 0.90

Tested by

no test coverage detected