diff options
author | Mani Maghsoudlou <manidlou@gmail.com> | 2018-09-03 17:22:30 -0700 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-09-04 11:57:04 -0400 |
commit | 641e3d404dfeb8f70ae0eb6c59b898b9f44742a1 (patch) | |
tree | 7611e133745846dbef3cd11437bad5d3f06a7e52 /js/os.ts | |
parent | b2b4299e3b499c50bd11059854e3dcb4df2e2891 (diff) |
Implement renameSync
Diffstat (limited to 'js/os.ts')
-rw-r--r-- | js/os.ts | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -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); +} |