From e23f33de7bdf2a20aa72ad222dfbea75c7332a7c Mon Sep 17 00:00:00 2001 From: Ali Hasani Date: Sun, 12 Apr 2020 23:04:16 +0430 Subject: add copyFile & copyFileSync to std/node/fs (#4726) --- std/node/_fs/_fs_copy.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 std/node/_fs/_fs_copy.ts (limited to 'std/node/_fs/_fs_copy.ts') diff --git a/std/node/_fs/_fs_copy.ts b/std/node/_fs/_fs_copy.ts new file mode 100644 index 000000000..4fdc63008 --- /dev/null +++ b/std/node/_fs/_fs_copy.ts @@ -0,0 +1,32 @@ +// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. + +import { CallbackWithError } from "./_fs_common.ts"; + +export function copyFile( + source: string, + destination: string, + callback: CallbackWithError +): void { + new Promise(async (resolve, reject) => { + try { + await Deno.copyFile(source, destination); + resolve(); + } catch (err) { + reject(err); + } + }) + .then(() => { + callback(); + }) + .catch((err) => { + callback(err); + }); +} + +export function copyFileSync(source: string, destination: string): void { + try { + Deno.copyFileSync(source, destination); + } catch (err) { + throw err; + } +} -- cgit v1.2.3