@ -171,8 +171,21 @@ fs.closeSync = function(fd) {
return binding . close ( fd ) ;
} ;
fs . open = function ( path , flags , mode_ , callback ) {
var mode = ( typeof ( mode_ ) == 'number' ? mode_ : 0666 ) ;
function modeNum ( m , def ) {
switch ( typeof m ) {
case 'number' : return m ;
case 'string' : return parseInt ( m , 8 ) ;
default :
if ( def ) {
return modeNum ( def ) ;
} else {
return undefined ;
}
}
}
fs . open = function ( path , flags , mode , callback ) {
mode = modeNum ( mode , '0666' ) ;
var callback_ = arguments [ arguments . length - 1 ] ;
var callback = ( typeof ( callback_ ) == 'function' ? callback_ : null ) ;
@ -180,7 +193,7 @@ fs.open = function(path, flags, mode_, callback) {
} ;
fs . openSync = function ( path , flags , mode ) {
if ( mode === undefined ) { mode = 0666 ; }
mode = modeNum ( mode , '0666' ) ;
return binding . open ( path , stringToFlags ( flags ) , mode ) ;
} ;
@ -306,11 +319,11 @@ fs.fsyncSync = function(fd) {
} ;
fs . mkdir = function ( path , mode , callback ) {
binding . mkdir ( path , mode , callback || noop ) ;
binding . mkdir ( path , modeNum ( mode ) , callback || noop ) ;
} ;
fs . mkdirSync = function ( path , mode ) {
return binding . mkdir ( path , mode ) ;
return binding . mkdir ( path , modeNum ( mode ) ) ;
} ;
fs . sendfile = function ( outFd , inFd , inOffset , length , callback ) {
@ -386,11 +399,11 @@ fs.unlinkSync = function(path) {
} ;
fs . chmod = function ( path , mode , callback ) {
binding . chmod ( path , mode , callback || noop ) ;
binding . chmod ( path , modeNum ( mode ) , callback || noop ) ;
} ;
fs . chmodSync = function ( path , mode ) {
return binding . chmod ( path , mode ) ;
return binding . chmod ( path , modeNum ( mode ) ) ;
} ;
fs . chown = function ( path , uid , gid , callback ) {
@ -684,7 +697,7 @@ var ReadStream = fs.ReadStream = function(path, options) {
this . paused = false ;
this . flags = 'r' ;
this . mode = 0666 ;
this . mode = parseInt ( '0666' , 8 ) ;
this . bufferSize = 64 * 1024 ;
options = options || { } ;
@ -871,7 +884,7 @@ var WriteStream = fs.WriteStream = function(path, options) {
this . flags = 'w' ;
this . encoding = 'binary' ;
this . mode = 0666 ;
this . mode = parseInt ( '0666' , 8 ) ;
options = options || { } ;