Open madarche opened 10 years ago
Hello @madarche,
I use fs2
in most cases, and would recommend to do that, but it's also important to see that fs2
is not only about returning promises, there are many other things that it offers over native fs
.
Also it's important to note one limitation in the way how functions are promisified in fs2
. They won't auto-resolve input arguments as function generated bypromisify
do, e.g. following works great:
var readFile = promisify(fs.readFile), writeFile = promisify(writeFile);
writeFile(__filename + '.copy', readFile(__filename)).done();
but following won't:
var readFile = fs2.readFile, writeFile = fs2.writeFile
writeFile(__filename + '.copy', readFile(__filename)).done(); // Fail
With fs2 functions, you need to do:
readFile(__filename)(function (content) {
return writeFile(__filename + '.copy', content);
}).done();
I plan to fix that, and then indeed it'll be good idea to mention it in a doc.
Thanks very much @medikoo. I'm now following fs2 closely to know when that happens.
Cheers!
Hello,
Happy and grateful user of deferred I have just discovered https://github.com/medikoo/fs2
Is it recommended to use a) var readFile = require('fs2').readFile; or b) var readFile = promisify(fs.readFile, 1); ?
Thanks!