MCPcopy Create free account
hub / github.com/Effect-TS/effect / writeFile

Function writeFile

packages/platform/deno/src/DenoFileSystem.ts:499–521  ·  view source on GitHub ↗
(path, data, options)

Source from the content-addressed store, hash-verified

497 )
498
499const writeFile: FileSystem.FileSystem["writeFile"] = (path, data, options) => {
500 const flag = options?.flag ?? "w"
501 if (options?.mode === undefined && (flag === "w" || flag === "wx" || flag === "a" || flag === "ax")) {
502 return tryPromise("writeFile", path, (signal) =>
503 Deno.writeFile(path, data, {
504 append: flag.startsWith("a"),
505 createNew: flag.includes("x"),
506 signal
507 }))
508 }
509 return Effect.acquireUseRelease(
510 tryPromise("writeFile", path, () => Deno.open(path, openOptions(flag, options?.mode))),
511 (file) =>
512 new FileImpl(file, flag.startsWith("a")).writeAll(data).pipe(
513 Effect.mapError((error) =>
514 error.reason._tag !== "BadArgument"
515 ? PlatformError.systemError({ ...error.reason, method: "writeFile", pathOrDescriptor: path })
516 : error
517 )
518 ),
519 (file) => close(file, "writeFile", path)
520 )
521}
522
523const makeFileSystem = Effect.map(Effect.serviceOption(FileSystem.WatchBackend), (backend) =>
524 FileSystem.make({

Callers

nothing calls this directly

Calls 6

openOptionsFunction · 0.85
tryPromiseFunction · 0.70
closeFunction · 0.70
pipeMethod · 0.65
openMethod · 0.45
writeAllMethod · 0.45

Tested by

no test coverage detected