summaryrefslogtreecommitdiff
path: root/js/os.ts
diff options
context:
space:
mode:
authorMani Maghsoudlou <manidlou@gmail.com>2018-09-03 17:22:30 -0700
committerRyan Dahl <ry@tinyclouds.org>2018-09-04 11:57:04 -0400
commit641e3d404dfeb8f70ae0eb6c59b898b9f44742a1 (patch)
tree7611e133745846dbef3cd11437bad5d3f06a7e52 /js/os.ts
parentb2b4299e3b499c50bd11059854e3dcb4df2e2891 (diff)
Implement renameSync
Diffstat (limited to 'js/os.ts')
-rw-r--r--js/os.ts26
1 files changed, 26 insertions, 0 deletions
diff --git a/js/os.ts b/js/os.ts
index cca121874..5cb1d1fdb 100644
--- a/js/os.ts
+++ b/js/os.ts
@@ -336,3 +336,29 @@ export function writeFileSync(
const msg = fbs.WriteFileSync.endWriteFileSync(builder);
send(builder, fbs.Any.WriteFileSync, msg);
}
+
+/**
+ * Renames (moves) oldpath to newpath.
+ * import { renameSync } from "deno";
+ * const oldpath = 'from/path';
+ * const newpath = 'to/path';
+ *
+ * renameSync(oldpath, newpath);
+ */
+export function renameSync(oldpath: string, newpath: string): void {
+ /* Ideally we could write:
+ const res = send({
+ command: fbs.Command.RENAME_SYNC,
+ renameOldPath: oldpath,
+ renameNewPath: newpath
+ });
+ */
+ const builder = new flatbuffers.Builder();
+ const _oldpath = builder.createString(oldpath);
+ const _newpath = builder.createString(newpath);
+ fbs.RenameSync.startRenameSync(builder);
+ fbs.RenameSync.addOldpath(builder, _oldpath);
+ fbs.RenameSync.addNewpath(builder, _newpath);
+ const msg = fbs.RenameSync.endRenameSync(builder);
+ send(builder, fbs.Any.RenameSync, msg);
+}