@@ -31,6 +31,7 @@ use failure::local_stderr;
31
31
use fmt;
32
32
use io:: { Reader , Writer , IoResult , IoError , OtherIoError ,
33
33
standard_error, EndOfFile , LineBufferedWriter , BufferedReader } ;
34
+ use iter:: Iterator ;
34
35
use kinds:: Send ;
35
36
use libc;
36
37
use option:: { Option , Some , None } ;
@@ -40,7 +41,9 @@ use rt;
40
41
use rt:: local:: Local ;
41
42
use rt:: task:: Task ;
42
43
use rt:: rtio:: { DontClose , IoFactory , LocalIo , RtioFileStream , RtioTTY } ;
44
+ use slice:: ImmutableVector ;
43
45
use str:: StrSlice ;
46
+ use uint;
44
47
45
48
// And so begins the tale of acquiring a uv handle to a stdio stream on all
46
49
// platforms in all situations. Our story begins by splitting the world into two
@@ -355,10 +358,18 @@ impl StdWriter {
355
358
356
359
impl Writer for StdWriter {
357
360
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 ( ( ) )
362
373
}
363
374
}
364
375
0 commit comments