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

Function writeFile

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

Source from the content-addressed store, hash-verified

440 )
441
442const writeFile: FileSystem.FileSystem["writeFile"] = (path, data, options) => {
443 const flag = options?.flag ?? "w"
444 if (flag === "w" || flag === "wx" || flag === "a" || flag === "ax") {
445 return tryPromise("writeFile", path, (signal) =>
446 Deno.writeFile(path, data, {
447 append: flag.startsWith("a"),
448 createNew: flag.includes("x"),
449 ...(options?.mode === undefined ? {} : { mode: options.mode }),
450 signal
451 }))
452 }
453 return Effect.acquireUseRelease(
454 tryPromise("writeFile", path, () => Deno.open(path, openOptions(flag, options?.mode))),
455 (file) =>
456 new FileImpl(file, flag.startsWith("a")).writeAll(data).pipe(
457 Effect.mapError((error) =>
458 error.reason._tag !== "BadArgument"
459 ? PlatformError.systemError({ ...error.reason, method: "writeFile", pathOrDescriptor: path })
460 : error
461 )
462 ),
463 (file) => close(file, "writeFile", path)
464 )
465}
466
467const makeFileSystem = Effect.map(Effect.serviceOption(FileSystem.WatchBackend), (backend) =>
468 FileSystem.make({

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected