@@ -555,40 +555,7 @@ fs.openSync = function(path, flags, mode) {
555555 return binding . open ( pathModule . _makeLong ( path ) , stringToFlags ( flags ) , mode ) ;
556556} ;
557557
558- var readWarned = false ;
559558fs . read = function ( fd , buffer , offset , length , position , callback ) {
560- if ( ! isUint8Array ( buffer ) ) {
561- // legacy string interface (fd, length, position, encoding, callback)
562- if ( ! readWarned ) {
563- readWarned = true ;
564- process . emitWarning (
565- 'fs.read\'s legacy String interface is deprecated. Use the Buffer ' +
566- 'API as mentioned in the documentation instead.' ,
567- 'DeprecationWarning' ) ;
568- }
569-
570- const cb = arguments [ 4 ] ;
571- const encoding = arguments [ 3 ] ;
572-
573- assertEncoding ( encoding ) ;
574-
575- position = arguments [ 2 ] ;
576- length = arguments [ 1 ] ;
577- buffer = Buffer . allocUnsafe ( length ) ;
578- offset = 0 ;
579-
580- callback = function ( err , bytesRead ) {
581- if ( ! cb ) return ;
582- if ( err ) return cb ( err ) ;
583-
584- if ( bytesRead > 0 ) {
585- tryToStringWithEnd ( buffer , encoding , bytesRead , cb ) ;
586- } else {
587- ( cb ) ( err , '' , bytesRead ) ;
588- }
589- } ;
590- }
591-
592559 if ( length === 0 ) {
593560 return process . nextTick ( function ( ) {
594561 callback && callback ( null , 0 , buffer ) ;
@@ -606,57 +573,12 @@ fs.read = function(fd, buffer, offset, length, position, callback) {
606573 binding . read ( fd , buffer , offset , length , position , req ) ;
607574} ;
608575
609- function tryToStringWithEnd ( buf , encoding , end , callback ) {
610- var e ;
611- try {
612- buf = buf . toString ( encoding , 0 , end ) ;
613- } catch ( err ) {
614- e = err ;
615- }
616- callback ( e , buf , end ) ;
617- }
618-
619- var readSyncWarned = false ;
620576fs . readSync = function ( fd , buffer , offset , length , position ) {
621- var legacy = false ;
622- var encoding ;
623-
624- if ( ! isUint8Array ( buffer ) ) {
625- // legacy string interface (fd, length, position, encoding, callback)
626- if ( ! readSyncWarned ) {
627- readSyncWarned = true ;
628- process . emitWarning (
629- 'fs.readSync\'s legacy String interface is deprecated. Use the ' +
630- 'Buffer API as mentioned in the documentation instead.' ,
631- 'DeprecationWarning' ) ;
632- }
633- legacy = true ;
634- encoding = arguments [ 3 ] ;
635-
636- assertEncoding ( encoding ) ;
637-
638- position = arguments [ 2 ] ;
639- length = arguments [ 1 ] ;
640- buffer = Buffer . allocUnsafe ( length ) ;
641-
642- offset = 0 ;
643- }
644-
645577 if ( length === 0 ) {
646- if ( legacy ) {
647- return [ '' , 0 ] ;
648- } else {
649- return 0 ;
650- }
651- }
652-
653- var r = binding . read ( fd , buffer , offset , length , position ) ;
654- if ( ! legacy ) {
655- return r ;
578+ return 0 ;
656579 }
657580
658- var str = ( r > 0 ) ? buffer . toString ( encoding , 0 , r ) : '' ;
659- return [ str , r ] ;
581+ return binding . read ( fd , buffer , offset , length , position ) ;
660582} ;
661583
662584// usage:
0 commit comments