mirror of
https://github.com/denoland/deno.git
synced 2025-02-25 14:42:51 -05:00

Fixes https://github.com/denoland/deno/issues/20803 Fixes https://github.com/denoland/deno/issues/21723 Performance: copying a 48GiB rust `target` folder (recursive) | Platform | `deno` | `node v21.5` | Improvement | | -------- | ------- | ------- | ------- | | macOS (APFS) | 3.1secs | 127.99 secs | **42x** | | Windows | 18.3secs | 67.2secs | **3.8x** | Copying files with varying sizes: 
41 lines
1 KiB
JavaScript
41 lines
1 KiB
JavaScript
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
|
|
// deno-lint-ignore-file prefer-primordials
|
|
|
|
import {
|
|
getValidatedPath,
|
|
validateCpOptions,
|
|
} from "ext:deno_node/internal/fs/utils.mjs";
|
|
import { promisify } from "ext:deno_node/internal/util.mjs";
|
|
|
|
const core = globalThis.__bootstrap.core;
|
|
const ops = core.ops;
|
|
const { op_node_cp } = core.ensureFastOps();
|
|
|
|
export function cpSync(src, dest, options) {
|
|
validateCpOptions(options);
|
|
const srcPath = getValidatedPath(src, "src");
|
|
const destPath = getValidatedPath(dest, "dest");
|
|
|
|
ops.op_node_cp_sync(srcPath, destPath);
|
|
}
|
|
|
|
export function cp(src, dest, options, callback) {
|
|
if (typeof options === "function") {
|
|
callback = options;
|
|
options = {};
|
|
}
|
|
validateCpOptions(options);
|
|
const srcPath = getValidatedPath(src, "src");
|
|
const destPath = getValidatedPath(dest, "dest");
|
|
|
|
op_node_cp(
|
|
srcPath,
|
|
destPath,
|
|
).then(
|
|
(res) => callback(null, res),
|
|
(err) => callback(err, null),
|
|
);
|
|
}
|
|
|
|
export const cpPromise = promisify(cp);
|