Hacker News new | ask | show | jobs
by thom_nic 3206 days ago
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.
2 comments

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...

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.
Are streams really considered "slow"? Would your second example be faster in practice for most files?
I'll buy it if you remove just third step.