summaryrefslogtreecommitdiff
path: root/js/chmod.ts
diff options
context:
space:
mode:
authorKevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com>2018-10-26 13:01:45 -0700
committerRyan Dahl <ry@tinyclouds.org>2018-10-26 13:01:45 -0700
commita99aaf5def7d2e223f8303e7a00bd9de4d3efdf6 (patch)
tree21297f1d3d2ebbc2f61b113996110bb86a7b97a5 /js/chmod.ts
parentfe97217fa8483cb2e4f75a63b3a50e9df1c233b7 (diff)
Add chmod/chmodSync on unix (and fix Cargo.toml) (#1088)
Initial implementation by Srijan Reddy (@srijanreddy98, #672).
Diffstat (limited to 'js/chmod.ts')
-rw-r--r--js/chmod.ts36
1 files changed, 36 insertions, 0 deletions
diff --git a/js/chmod.ts b/js/chmod.ts
new file mode 100644
index 000000000..385e6345d
--- /dev/null
+++ b/js/chmod.ts
@@ -0,0 +1,36 @@
+// Copyright 2018 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.
+ *
+ * import { chmodSync } from "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.
+ *
+ * import { chmod } from "deno";
+ * await 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];
+}