diff options
| author | Arnaud Bailly <arnaud@pankzsoft.com> | 2025-12-02 08:41:54 +0100 |
|---|---|---|
| committer | Arnaud Bailly <arnaud@pankzsoft.com> | 2025-12-02 08:51:13 +0100 |
| commit | 90b90dc46161b6eadfc71b37bad41d9f4cd61d5c (patch) | |
| tree | c13872efa624ba4db0c3283dc344dfd1a6d331a2 /pbt/ts/src/fs.ts | |
| parent | 83d63d6d3248666ebb23c7c29f0c58775f277482 (diff) | |
| download | lambda-nantes-90b90dc46161b6eadfc71b37bad41d9f4cd61d5c.tar.gz | |
introduce test (with a bug) using LevelDB
Diffstat (limited to 'pbt/ts/src/fs.ts')
| -rw-r--r-- | pbt/ts/src/fs.ts | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/pbt/ts/src/fs.ts b/pbt/ts/src/fs.ts new file mode 100644 index 0000000..133c8fd --- /dev/null +++ b/pbt/ts/src/fs.ts @@ -0,0 +1,16 @@ +import {mkdtemp, realpath} from 'fs/promises'; +import {tmpdir} from 'os'; +import path = require('path'); +import fs = require('fs'); + +export const withTempFile = <A>(fn: (filepath: string) => A) => + withTempDir(dir => fn(path.join(dir, 'file'))); + +export const withTempDir = async <A>(fn: (path: string) => A) => { + const dir = await mkdtemp((await realpath(tmpdir())) + path.sep); + try { + return await fn(dir); + } finally { + fs.rmdir(dir, () => {}); + } +}; |
