2020-01-02 15:13:47 -05:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2020-03-09 19:22:15 -04:00
|
|
|
import { sendSync, sendAsync } from "../dispatch_json.ts";
|
2019-03-09 12:30:38 -05:00
|
|
|
|
2020-03-11 16:14:23 -04:00
|
|
|
type MkdirArgs = { path: string; recursive: boolean; mode?: number };
|
|
|
|
|
2020-04-09 11:15:56 -04:00
|
|
|
function mkdirArgs(path: string, options?: MkdirOptions): MkdirArgs {
|
2020-03-11 16:14:23 -04:00
|
|
|
const args: MkdirArgs = { path, recursive: false };
|
2020-04-09 11:15:56 -04:00
|
|
|
if (options) {
|
|
|
|
if (typeof options.recursive == "boolean") {
|
|
|
|
args.recursive = options.recursive;
|
2020-01-07 14:14:33 -05:00
|
|
|
}
|
2020-04-09 11:15:56 -04:00
|
|
|
if (options.mode) {
|
|
|
|
args.mode = options.mode;
|
2020-01-07 14:14:33 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return args;
|
|
|
|
}
|
|
|
|
|
2020-03-02 15:24:42 -05:00
|
|
|
export interface MkdirOptions {
|
2020-01-07 14:14:33 -05:00
|
|
|
recursive?: boolean;
|
|
|
|
mode?: number;
|
|
|
|
}
|
|
|
|
|
2020-04-09 11:15:56 -04:00
|
|
|
export function mkdirSync(path: string, options?: MkdirOptions): void {
|
|
|
|
sendSync("op_mkdir", mkdirArgs(path, options));
|
2018-09-10 05:48:36 -04:00
|
|
|
}
|
|
|
|
|
2019-01-17 23:39:06 -05:00
|
|
|
export async function mkdir(
|
|
|
|
path: string,
|
2020-04-09 11:15:56 -04:00
|
|
|
options?: MkdirOptions
|
2019-01-17 23:39:06 -05:00
|
|
|
): Promise<void> {
|
2020-04-09 11:15:56 -04:00
|
|
|
await sendAsync("op_mkdir", mkdirArgs(path, options));
|
2018-09-10 05:48:36 -04:00
|
|
|
}
|