2019-01-01 19:58:40 -05:00
|
|
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
2019-08-21 20:42:48 -04:00
|
|
|
import { sendSync, sendAsync, msg, flatbuffers } from "./dispatch_flatbuffers";
|
2018-09-30 18:06:41 -04:00
|
|
|
|
2019-03-09 12:30:38 -05:00
|
|
|
function req(
|
|
|
|
from: string,
|
|
|
|
to: string
|
|
|
|
): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] {
|
|
|
|
const builder = flatbuffers.createBuilder();
|
|
|
|
const from_ = builder.createString(from);
|
|
|
|
const to_ = builder.createString(to);
|
2019-04-07 20:51:43 -04:00
|
|
|
const inner = msg.CopyFile.createCopyFile(builder, from_, to_);
|
2019-03-09 12:30:38 -05:00
|
|
|
return [builder, msg.Any.CopyFile, inner];
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
*
|
2019-02-12 10:08:56 -05:00
|
|
|
* Deno.copyFileSync("from.txt", "to.txt");
|
2018-09-30 18:06:41 -04:00
|
|
|
*/
|
|
|
|
export function copyFileSync(from: string, to: string): void {
|
2019-08-21 20:42:48 -04:00
|
|
|
sendSync(...req(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.
|
|
|
|
*
|
2019-02-12 10:08:56 -05:00
|
|
|
* 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> {
|
2019-08-21 20:42:48 -04:00
|
|
|
await sendAsync(...req(from, to));
|
2018-09-30 18:06:41 -04:00
|
|
|
}
|