1- common = require ( "../common" ) ;
2- assert = common . assert
1+ var common = require ( "../common" ) ;
2+ var assert = common . assert
33var path = require ( 'path' ) ;
44var Buffer = require ( 'buffer' ) . Buffer ;
55var fs = require ( 'fs' ) ;
66var fn = path . join ( common . tmpDir , "write.txt" ) ;
7+ var fn2 = path . join ( common . tmpDir , "write2.txt" ) ;
78var expected = "ümlaut." ;
8- var found ;
9+ var constants = require ( 'constants' ) ;
10+ var found , found2 ;
911
1012fs . open ( fn , 'w' , 0644 , function ( err , fd ) {
1113 if ( err ) throw err ;
@@ -25,7 +27,29 @@ fs.open(fn, 'w', 0644, function (err, fd) {
2527 } ) ;
2628} ) ;
2729
30+
31+ fs . open ( fn2 , constants . O_CREAT | constants . O_WRONLY | constants . O_TRUNC ,
32+ 0644 , function ( err , fd ) {
33+ if ( err ) throw err ;
34+ console . log ( 'open done' ) ;
35+ fs . write ( fd , '' , 0 , 'utf8' , function ( err , written ) {
36+ assert . equal ( 0 , written ) ;
37+ } ) ;
38+ fs . write ( fd , expected , 0 , "utf8" , function ( err , written ) {
39+ console . log ( 'write done' ) ;
40+ if ( err ) throw err ;
41+ assert . equal ( Buffer . byteLength ( expected ) , written ) ;
42+ fs . closeSync ( fd ) ;
43+ found2 = fs . readFileSync ( fn2 , 'utf8' ) ;
44+ console . log ( 'expected: ' + expected . toJSON ( ) ) ;
45+ console . log ( 'found: ' + found2 . toJSON ( ) ) ;
46+ fs . unlinkSync ( fn2 ) ;
47+ } ) ;
48+ } ) ;
49+
50+
2851process . addListener ( "exit" , function ( ) {
2952 assert . equal ( expected , found ) ;
53+ assert . equal ( expected , found2 ) ;
3054} ) ;
3155
0 commit comments