1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-14 16:33:45 -05:00
denoland-deno/js/mkdir.ts

38 lines
1.1 KiB
TypeScript
Raw Normal View History

2018-09-10 05:48:36 -04:00
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
2018-10-03 21:18:23 -04:00
import * as msg from "gen/msg_generated";
2018-09-10 05:48:36 -04:00
import { flatbuffers } from "flatbuffers";
import * as dispatch from "./dispatch";
/**
* Creates a new directory with the specified path and permission synchronously.
*
* import { mkdirSync } from "deno";
* mkdirSync("new_dir");
*/
export function mkdirSync(path: string, mode = 0o777): void {
dispatch.sendSync(...req(path, mode));
}
/**
* Creates a new directory with the specified path and permission.
*
* import { mkdir } from "deno";
* await mkdir("new_dir");
*/
export async function mkdir(path: string, mode = 0o777): Promise<void> {
await dispatch.sendAsync(...req(path, mode));
}
function req(
path: string,
mode: number
2018-10-03 21:18:23 -04:00
): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] {
2018-09-10 05:48:36 -04:00
const builder = new flatbuffers.Builder();
const path_ = builder.createString(path);
2018-10-03 21:18:23 -04:00
msg.Mkdir.startMkdir(builder);
msg.Mkdir.addPath(builder, path_);
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
}