Function
tempFile_
(
folder: string,
prefix: string,
data: Data,
options?: FileOptions
)
Source from the content-addressed store, hash-verified
| 41 | | BufferEncoding |
| 42 | | null |
| 43 | export 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 |
Tested by
no test coverage detected
Used in the wild real call sites across dependent graphs
searching dependent graphs…