@@ -31,6 +31,7 @@ use failure::local_stderr;
3131use fmt;
3232use io:: { Reader , Writer , IoResult , IoError , OtherIoError ,
3333 standard_error, EndOfFile , LineBufferedWriter , BufferedReader } ;
34+ use iter:: Iterator ;
3435use kinds:: Send ;
3536use libc;
3637use option:: { Option , Some , None } ;
@@ -40,7 +41,9 @@ use rt;
4041use rt:: local:: Local ;
4142use rt:: task:: Task ;
4243use rt:: rtio:: { DontClose , IoFactory , LocalIo , RtioFileStream , RtioTTY } ;
44+ use slice:: ImmutableVector ;
4345use str:: StrSlice ;
46+ use uint;
4447
4548// And so begins the tale of acquiring a uv handle to a stdio stream on all
4649// platforms in all situations. Our story begins by splitting the world into two
@@ -355,10 +358,18 @@ impl StdWriter {
355358
356359impl Writer for StdWriter {
357360 fn write ( & mut self , buf : & [ u8 ] ) -> IoResult < ( ) > {
358- match self . inner {
359- TTY ( ref mut tty) => tty. write ( buf) ,
360- File ( ref mut file) => file. write ( buf) ,
361- } . map_err ( IoError :: from_rtio_error)
361+ // As with stdin on windows, stdout often can't handle writes of large
362+ // sizes. For an example, see #14940. For this reason, chunk the output
363+ // buffer on windows, but on unix we can just write the whole buffer all
364+ // at once.
365+ let max_size = if cfg ! ( windows) { 64 * 1024 } else { uint:: MAX } ;
366+ for chunk in buf. chunks ( max_size) {
367+ try!( match self . inner {
368+ TTY ( ref mut tty) => tty. write ( chunk) ,
369+ File ( ref mut file) => file. write ( chunk) ,
370+ } . map_err ( IoError :: from_rtio_error) )
371+ }
372+ Ok ( ( ) )
362373 }
363374}
364375
0 commit comments