deno/js/copy_file.ts

43 lines
1.4 KiB
TypeScript
Raw Normal View History

2019-01-02 00:58:40 +00:00
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import * as msg from "gen/cli/msg_generated";
import * as flatbuffers from "./flatbuffers";
2018-09-30 22:06:41 +00:00
import * as dispatch from "./dispatch";
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);
const inner = msg.CopyFile.createCopyFile(builder, from_, to_);
return [builder, msg.Any.CopyFile, inner];
}
2018-10-14 20:29:50 +00:00
/** Copies the contents of a file to another by name synchronously.
2018-09-30 22:06:41 +00:00
* Creates a new file if target does not exists, and if target exists,
* overwrites original content of the target file.
2018-10-14 20:29:50 +00:00
*
2018-09-30 22:06:41 +00:00
* It would also copy the permission of the original file
* to the destination.
*
* Deno.copyFileSync("from.txt", "to.txt");
2018-09-30 22:06:41 +00:00
*/
export function copyFileSync(from: string, to: string): void {
dispatch.sendSync(...req(from, to));
}
2018-10-14 20:29:50 +00:00
/** Copies the contents of a file to another by name.
*
2018-09-30 22:06:41 +00:00
* Creates a new file if target does not exists, and if target exists,
* overwrites original content of the target file.
2018-10-14 20:29:50 +00:00
*
2018-09-30 22:06:41 +00:00
* It would also copy the permission of the original file
* to the destination.
*
* await Deno.copyFile("from.txt", "to.txt");
2018-09-30 22:06:41 +00:00
*/
export async function copyFile(from: string, to: string): Promise<void> {
await dispatch.sendAsync(...req(from, to));
}