mirror of
https://github.com/lancedb/lancedb.git
synced 2025-12-23 05:19:58 +00:00
17 lines
457 B
TypeScript
17 lines
457 B
TypeScript
// SPDX-License-Identifier: Apache-2.0
|
|
// SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
|
import * as fs from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import * as path from "node:path";
|
|
|
|
export async function withTempDirectory(
|
|
fn: (tempDir: string) => Promise<void>,
|
|
) {
|
|
const tmpDirPath = fs.mkdtempSync(path.join(tmpdir(), "temp-dir-"));
|
|
try {
|
|
await fn(tmpDirPath);
|
|
} finally {
|
|
fs.rmSync(tmpDirPath, { recursive: true });
|
|
}
|
|
}
|