1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-26 16:09:27 -05:00
denoland-deno/cli/js/copy_file.ts

30 lines
1,020 B
TypeScript
Raw Normal View History

2020-01-02 15:13:47 -05:00
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { sendSync, sendAsync } from "./dispatch_json.ts";
2018-10-14 16:29:50 -04:00
/** Copies the contents of a file to another by name synchronously.
2018-09-30 18:06:41 -04:00
* Creates a new file if target does not exists, and if target exists,
* overwrites original content of the target file.
2018-10-14 16:29:50 -04:00
*
2018-09-30 18:06:41 -04:00
* It would also copy the permission of the original file
* to the destination.
*
* Deno.copyFileSync("from.txt", "to.txt");
2018-09-30 18:06:41 -04:00
*/
export function copyFileSync(from: string, to: string): void {
2020-02-25 09:14:27 -05:00
sendSync("op_copy_file", { from, to });
2018-09-30 18:06:41 -04:00
}
2018-10-14 16:29:50 -04:00
/** Copies the contents of a file to another by name.
*
2018-09-30 18:06:41 -04:00
* Creates a new file if target does not exists, and if target exists,
* overwrites original content of the target file.
2018-10-14 16:29:50 -04:00
*
2018-09-30 18:06:41 -04:00
* It would also copy the permission of the original file
* to the destination.
*
* await Deno.copyFile("from.txt", "to.txt");
2018-09-30 18:06:41 -04:00
*/
export async function copyFile(from: string, to: string): Promise<void> {
2020-02-25 09:14:27 -05:00
await sendAsync("op_copy_file", { from, to });
2018-09-30 18:06:41 -04:00
}