| 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 { |
| 11 /** | 11 /** |
| 12 * Call to process a chunk of data. A call to [process] should only be made | 12 * Call to process a chunk of data. A call to [process] should only be made |
| 13 * when [processed] returns [null]. | 13 * when [processed] returns [null]. |
| 14 */ | 14 */ |
| 15 void process(List<int> data); | 15 void process(List<int> data); |
| 16 | 16 |
| 17 /** | 17 /** |
| 18 * Get a chunk of processed data. When there are no more data available, | 18 * Get a chunk of processed data. When there are no more data available, |
| 19 * [processed] will return [null]. Set [flush] to [false] for non-final | 19 * [processed] will return [null]. Set [flush] to [false] for non-final |
| 20 * calls to improve performance of some filters. | 20 * calls to improve performance of some filters. |
| 21 * |
| 22 * The last call to [processed] should have [end] set to [true]. This will mak
e |
| 23 * sure a 'end' packet is written on the stream. |
| 21 */ | 24 */ |
| 22 List<int> processed({bool flush: true}); | 25 List<int> processed({bool flush: true, bool end: false}); |
| 23 | 26 |
| 24 /** | 27 /** |
| 25 * Mark the filter as closed. Always call this method for any filter created | 28 * Mark the filter as closed. Always call this method for any filter created |
| 26 * to avoid leaking resources. [end] can be called at any time, but any | 29 * to avoid leaking resources. [end] can be called at any time, but any |
| 27 * successive calls to [process] or [processed] will fail. | 30 * successive calls to [process] or [processed] will fail. |
| 28 */ | 31 */ |
| 29 void end(); | 32 void end(); |
| 30 | 33 |
| 31 external static _Filter newZLibDeflateFilter(bool gzip, int level); | 34 external static _Filter newZLibDeflateFilter(bool gzip, int level); |
| 32 external static _Filter newZLibInflateFilter(); | 35 external static _Filter newZLibInflateFilter(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 55 sink.addError(e); | 58 sink.addError(e); |
| 56 sink.close(); | 59 sink.close(); |
| 57 } | 60 } |
| 58 } | 61 } |
| 59 | 62 |
| 60 void handleDone(EventSink<List<int>> sink) { | 63 void handleDone(EventSink<List<int>> sink) { |
| 61 if (_closed) return; | 64 if (_closed) return; |
| 62 if (_empty) _filter.process(const []); | 65 if (_empty) _filter.process(const []); |
| 63 try { | 66 try { |
| 64 var out; | 67 var out; |
| 65 while ((out = _filter.processed()) != null) { | 68 while ((out = _filter.processed(end: true)) != null) { |
| 66 sink.add(out); | 69 sink.add(out); |
| 67 } | 70 } |
| 68 } catch (e, s) { | 71 } catch (e, s) { |
| 69 // TODO(floitsch): we are losing the stack trace. | 72 // TODO(floitsch): we are losing the stack trace. |
| 70 sink.addError(e); | 73 sink.addError(e); |
| 71 _closed = true; | 74 _closed = true; |
| 72 } | 75 } |
| 73 if (!_closed) _filter.end(); | 76 if (!_closed) _filter.end(); |
| 74 _closed = true; | 77 _closed = true; |
| 75 sink.close(); | 78 sink.close(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 86 } | 89 } |
| 87 | 90 |
| 88 | 91 |
| 89 /** | 92 /** |
| 90 * ZLibInflater class used to inflate a stream of bytes, using zlib. | 93 * ZLibInflater class used to inflate a stream of bytes, using zlib. |
| 91 */ | 94 */ |
| 92 class ZLibInflater extends _FilterTransformer { | 95 class ZLibInflater extends _FilterTransformer { |
| 93 ZLibInflater() : super(_Filter.newZLibInflateFilter()); | 96 ZLibInflater() : super(_Filter.newZLibInflateFilter()); |
| 94 } | 97 } |
| 95 | 98 |
| OLD | NEW |