MCPcopy Create free account
hub / github.com/effect-app/libs / tempFile_

Function tempFile_

packages/infra/src/fileUtil.ts:43–63  ·  view source on GitHub ↗
(
  folder: string,
  prefix: string,
  data: Data,
  options?: FileOptions
)

Source from the content-addressed store, hash-verified

41 | BufferEncoding
42 | null
43export function tempFile_(
44 folder: string,
45 prefix: string,
46 data: Data,
47 options?: FileOptions
48) {
49 return Effect.flatMap(
50 Effect
51 .sync(() => path.join(os.tmpdir(), folder, `${prefix}-` + crypto.randomUUID())),
52 (fp) =>
53 Effect.acquireRelease(
54 Effect
55 .map(
56 Effect
57 .tryPromise(() => fs.writeFile(fp, data, options)),
58 (_) => fp
59 ),
60 (p) => Effect.promise(() => fs.unlink(p))
61 )
62 )
63}
64
65/**
66 * Safe write file to .tmp and then rename

Callers 1

tempFileFunction · 0.85

Calls 3

syncMethod · 0.80
joinMethod · 0.80
mapMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…