2019-01-21 14:03:30 -05:00
|
|
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
2019-08-26 10:18:42 -04:00
|
|
|
import { sendSync, sendAsync } from "./dispatch_json";
|
|
|
|
import * as dispatch from "./dispatch";
|
2018-09-12 22:04:45 -04:00
|
|
|
|
|
|
|
export interface MakeTempDirOptions {
|
|
|
|
dir?: string;
|
|
|
|
prefix?: string;
|
|
|
|
suffix?: string;
|
|
|
|
}
|
|
|
|
|
2019-03-09 12:30:38 -05:00
|
|
|
/** makeTempDirSync is the synchronous version of `makeTempDir`.
|
|
|
|
*
|
|
|
|
* const tempDirName0 = Deno.makeTempDirSync();
|
|
|
|
* const tempDirName1 = Deno.makeTempDirSync({ prefix: 'my_temp' });
|
|
|
|
*/
|
|
|
|
export function makeTempDirSync(options: MakeTempDirOptions = {}): string {
|
2019-08-26 10:18:42 -04:00
|
|
|
return sendSync(dispatch.OP_MAKE_TEMP_DIR, options);
|
2019-03-09 12:30:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/** 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> {
|
2019-08-26 10:18:42 -04:00
|
|
|
return await sendAsync(dispatch.OP_MAKE_TEMP_DIR, options);
|
2019-03-09 12:30:38 -05:00
|
|
|
}
|