From 90b90dc46161b6eadfc71b37bad41d9f4cd61d5c Mon Sep 17 00:00:00 2001 From: Arnaud Bailly Date: Tue, 2 Dec 2025 08:41:54 +0100 Subject: introduce test (with a bug) using LevelDB --- pbt/ts/src/fs.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 pbt/ts/src/fs.ts (limited to 'pbt/ts/src/fs.ts') 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 = (fn: (filepath: string) => A) => + withTempDir(dir => fn(path.join(dir, 'file'))); + +export const withTempDir = async (fn: (path: string) => A) => { + const dir = await mkdtemp((await realpath(tmpdir())) + path.sep); + try { + return await fn(dir); + } finally { + fs.rmdir(dir, () => {}); + } +}; -- cgit v1.3.1