-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { mkdir } from "node:fs/promises"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { assertEquals } from "@std/assert"; | ||
import { test } from "@cross/test"; | ||
import { mktempdir, rmdir } from "./mod.ts"; | ||
import { isDir } from "../stat/mod.ts"; | ||
|
||
test("mktempdir creates a temporary directory", async () => { | ||
const tempDir = await mktempdir(); | ||
try { | ||
assertEquals(await isDir(tempDir), true); | ||
} finally { | ||
await rmdir(tempDir); | ||
} | ||
}); | ||
|
||
test("mktempdir creates a temporary directory with prefix", async () => { | ||
const tempDir = await mktempdir("test"); | ||
assertEquals(tempDir.includes("test-"), true); | ||
try { | ||
assertEquals(await isDir(tempDir), true); | ||
} finally { | ||
await rmdir(tempDir); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { dir } from "@cross/dir"; | ||
import { generate } from "@std/uuid/v1"; | ||
import { join } from "@std/path"; | ||
import { mkdir } from "./mkdir.ts"; | ||
|
||
/** | ||
* Creates a uniquely named directory under the system temp directory. | ||
* | ||
* @param prefix - An optional prefix for the generated directory name. | ||
* @returns The full path to the newly created temporary directory. | ||
* @throws On error | ||
*/ | ||
export async function mktempdir(prefix?: string): Promise<string> { | ||
const tempBaseDir = await dir("tmp"); | ||
let uuid = generate(); | ||
if (prefix) { | ||
uuid = `${prefix}-${uuid}`; | ||
} | ||
const tempDirPath = join(tempBaseDir, uuid.toString()); | ||
await mkdir(tempDirPath, { recursive: true }); | ||
return tempDirPath; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
export * from "./unlink.ts"; | ||
export * from "./mkdir.ts"; | ||
export * from "./rmdir.ts"; | ||
export * from "./mktempdir.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { rmdir } from "node:fs/promises"; |