level-filesystem
Full implementation of the fs module on top of leveldb (except sync ops)
npm install level-filesystem
Current status
All async methods in the fs module are supported and well tested (including links!)
β fs.rmdir(path, callback)
β fs.mkdir(path, [mode], callback)
β fs.readdir(path, callback)
β fs.stat(path, callback)
β fs.exists(path, callback)
β fs.chmod(path, mode, callback)
β fs.chown(path, uid, gid, callback)
β fs.rename(oldPath, newPath, callback)
β fs.realpath(path, [cache], callback)
β fs.readFile(filename, [options], callback)
β fs.writeFile(filename, data, [options], callback)
β fs.appendFile(filename, data, [options], callback)
β fs.utimes(path, atime, mtime, callback)
β fs.unlink(path, callback)
β fs.createReadStream(path, [options])
β fs.createWriteStream(path, [options])
β fs.truncate(path, len, callback)
β fs.watchFile(filename, [options], listener)
β fs.unwatchFile(filename, [listener])
β fs.watch(filename, [options], [listener])
β fs.fsync(fd, callback)
β fs.write(fd, buffer, offset, length, position, callback)
β fs.read(fd, buffer, offset, length, position, callback)
β fs.close(fd, callback)
β fs.open(path, flags, [mode], callback)
β fs.futimes(fd, atime, mtime, callback)
β fs.fchown(fd, uid, gid, callback)
β fs.ftruncate(fd, len, callback)
β fs.fchmod(fd, mode, callback)
β fs.fstat(fd, callback)
β fs.lchown(path, uid, gid, callback)
β fs.lchmod(path, mode, callback)
β fs.symlink(srcpath, dstpath, [type], callback)
β fs.lstat(path, callback)
β fs.readlink(path, callback)
β fs.link(srcpath, dstpath, callback)
If any of the methods do not behave as you would expect please add a test case or open an issue.
Usage
var filesystem = require('level-filesystem');
var fs = filesystem(db); // where db is a levelup instance
// use fs as you would node cores fs module
fs.mkdir('/hello', function(err) {
if (err) throw err;
fs.writeFile('/hello/world.txt', 'world', function(err) {
if (err) throw err;
fs.readFile('/hello/world.txt', 'utf-8', function(err, data) {
console.log(data);
});
});
});
Errors
When you get an error in a callback it is similar to what you get in Node core fs.
fs.mkdir('/hello', function() {
fs.mkdir('/hello', function(err) {
console.log(err); // err.code is EEXIST
});
});
fs.mkdir('/hello', function() {
fs.readFile('/hello', function(err) {
console.log(err); // err.code is EISDIR
});
});
...
Relation to level-fs
The goal of this module is similar to level-fs and is probably gonna end up as a PR to that module. I decided to make this as a standalone module (for now) since adding proper directory support to level-fs turned out to be non-trivial (more or a less a complete rewrite).
License
MIT