Chromium Code Reviews| Index: runtime/bin/process_patch.dart |
| diff --git a/runtime/bin/process_patch.dart b/runtime/bin/process_patch.dart |
| index 0acd6c0498172154f50b4b0cd2eaf2be84df3599..f74e814af0856df0fb184d4e0ee76b6960e982d8 100644 |
| --- a/runtime/bin/process_patch.dart |
| +++ b/runtime/bin/process_patch.dart |
| @@ -337,8 +337,8 @@ Future<ProcessResult> _runNonInteractiveProcess(String path, |
| Encoding stdoutEncoding, |
| Encoding stderrEncoding) { |
| // Extract output encoding options and verify arguments. |
| - if (stdoutEncoding == null) stdoutEncoding = Encoding.SYSTEM; |
| - if (stderrEncoding == null) stderrEncoding = Encoding.SYSTEM; |
| + if (stdoutEncoding == null) stdoutEncoding = Encoding.BINARY; |
|
Anders Johnsen
2013/06/13 09:02:07
Why BINARY here? I suppose we still default to SYS
Søren Gjesse
2013/06/13 10:27:12
The default in the signature for Process.run is st
|
| + if (stderrEncoding == null) stderrEncoding = Encoding.BINARY; |
| // Start the underlying process. |
| return Process.start(path, |
| @@ -351,30 +351,35 @@ Future<ProcessResult> _runNonInteractiveProcess(String path, |
| // Make sure the process stdin is closed. |
| p.stdin.close(); |
| - // Setup stdout handling. |
| - Future<StringBuffer> stdout = p.stdout |
| - .transform(new StringDecoder(stdoutEncoding)) |
| - .fold( |
| - new StringBuffer(), |
| - (buf, data) { |
| - buf.write(data); |
| - return buf; |
| - }); |
| - |
| - Future<StringBuffer> stderr = p.stderr |
| - .transform(new StringDecoder(stderrEncoding)) |
| - .fold( |
| - new StringBuffer(), |
| - (buf, data) { |
| - buf.write(data); |
| - return buf; |
| - }); |
| + // Setup stdout and stderr handling. |
| + Future foldStream(Stream<List<int>> stream, Encoding encoding) { |
| + if (encoding == Encoding.BINARY) { |
| + return stream |
| + .fold( |
| + new _BufferList(), |
| + (buf, data) { |
| + buf.add(data); |
| + return buf; |
| + }) |
| + .then((buf) => buf.readBytes()); |
| + } else { |
| + return stream |
| + .transform(new StringDecoder(encoding)) |
| + .fold( |
| + new StringBuffer(), |
| + (buf, data) { |
| + buf.write(data); |
| + return buf; |
| + }) |
| + .then((sb) => sb.toString()); |
| + } |
| + } |
| + |
| + Future stdout = foldStream(p.stdout, stdoutEncoding); |
| + Future stderr = foldStream(p.stderr, stderrEncoding); |
| return Future.wait([p.exitCode, stdout, stderr]).then((result) { |
| - return new _ProcessResult(pid, |
| - result[0], |
| - result[1].toString(), |
| - result[2].toString()); |
| + return new _ProcessResult(pid, result[0], result[1], result[2]); |
| }); |
| }); |
| } |
| @@ -383,11 +388,11 @@ Future<ProcessResult> _runNonInteractiveProcess(String path, |
| class _ProcessResult implements ProcessResult { |
| const _ProcessResult(int this.pid, |
| int this.exitCode, |
| - String this.stdout, |
| - String this.stderr); |
| + this.stdout, |
| + this.stderr); |
| final int pid; |
| final int exitCode; |
| - final String stdout; |
| - final String stderr; |
| + final stdout; |
| + final stderr; |
| } |