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

Function writeTextFileSync

fs/unstable_write_text_file.ts:78–103  ·  view source on GitHub ↗
(
  path: string | URL,
  data: string,
  options?: WriteFileOptions,
)

Source from the content-addressed store, hash-verified

76 * @param options Options for writing files. See {@linkcode WriteFileOptions}.
77 */
78export function writeTextFileSync(
79 path: string | URL,
80 data: string,
81 options?: WriteFileOptions,
82): void {
83 if (isDeno) {
84 Deno.writeTextFileSync(path, data, { ...options });
85 } else {
86 const {
87 append = false,
88 create = true,
89 createNew = false,
90 mode,
91 } = options ?? {};
92
93 const flag = getWriteFsFlag({ append, create, createNew });
94 try {
95 getNodeFs().writeFileSync(path, data, { encoding: "utf-8", flag });
96 if (mode != null) {
97 getNodeFs().chmodSync(path, mode);
98 }
99 } catch (error) {
100 throw mapError(error);
101 }
102 }
103}

Callers 3

makeTempFileSyncFunction · 0.90

Calls 3

getWriteFsFlagFunction · 0.90
getNodeFsFunction · 0.90
mapErrorFunction · 0.90

Tested by

no test coverage detected