summaryrefslogtreecommitdiff
path: root/js/chmod.ts
blob: 2a9b1b01db3fa25e19160ee3ed1dc22754c14809 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import * as msg from "gen/msg_generated";
import * as flatbuffers from "./flatbuffers";
import * as dispatch from "./dispatch";

/** 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 {
  dispatch.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 dispatch.sendAsync(...req(path, mode));
}

function req(
  path: string,
  mode: number
): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] {
  const builder = flatbuffers.createBuilder();
  const path_ = builder.createString(path);
  msg.Chmod.startChmod(builder);
  msg.Chmod.addPath(builder, path_);
  msg.Chmod.addMode(builder, mode);
  const inner = msg.Chmod.endChmod(builder);
  return [builder, msg.Any.Chmod, inner];
}