Created
March 10, 2014 04:42
-
-
Save modeswitch/9459595 to your computer and use it in GitHub Desktop.
FileSystem interface generation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var methods = [ | |
'open', | |
'close', | |
'mkdir', | |
'rmdir', | |
'stat', | |
'fstat', | |
'link', | |
'unlink', | |
'read', | |
'readFile', | |
'write', | |
'writeFile', | |
'appendFile', | |
'exists', | |
'lseek', | |
'readdir', | |
'rename', | |
'readlink', | |
'symlink', | |
'lstat', | |
'truncate', | |
'ftruncate', | |
'utimes', | |
'futimes', | |
'setxattr', | |
'getxattr', | |
'fsetxattr', | |
'fgetxattr', | |
'removexattr', | |
'fremovexattr', | |
]; | |
function FileSystemInterface(obj, call) { | |
methods.forEach(function(method_name) { | |
this[method_name] = call.bind(this, method_name); | |
}.bind(this)); | |
} | |
var FS = new FileSystemInterface(fs, function(method_name) { | |
callback = maybeCallback(arguments[arguments.length - 1]); | |
var fs = this; | |
var error = fs.queueOrRun( | |
function() { | |
var context = fs.provider.openReadWriteContext(); | |
function complete() { | |
context.close(); | |
callback.apply(fs, arguments); | |
} | |
var args = [fs, context]; | |
args.concat(Array.prototype.slice.call(arguments, 1, arguments.length - 1)); | |
args.concat(complete); | |
fs[method_name].apply(args); | |
} | |
); | |
if(error) callback(error); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment