0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-10-31 09:14:20 -04:00
denoland-deno/js/mkdir.ts

50 lines
1.6 KiB
TypeScript
Raw Normal View History

2019-01-21 14:03:30 -05:00
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
2018-10-03 21:18:23 -04:00
import * as msg from "gen/msg_generated";
import * as flatbuffers from "./flatbuffers";
2018-09-10 05:48:36 -04:00
import * as dispatch from "./dispatch";
/** Creates a new directory with the specified path synchronously.
* If `recursive` is set to true, nested directories will be created (also known
* as "mkdir -p").
* `mode` sets permission bits (before umask) on UNIX and does nothing on
* Windows.
2018-09-10 05:48:36 -04:00
*
* Deno.mkdirSync("new_dir");
* Deno.mkdirSync("nested/directories", true);
2018-09-10 05:48:36 -04:00
*/
export function mkdirSync(path: string, recursive = false, mode = 0o777): void {
dispatch.sendSync(...req(path, recursive, mode));
2018-09-10 05:48:36 -04:00
}
/** Creates a new directory with the specified path.
* If `recursive` is set to true, nested directories will be created (also known
* as "mkdir -p").
* `mode` sets permission bits (before umask) on UNIX and does nothing on
* Windows.
2018-09-10 05:48:36 -04:00
*
* await Deno.mkdir("new_dir");
* await Deno.mkdir("nested/directories", true);
2018-09-10 05:48:36 -04:00
*/
export async function mkdir(
path: string,
recursive = false,
mode = 0o777
): Promise<void> {
await dispatch.sendAsync(...req(path, recursive, mode));
2018-09-10 05:48:36 -04:00
}
function req(
path: string,
recursive: boolean,
2018-09-10 05:48:36 -04:00
mode: number
2018-10-03 21:18:23 -04:00
): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] {
const builder = flatbuffers.createBuilder();
2018-09-10 05:48:36 -04:00
const path_ = builder.createString(path);
2018-10-03 21:18:23 -04:00
msg.Mkdir.startMkdir(builder);
msg.Mkdir.addPath(builder, path_);
msg.Mkdir.addRecursive(builder, recursive);
2018-10-03 21:18:23 -04:00
msg.Mkdir.addMode(builder, mode);
const inner = msg.Mkdir.endMkdir(builder);
return [builder, msg.Any.Mkdir, inner];
2018-09-10 05:48:36 -04:00
}