0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-10-31 09:14:20 -04:00
denoland-deno/js/chmod.ts
Ryan Dahl bdc97b3976
Organize dispatch a bit (#2796)
Just some clean up reorganization around flatbuffer/minimal dispatch
code. This is prep for adding a JSON dispatcher.
2019-08-21 20:42:48 -04:00

29 lines
946 B
TypeScript

// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import { sendSync, sendAsync, msg, flatbuffers } from "./dispatch_flatbuffers";
function req(
path: string,
mode: number
): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] {
const builder = flatbuffers.createBuilder();
const path_ = builder.createString(path);
const inner = msg.Chmod.createChmod(builder, path_, mode);
return [builder, msg.Any.Chmod, inner];
}
/** Changes the permission of a specific file/directory of specified path
* synchronously.
*
* Deno.chmodSync("/path/to/file", 0o666);
*/
export function chmodSync(path: string, mode: number): void {
sendSync(...req(path, mode));
}
/** Changes the permission of a specific file/directory of specified path.
*
* await Deno.chmod("/path/to/file", 0o666);
*/
export async function chmod(path: string, mode: number): Promise<void> {
await sendAsync(...req(path, mode));
}