@@ -1337,3 +1337,64 @@ WriteStream.prototype.destroy = function(cb) {
13371337// There is no shutdown() for files.
13381338WriteStream . prototype . destroySoon = WriteStream . prototype . end ;
13391339
1340+
1341+ // SyncWriteStream is internal. DO NOT USE.
1342+ // Temporary hack for process.stdout and process.stderr when piped to files.
1343+ function SyncWriteStream ( fd ) {
1344+ this . fd = fd ;
1345+ this . writable = true ;
1346+ this . readable = false ;
1347+ } ;
1348+ util . inherits ( SyncWriteStream , Stream ) ;
1349+
1350+
1351+ // Export
1352+ fs . SyncWriteStream = SyncWriteStream ;
1353+
1354+
1355+ SyncWriteStream . prototype . write = function ( data , arg1 , arg2 ) {
1356+ var encoding , cb ;
1357+
1358+ // parse arguments
1359+ if ( arg1 ) {
1360+ if ( typeof arg1 === 'string' ) {
1361+ encoding = arg1 ;
1362+ cb = arg2 ;
1363+ } else if ( typeof arg1 === 'function' ) {
1364+ cb = arg1 ;
1365+ } else {
1366+ throw new Error ( "bad arg" ) ;
1367+ }
1368+ }
1369+
1370+ // Change strings to buffers. SLOW
1371+ if ( typeof data == 'string' ) {
1372+ data = new Buffer ( data , encoding ) ;
1373+ }
1374+
1375+ fs . writeSync ( this . fd , data , 0 , data . length ) ;
1376+
1377+ if ( cb ) {
1378+ process . nextTick ( cb ) ;
1379+ }
1380+
1381+ return true ;
1382+ } ;
1383+
1384+
1385+ SyncWriteStream . prototype . end = function ( data , arg1 , arg2 ) {
1386+ if ( data ) {
1387+ this . write ( data , arg1 , arg2 ) ;
1388+ }
1389+ this . destroy ( ) ;
1390+ } ;
1391+
1392+
1393+ SyncWriteStream . prototype . destroy = function ( ) {
1394+ fs . closeSync ( this . fd ) ;
1395+ this . fd = null ;
1396+ this . emit ( 'close' ) ;
1397+ return true ;
1398+ } ;
1399+
1400+ SyncWriteStream . prototype . destroySoon = SyncWriteStream . prototype . destroy ;
0 commit comments