Skip to content

Provide a way to create clone/CoW copies #12902

Description

@candrews

Currently, copying files is implemented by reading the data of the source file and writing it to the new file, see fs-extra's implementation of copy. The problem is that this approach doesn't allow the OS to optimize file copying (such as by using direct disk-to-disk copy if it's available), nor does it allow the (optional or by default) use of reflink/CoW.

I'm specifically interested in making CoW (which is already available on some *nix file systems, including btrfs and zfs) available to nodejs.

IMHO, nodejs should add an fs.copy function (just like what fs-extra already does) which is implemented using the OS native file copying syscall. It should have an optional option parameter that allows specifying the copy should use CoW (if available), just like how cp --reflink=auto from coreutils works on Linux.

Note that this would be particularly benefit for cases where files are copied often - particularly big files. I'm thinking that this improvement would substantially benefit package managers (npm, yarn, etc).

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues requesting new Node.js features.fsIssues and PRs related to file-system APIs and the fs module.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions