Node core fs
wrapped functions that return thunks for co.
$ npm install co-fs
Use all the regular async fs functions without callback hell:
var json = yield fs.readFile('package.json', 'utf8')
var files = yield fs.readdir('/tmp')
MIT
nodejs core fs module thunk wrappers for "co"
Node core fs
wrapped functions that return thunks for co.
$ npm install co-fs
Use all the regular async fs functions without callback hell:
var json = yield fs.readFile('package.json', 'utf8')
var files = yield fs.readdir('/tmp')
MIT
Hi,
Your package.json depends on thunkify v0.0.1. Latest version of thunkify is however 2.1.2.
You can always verify dependencies versions with npm outdated
It's time to update all stuff. Does not work with async await.
No thunkify. There is a native Promise object!
https://github.com/isaacs/node-graceful-fs
there doesn't seem to be a downside. we can also make it a peer dependency and do
try {
fs = require('graceful-fs')
} catch (err) {
fs = require('fs')
}
https://github.com/fundon/co-fs-plus
var filenames = yield fs.walk('/opt/boxen'); // returns an array of filenames.
I don't know if it has to do with the library itself, but it's failing on require('co-fs') because lchown is undefined on fs for node-v0.11.6
Error: fs.lchown does not exist
Since we are including co-fs
as var fs;
, and the this module exposes createReadStream
, but not createWriteStream
, it would be nice to be able to expose that last one, too.
I try to rename a file using:
yield fs.rename(src, dest);
Yet, I got the following error:
TypeError: You may only yield a function, promise, generator, array, or object, but the following object was passed: "undefined"
at next (/home/jpetitcolas/dev/xxx/node_modules/koa/node_modules/co/index.js:101:25)
at onFulfilled (/home/jpetitcolas/dev/xxx/node_modules/koa/node_modules/co/index.js:69:7)
fs.js:77
throw err; // Forgot a callback but don't know where? Use NODE_DEBUG=fs
^
Error: EXDEV, rename '/tmp/lazg2qxdek4kj4i/file.png'
I am using Koa 1.0.0 and co-fs 1.2.0. Any idea? :)
The version 1.1.1
on npm does not contain createReadStream
, whereas the repository code does. Should bump npm's version to 1.1.2
?
With this code
var cofsTest = function * () {
console.log("Unknown file", yield fs.exists('random.file'));
console.log("this file", yield * fs.exists(__filename));
return true;
};
var generator = cofsTest();
var genResult;
while (!(genResult = generator.next(genResult && genResult.value)).done);
console.log("Test", genResult.value);
I get this result
Unknown file function (done){
fs.stat(path, function(err, res){
done(null, !err);
});
}
this file function (done){
fs.stat(path, function(err, res){
done(null, !err);
});
}
Test true
Where I would have expected something like
Unknown file false
this file true
Test true
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.