1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-23 07:44:48 -05:00
denoland-deno/js/rename.ts

42 lines
1.5 KiB
TypeScript
Raw Normal View History

2018-09-12 11:44:58 -04:00
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
2018-10-03 21:18:23 -04:00
import * as msg from "gen/msg_generated";
import * as flatbuffers from "./flatbuffers";
2018-09-12 11:44:58 -04:00
import * as dispatch from "./dispatch";
2018-10-14 16:29:50 -04:00
/** Synchronously renames (moves) `oldpath` to `newpath`. If `newpath` already
* exists and is not a directory, `renameSync()` replaces it. OS-specific
* restrictions may apply when `oldpath` and `newpath` are in different
* directories.
2018-09-12 11:44:58 -04:00
*
2018-10-14 16:29:50 -04:00
* import { renameSync } from "deno";
* renameSync("old/path", "new/path");
2018-09-12 11:44:58 -04:00
*/
export function renameSync(oldpath: string, newpath: string): void {
dispatch.sendSync(...req(oldpath, newpath));
}
2018-10-14 16:29:50 -04:00
/** Renames (moves) `oldpath` to `newpath`. If `newpath` already exists and is
* not a directory, `rename()` replaces it. OS-specific restrictions may apply
* when `oldpath` and `newpath` are in different directories.
2018-09-12 11:44:58 -04:00
*
2018-10-14 16:29:50 -04:00
* import { rename } from "deno";
* await rename("old/path", "new/path");
2018-09-12 11:44:58 -04:00
*/
export async function rename(oldpath: string, newpath: string): Promise<void> {
await dispatch.sendAsync(...req(oldpath, newpath));
}
function req(
oldpath: string,
newpath: string
2018-10-03 21:18:23 -04:00
): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] {
const builder = flatbuffers.createBuilder();
2018-09-12 11:44:58 -04:00
const oldpath_ = builder.createString(oldpath);
const newpath_ = builder.createString(newpath);
2018-10-03 21:18:23 -04:00
msg.Rename.startRename(builder);
msg.Rename.addOldpath(builder, oldpath_);
msg.Rename.addNewpath(builder, newpath_);
const inner = msg.Rename.endRename(builder);
return [builder, msg.Any.Rename, inner];
2018-09-12 11:44:58 -04:00
}