Created
May 22, 2014 16:01
-
-
Save lance/de1abf2a0b63a7f21a5b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// When vertx file system functions mirror node file system | |
// functions, we can use this high-order function to | |
// delegate. It passes args unmolested into the vertx | |
// API, and provides a possibly converted return value | |
// (or callback arg). If the type/order of function | |
// arguments don't match up between vertx and node, then | |
// don't use this function. | |
function delegateFunction(f, converter) { | |
return function() { | |
if (!converter) { converter = function(result) { return result; }; } | |
var args = Array.prototype.slice.call(arguments); | |
var last = args[args.length - 1]; | |
if (typeof last === 'function') { | |
args[args.length - 1] = nodyn.vertxHandler(last, converter); | |
} | |
return converter(f.apply(system, args)); | |
}; | |
} | |
FS.truncate = delegateFunction(system.truncate); | |
FS.truncateSync = delegateFunction(system.truncateSync); | |
FS.ftruncate = delegateFunction(system.truncate); | |
FS.ftruncateSync = delegateFunction(system.truncateSync); | |
FS.rename = delegateFunction(system.move); | |
FS.renameSync = delegateFunction(system.moveSync); | |
FS.readdir = delegateFunction(system.readDir, nodyn.arrayConverter); | |
FS.readdirSync = delegateFunction(system.readDirSync, nodyn.arrayConverter); | |
FS.chown = delegateFunction(system.chown); | |
FS.fchown = delegateFunction(system.chown); | |
FS.lchown = delegateFunction(system.chown); | |
FS.chownSync = delegateFunction(system.chownSync); | |
FS.fchownSync = delegateFunction(system.chownSync); | |
FS.lchownSync = delegateFunction(system.chownSync); | |
FS.readlink = delegateFunction(system.readSymlink); | |
FS.readlinkSync = delegateFunction(system.readSymlinkSync); | |
FS.unlink = delegateFunction(system.unlink); | |
FS.unlinkSync = delegateFunction(system.unlinkSync); | |
FS.rmdir = delegateFunction(system.delete); | |
FS.rmdirSync = delegateFunction(system.deleteSync); | |
FS.stat = delegateFunction(system.props, function(result) { return new Stat(result); } ); | |
FS.stat = delegateFunction(system.propsSync, function(result) { return new Stat(result); } ); | |
FS.stat = delegateFunction(system.lprops, function(result) { return new Stat(result); } ); | |
FS.stat = delegateFunction(system.lpropsSync, function(result) { return new Stat(result); } ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment