Chromium Code Reviews| Index: pkg/kernel/lib/kernel.dart |
| diff --git a/pkg/kernel/lib/kernel.dart b/pkg/kernel/lib/kernel.dart |
| index 361f59aaa265445c0a472feb4138df8e821c00b3..16eb86adeb78ff1e1eab6c80bf0fdb9f384cde04 100644 |
| --- a/pkg/kernel/lib/kernel.dart |
| +++ b/pkg/kernel/lib/kernel.dart |
| @@ -29,13 +29,21 @@ Program loadProgramFromBinary(String path, [Program program]) { |
| } |
| Future writeProgramToBinary(Program program, String path) { |
| - var sink = new File(path).openWrite(); |
| + var sink; |
| + if (path == 'null' || path == 'stdout') { |
| + sink = new _ByteBuffer(); |
|
asgerf
2017/03/31 08:40:16
Is the wrapper necessary? Could you try this inst
Emily Fortuna
2017/03/31 17:46:55
Ah, that's MUCH better. I didn't know about that.
|
| + } else { |
| + sink = new File(path).openWrite(); |
| + } |
| + |
| var future; |
| try { |
| new BinaryPrinter(sink).writeProgramFile(program); |
| } finally { |
| future = sink.close(); |
| } |
| + |
| + if (sink is _ByteBuffer) print(sink.takeBytes()); |
|
asgerf
2017/03/31 08:40:16
Calling toString on a List<int> normally emits som
Emily Fortuna
2017/03/31 17:46:56
touche. No I hadn't actually tested consuming this
|
| return future; |
| } |
| @@ -60,3 +68,25 @@ void writeProgramToText(Program program, |
| new File(path).writeAsStringSync('$buffer'); |
| } |
| } |
| + |
| +/// Silly wrapper around BytesBuilder that conforms to the Sink interface. |
|
Johnni Winther
2017/03/31 06:38:35
'Silly' -> 'Simple'
Emily Fortuna
2017/03/31 17:46:56
Acknowledged.
|
| +class _ByteBuffer implements Sink<List<int>> { |
| + BytesBuilder _builder; |
| + bool _open; |
| + |
| + _ByteBuffer() |
| + : _open = true, |
| + _builder = new BytesBuilder(); |
|
asgerf
2017/03/31 08:40:16
You can pass `copy: false` to the BytesBuilder her
Emily Fortuna
2017/03/31 17:46:56
No longer needed once I took this out.
|
| + |
| + void add(List<int> data) { |
| + if (_open) { |
| + _builder.add(data); |
| + } |
| + } |
| + |
| + void close() { |
| + _open = false; |
| + } |
| + |
| + List<int> takeBytes() => _builder.takeBytes(); |
| +} |