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

Function writeFile

fs/unstable_write_file.ts:32–58  ·  view source on GitHub ↗
(
  path: string | URL,
  data: Uint8Array | ReadableStream<Uint8Array>,
  options?: WriteFileOptions,
)

Source from the content-addressed store, hash-verified

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

Calls 3

getWriteFsFlagFunction · 0.90
getNodeFsFunction · 0.90
mapErrorFunction · 0.90

Tested by

no test coverage detected