| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of dart.io; | 5 part of dart.io; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Private helper-class to handle native filters. | 8 * Private helper-class to handle native filters. |
| 9 */ | 9 */ |
| 10 abstract class _Filter { | 10 abstract class _Filter { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 void end(); | 29 void end(); |
| 30 | 30 |
| 31 external static _Filter newZLibDeflateFilter(bool gzip, int level); | 31 external static _Filter newZLibDeflateFilter(bool gzip, int level); |
| 32 external static _Filter newZLibInflateFilter(); | 32 external static _Filter newZLibInflateFilter(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 | 35 |
| 36 class _FilterTransformer extends StreamEventTransformer<List<int>, List<int>> { | 36 class _FilterTransformer extends StreamEventTransformer<List<int>, List<int>> { |
| 37 final _Filter _filter; | 37 final _Filter _filter; |
| 38 bool _closed = false; | 38 bool _closed = false; |
| 39 bool _empty = true; |
| 39 | 40 |
| 40 _FilterTransformer(_Filter this._filter); | 41 _FilterTransformer(_Filter this._filter); |
| 41 | 42 |
| 42 void handleData(List<int> data, EventSink<List<int>> sink) { | 43 void handleData(List<int> data, EventSink<List<int>> sink) { |
| 43 if (_closed) return; | 44 if (_closed) return; |
| 44 try { | 45 try { |
| 46 _empty = false; |
| 45 _filter.process(data); | 47 _filter.process(data); |
| 46 var out; | 48 var out; |
| 47 while ((out = _filter.processed(flush: false)) != null) { | 49 while ((out = _filter.processed(flush: false)) != null) { |
| 48 sink.add(out); | 50 sink.add(out); |
| 49 } | 51 } |
| 50 } catch (e, s) { | 52 } catch (e, s) { |
| 51 _closed = true; | 53 _closed = true; |
| 52 sink.addError(new AsyncError(e, s)); | 54 sink.addError(new AsyncError(e, s)); |
| 53 sink.close(); | 55 sink.close(); |
| 54 } | 56 } |
| 55 } | 57 } |
| 56 | 58 |
| 57 void handleDone(EventSink<List<int>> sink) { | 59 void handleDone(EventSink<List<int>> sink) { |
| 58 if (_closed) return; | 60 if (_closed) return; |
| 61 if (_empty) _filter.process(const []); |
| 59 try { | 62 try { |
| 60 var out; | 63 var out; |
| 61 while ((out = _filter.processed()) != null) { | 64 while ((out = _filter.processed()) != null) { |
| 62 sink.add(out); | 65 sink.add(out); |
| 63 } | 66 } |
| 64 } catch (e, s) { | 67 } catch (e, s) { |
| 65 sink.addError(new AsyncError(e, s)); | 68 sink.addError(new AsyncError(e, s)); |
| 66 _closed = true; | 69 _closed = true; |
| 67 } | 70 } |
| 68 if (!_closed) _filter.end(); | 71 if (!_closed) _filter.end(); |
| 72 _closed = true; |
| 69 sink.close(); | 73 sink.close(); |
| 70 } | 74 } |
| 71 } | 75 } |
| 72 | 76 |
| 73 | 77 |
| 74 /** | 78 /** |
| 75 * ZLibDeflater class used to deflate a stream of bytes, using zlib. | 79 * ZLibDeflater class used to deflate a stream of bytes, using zlib. |
| 76 */ | 80 */ |
| 77 class ZLibDeflater extends _FilterTransformer { | 81 class ZLibDeflater extends _FilterTransformer { |
| 78 ZLibDeflater({bool gzip: true, int level: 6}) | 82 ZLibDeflater({bool gzip: true, int level: 6}) |
| 79 : super(_Filter.newZLibDeflateFilter(gzip, level)); | 83 : super(_Filter.newZLibDeflateFilter(gzip, level)); |
| 80 } | 84 } |
| 81 | 85 |
| 82 | 86 |
| 83 /** | 87 /** |
| 84 * ZLibInflater class used to inflate a stream of bytes, using zlib. | 88 * ZLibInflater class used to inflate a stream of bytes, using zlib. |
| 85 */ | 89 */ |
| 86 class ZLibInflater extends _FilterTransformer { | 90 class ZLibInflater extends _FilterTransformer { |
| 87 ZLibInflater() : super(_Filter.newZLibInflateFilter()); | 91 ZLibInflater() : super(_Filter.newZLibInflateFilter()); |
| 88 } | 92 } |
| 89 | 93 |
| OLD | NEW |