summaryrefslogtreecommitdiff
path: root/cli/js/make_temp_dir.ts
diff options
context:
space:
mode:
Diffstat (limited to 'cli/js/make_temp_dir.ts')
-rw-r--r--cli/js/make_temp_dir.ts35
1 files changed, 35 insertions, 0 deletions
diff --git a/cli/js/make_temp_dir.ts b/cli/js/make_temp_dir.ts
new file mode 100644
index 000000000..14494b5da
--- /dev/null
+++ b/cli/js/make_temp_dir.ts
@@ -0,0 +1,35 @@
+// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
+import { sendSync, sendAsync } from "./dispatch_json.ts";
+import * as dispatch from "./dispatch.ts";
+
+export interface MakeTempDirOptions {
+ dir?: string;
+ prefix?: string;
+ suffix?: string;
+}
+
+/** makeTempDirSync is the synchronous version of `makeTempDir`.
+ *
+ * const tempDirName0 = Deno.makeTempDirSync();
+ * const tempDirName1 = Deno.makeTempDirSync({ prefix: 'my_temp' });
+ */
+export function makeTempDirSync(options: MakeTempDirOptions = {}): string {
+ return sendSync(dispatch.OP_MAKE_TEMP_DIR, options);
+}
+
+/** makeTempDir creates a new temporary directory in the directory `dir`, its
+ * name beginning with `prefix` and ending with `suffix`.
+ * It returns the full path to the newly created directory.
+ * If `dir` is unspecified, tempDir uses the default directory for temporary
+ * files. Multiple programs calling tempDir simultaneously will not choose the
+ * same directory. It is the caller's responsibility to remove the directory
+ * when no longer needed.
+ *
+ * const tempDirName0 = await Deno.makeTempDir();
+ * const tempDirName1 = await Deno.makeTempDir({ prefix: 'my_temp' });
+ */
+export async function makeTempDir(
+ options: MakeTempDirOptions = {}
+): Promise<string> {
+ return await sendAsync(dispatch.OP_MAKE_TEMP_DIR, options);
+}