diff options
Diffstat (limited to 'lib/fs.js')
-rw-r--r-- | lib/fs.js | 66 |
1 files changed, 37 insertions, 29 deletions
@@ -37,18 +37,18 @@ var EventEmitter = require('events').EventEmitter; var kMinPoolSpace = 128; var kPoolSize = 40 * 1024; -var O_APPEND = constants.O_APPEND || 0; -var O_CREAT = constants.O_CREAT || 0; +var O_APPEND = constants.O_APPEND || 0; +var O_CREAT = constants.O_CREAT || 0; var O_DIRECTORY = constants.O_DIRECTORY || 0; -var O_EXCL = constants.O_EXCL || 0; -var O_NOCTTY = constants.O_NOCTTY || 0; -var O_NOFOLLOW = constants.O_NOFOLLOW || 0; -var O_RDONLY = constants.O_RDONLY || 0; -var O_RDWR = constants.O_RDWR || 0; -var O_SYMLINK = constants.O_SYMLINK || 0; -var O_SYNC = constants.O_SYNC || 0; -var O_TRUNC = constants.O_TRUNC || 0; -var O_WRONLY = constants.O_WRONLY || 0; +var O_EXCL = constants.O_EXCL || 0; +var O_NOCTTY = constants.O_NOCTTY || 0; +var O_NOFOLLOW = constants.O_NOFOLLOW || 0; +var O_RDONLY = constants.O_RDONLY || 0; +var O_RDWR = constants.O_RDWR || 0; +var O_SYMLINK = constants.O_SYMLINK || 0; +var O_SYNC = constants.O_SYNC || 0; +var O_TRUNC = constants.O_TRUNC || 0; +var O_WRONLY = constants.O_WRONLY || 0; fs.Stats = binding.Stats; @@ -199,10 +199,10 @@ function stringToFlags(flag) { } switch (flag) { - case 'r' : return O_RDONLY; + case 'r' : return O_RDONLY; case 'r+' : return O_RDWR; - case 'w' : return O_TRUNC | O_CREAT | O_WRONLY; + case 'w' : return O_TRUNC | O_CREAT | O_WRONLY; case 'wx' : // fall through case 'xw' : return O_TRUNC | O_CREAT | O_WRONLY | O_EXCL; @@ -210,7 +210,7 @@ function stringToFlags(flag) { case 'wx+': // fall through case 'xw+': return O_TRUNC | O_CREAT | O_RDWR | O_EXCL; - case 'a' : return O_APPEND | O_CREAT | O_WRONLY; + case 'a' : return O_APPEND | O_CREAT | O_WRONLY; case 'ax' : // fall through case 'xa' : return O_APPEND | O_CREAT | O_WRONLY | O_EXCL; @@ -262,8 +262,10 @@ fs.open = function(path, flags, mode, callback) { mode = modeNum(mode, 438 /*=0666*/); - binding.open(pathModule._makeLong(path), stringToFlags(flags), mode, - callback); + binding.open(pathModule._makeLong(path), + stringToFlags(flags), + mode, + callback); }; fs.openSync = function(path, flags, mode) { @@ -363,13 +365,14 @@ fs.writeSync = function(fd, buffer, offset, length, position) { }; fs.rename = function(oldPath, newPath, callback) { - binding.rename(pathModule._makeLong(oldPath), pathModule._makeLong(newPath), - callback || noop); + binding.rename(pathModule._makeLong(oldPath), + pathModule._makeLong(newPath), + callback || noop); }; fs.renameSync = function(oldPath, newPath) { return binding.rename(pathModule._makeLong(oldPath), - pathModule._makeLong(newPath)); + pathModule._makeLong(newPath)); }; fs.truncate = function(fd, len, callback) { @@ -407,12 +410,12 @@ fs.fsyncSync = function(fd) { fs.mkdir = function(path, mode, callback) { if (typeof mode === 'function') callback = mode; binding.mkdir(pathModule._makeLong(path), modeNum(mode, 511 /*=0777*/), - callback || noop); + callback || noop); }; fs.mkdirSync = function(path, mode) { return binding.mkdir(pathModule._makeLong(path), - modeNum(mode, 511 /*=0777*/)); + modeNum(mode, 511 /*=0777*/)); }; fs.sendfile = function(outFd, inFd, inOffset, length, callback) { @@ -468,22 +471,23 @@ fs.symlink = function(destination, path, type_, callback) { var callback_ = arguments[arguments.length - 1]; callback = (typeof(callback_) == 'function' ? callback_ : null); binding.symlink(pathModule._makeLong(destination), - pathModule._makeLong(path), type, callback); + pathModule._makeLong(path), type, callback); }; fs.symlinkSync = function(destination, path, type) { return binding.symlink(pathModule._makeLong(destination), - pathModule._makeLong(path), type); + pathModule._makeLong(path), type); }; fs.link = function(srcpath, dstpath, callback) { - binding.link(pathModule._makeLong(srcpath), pathModule._makeLong(dstpath), - callback || noop); + binding.link(pathModule._makeLong(srcpath), + pathModule._makeLong(dstpath), + callback || noop); }; fs.linkSync = function(srcpath, dstpath) { return binding.link(pathModule._makeLong(srcpath), - pathModule._makeLong(dstpath)); + pathModule._makeLong(dstpath)); }; fs.unlink = function(path, callback) { @@ -637,7 +641,10 @@ function writeAll(fd, buffer, offset, length, position, callback) { if (written === length) { fs.close(fd, callback); } else { - writeAll(fd, buffer, offset + written, length - written, position + written, callback); + offset += written; + length -= written; + position += written; + writeAll(fd, buffer, offset, length, position, callback); } } }); @@ -1462,7 +1469,8 @@ function SyncWriteStream(fd) { this.fd = fd; this.writable = true; this.readable = false; -}; +} + util.inherits(SyncWriteStream, Stream); @@ -1481,7 +1489,7 @@ SyncWriteStream.prototype.write = function(data, arg1, arg2) { } else if (typeof arg1 === 'function') { cb = arg1; } else { - throw new Error("bad arg"); + throw new Error('bad arg'); } } |