News for hackers. Stuff that matters.
Re:Node v8.5.0 by Johnny_Brahms on Wednesday September 13, 2017 @01:36AM (#15235814)
Wiuldnt implementing those be trivial? They are hardly going to be "too slow" like file copy might be, and with the JS love of small packages this should already be a solved problem.
Re:Node v8.5.0 by jaredklewis on Wednesday September 13, 2017 @08:12AM (#15237491)
There most certainly are already packages that do this, as well as countless projects with a util.js file implementing a hodgepodge of such functions that are standards in many languages. But as a programmer I would say my biggest complaint against JS is the miserably small standard library. Thus every project has its own set of dependencies that have their own APIs. Two projects from different JS ecosystems are as different as projects in different languages altogether.

There are trade offs to be sure, but I prefer the languages (and in this case platforms) that have batteries included.

Re:Node v8.5.0 by amelius on Wednesday September 13, 2017 @08:56AM (#15237783)
> Thus every project has its own set of dependencies that have their own APIs.

Yes, this means that if your project depends on ten other projects, and all ten projects implement their own copy-file routine, your project will end up with ten copy-file routines.

Re:Node v8.5.0 by thom_nic on Wednesday September 13, 2017 @09:10AM (#15237878)
As Larry Wall said, "Easy things should be easy."

When working on a project and you need to copy something for the first time, you shouldn't have to do:

  * Ok I need to copy...  What npm package does that again?
  * search NPM for copy
  * figure out which package is "best"
  * npm i some-copy-package
  * require("some-copy-packge")
  * do thing
The first 4 steps should be unnecessary.
Re:Node v8.5.0 by tkone on Wednesday September 13, 2017 @11:49AM (#15239431)
or just

fs.createReadStream('file.txt').pipe(fs.createWriteStream('new-file.txt'))

Streams are too slow you say?

fs.writeFileSync('new-file.txt', fs.readFileSync('file.txt'))

I've never had a problem with no explicit copy, but I am very happy it has been added...

Re:Node v8.5.0 by pitaj on Wednesday September 13, 2017 @04:02PM (#15242050)
For the first one, what about error handling? You have to handle errors by both the read and write stream, and also most people will want a callback when everything is done, so you have to handle that event, too.
Re:Node v8.5.0 by VeejayRampay on Wednesday September 13, 2017 @11:54AM (#15239501)
Are streams really considered "slow"? Would your second example be faster in practice for most files?
Re:Node v8.5.0 by wruza on Wednesday September 13, 2017 @10:21AM (#15238529)
I'll buy it if you remove just third step.
Re:Node v8.5.0 by dchest on Wednesday September 13, 2017 @01:44PM (#15240670)
I'm not sure how fs.copyFile is implemented, but file copying is not the same as reading the contents of file and then writing it into another file, which is easy to implement. There are also permissions, extended attributes, access control lists, etc. And then there are CoW file systems such as APFL that can optimize copying referencing the original data instead of physically copying it.

In macOS libc there's a copyfile(3) function: https://developer.apple.com/legacy/library/documentation/Dar...