You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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).
FWIW, CoW is not supported yet. There is a PR to add it to libuv but I haven't landed it yet because I have yet to see it work on any of the CI machines.
Ponyfillfs-copy-file can be used for copying files. In node.js < v8.5.0 it copies files with help of streams and for v8.5.0 and next versions it uses native implementation of fs.copyFile.
@coderaiser - That looks like a useful module. Although, technically that's not a ponyfill as ponyfills never use the native API (as per the document you linked to) 😃
Activity
eljefedelrodeodeljefe commentedon May 9, 2017
Likely needs libuv implementation. Related: libuv/libuv#925
Daniel15 commentedon Jun 6, 2017
Also see some of the attempts at using native copy calls in Yarn:
yarnpkg/yarn#3290 which uses https://github.com/sciolist/fcopy (Unix via a native module)
yarnpkg/yarn#2960 (Win32 via node-ffi)
richardlau commentedon Sep 8, 2017
fs.copyFilewas added by #15034.cjihrig commentedon Sep 8, 2017
FWIW, CoW is not supported yet. There is a PR to add it to libuv but I haven't landed it yet because I have yet to see it work on any of the CI machines.
richardlau commentedon Sep 8, 2017
Let's keep this open then.
coderaiser commentedon Sep 13, 2017
Ponyfill fs-copy-file can be used for copying files. In
node.js<v8.5.0it copies files with help of streams and forv8.5.0and next versions it uses native implementation offs.copyFile.Daniel15 commentedon Oct 4, 2017
@coderaiser - That looks like a useful module. Although, technically that's not a ponyfill as ponyfills never use the native API (as per the document you linked to) 😃
cjihrig commentedon Apr 6, 2018
Forgot to link it, but this is closed in a16d88d.