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 * Exposes ZLib options for input parameters. | 8 * Exposes ZLib options for input parameters. |
9 * | 9 * |
10 * See http://www.zlib.net/manual.html for more documentation. | 10 * See http://www.zlib.net/manual.html for more documentation. |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 windowBits = ZLibOption.DEFAULT_WINDOW_BITS, | 140 windowBits = ZLibOption.DEFAULT_WINDOW_BITS, |
141 memLevel = ZLibOption.DEFAULT_MEM_LEVEL, | 141 memLevel = ZLibOption.DEFAULT_MEM_LEVEL, |
142 strategy = ZLibOption.STRATEGY_DEFAULT, | 142 strategy = ZLibOption.STRATEGY_DEFAULT, |
143 raw = false, | 143 raw = false, |
144 gzip = false, | 144 gzip = false, |
145 dictionary = null; | 145 dictionary = null; |
146 | 146 |
147 /** | 147 /** |
148 * Get a [ZLibEncoder] for encoding to `ZLib` compressed data. | 148 * Get a [ZLibEncoder] for encoding to `ZLib` compressed data. |
149 */ | 149 */ |
150 Converter<List<int>, List<int>> get encoder => | 150 ZLibEncoder get encoder => |
151 new ZLibEncoder(gzip: false, level: level, windowBits: windowBits, | 151 new ZLibEncoder(gzip: false, level: level, windowBits: windowBits, |
152 memLevel: memLevel, strategy: strategy, | 152 memLevel: memLevel, strategy: strategy, |
153 dictionary: dictionary, raw: raw); | 153 dictionary: dictionary, raw: raw); |
154 | 154 |
155 /** | 155 /** |
156 * Get a [ZLibDecoder] for decoding `ZLib` compressed data. | 156 * Get a [ZLibDecoder] for decoding `ZLib` compressed data. |
157 */ | 157 */ |
158 Converter<List<int>, List<int>> get decoder => | 158 ZLibDecoder get decoder => |
159 new ZLibDecoder(windowBits: windowBits, dictionary: dictionary, raw: raw); | 159 new ZLibDecoder(windowBits: windowBits, dictionary: dictionary, raw: raw); |
160 } | 160 } |
161 | 161 |
162 | 162 |
163 /** | 163 /** |
164 * An instance of the default implementation of the [GZipCodec]. | 164 * An instance of the default implementation of the [GZipCodec]. |
165 */ | 165 */ |
166 const GZipCodec GZIP = const GZipCodec._default(); | 166 const GZipCodec GZIP = const GZipCodec._default(); |
167 | 167 |
168 | 168 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 windowBits = ZLibOption.DEFAULT_WINDOW_BITS, | 252 windowBits = ZLibOption.DEFAULT_WINDOW_BITS, |
253 memLevel = ZLibOption.DEFAULT_MEM_LEVEL, | 253 memLevel = ZLibOption.DEFAULT_MEM_LEVEL, |
254 strategy = ZLibOption.STRATEGY_DEFAULT, | 254 strategy = ZLibOption.STRATEGY_DEFAULT, |
255 raw = false, | 255 raw = false, |
256 gzip = true, | 256 gzip = true, |
257 dictionary = null; | 257 dictionary = null; |
258 | 258 |
259 /** | 259 /** |
260 * Get a [ZLibEncoder] for encoding to `GZip` compressed data. | 260 * Get a [ZLibEncoder] for encoding to `GZip` compressed data. |
261 */ | 261 */ |
262 Converter<List<int>, List<int>> get encoder => | 262 ZLibEncoder get encoder => |
263 new ZLibEncoder(gzip: true, level: level, windowBits: windowBits, | 263 new ZLibEncoder(gzip: true, level: level, windowBits: windowBits, |
264 memLevel: memLevel, strategy: strategy, | 264 memLevel: memLevel, strategy: strategy, |
265 dictionary: dictionary, raw: raw); | 265 dictionary: dictionary, raw: raw); |
266 | 266 |
267 /** | 267 /** |
268 * Get a [ZLibDecoder] for decoding `GZip` compressed data. | 268 * Get a [ZLibDecoder] for decoding `GZip` compressed data. |
269 */ | 269 */ |
270 Converter<List<int>, List<int>> get decoder => | 270 ZLibDecoder get decoder => |
271 new ZLibDecoder(windowBits: windowBits, dictionary: dictionary, raw: raw); | 271 new ZLibDecoder(windowBits: windowBits, dictionary: dictionary, raw: raw); |
272 } | 272 } |
273 | 273 |
274 /** | 274 /** |
275 * The [ZLibEncoder] encoder is used by [ZLibCodec] and [GZipCodec] to compress | 275 * The [ZLibEncoder] encoder is used by [ZLibCodec] and [GZipCodec] to compress |
276 * data. | 276 * data. |
277 */ | 277 */ |
278 class ZLibEncoder extends Converter<List<int>, List<int>> { | 278 class ZLibEncoder extends |
| 279 ChunkedConverter<List<int>, List<int>, List<int>, List<int>> { |
279 /** | 280 /** |
280 * When true, `GZip` frames will be added to the compressed data. | 281 * When true, `GZip` frames will be added to the compressed data. |
281 */ | 282 */ |
282 final bool gzip; | 283 final bool gzip; |
283 | 284 |
284 /** | 285 /** |
285 * The compression-[level] can be set in the range of `-1..9`, with `6` being | 286 * The compression-[level] can be set in the range of `-1..9`, with `6` being |
286 * the default compression level. Levels above `6` will have higher | 287 * the default compression level. Levels above `6` will have higher |
287 * compression rates at the cost of more CPU and memory usage. Levels below | 288 * compression rates at the cost of more CPU and memory usage. Levels below |
288 * `6` will use less CPU and memory at the cost of lower compression rates. | 289 * `6` will use less CPU and memory at the cost of lower compression rates. |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 } | 372 } |
372 return new _ZLibEncoderSink(sink, gzip, level, windowBits, memLevel, | 373 return new _ZLibEncoderSink(sink, gzip, level, windowBits, memLevel, |
373 strategy, dictionary, raw); | 374 strategy, dictionary, raw); |
374 } | 375 } |
375 } | 376 } |
376 | 377 |
377 | 378 |
378 /** | 379 /** |
379 * The [ZLibDecoder] is used by [ZLibCodec] and [GZipCodec] to decompress data. | 380 * The [ZLibDecoder] is used by [ZLibCodec] and [GZipCodec] to decompress data. |
380 */ | 381 */ |
381 class ZLibDecoder extends Converter<List<int>, List<int>> { | 382 class ZLibDecoder extends |
| 383 ChunkedConverter<List<int>, List<int>, List<int>, List<int>> { |
382 /** | 384 /** |
383 * Base two logarithm of the window size (the size of the history buffer). It | 385 * Base two logarithm of the window size (the size of the history buffer). It |
384 * should be in the range `8..15`. Larger values result in better compression | 386 * should be in the range `8..15`. Larger values result in better compression |
385 * at the expense of memory usage. The default value is `15`. | 387 * at the expense of memory usage. The default value is `15`. |
386 */ | 388 */ |
387 final int windowBits; | 389 final int windowBits; |
388 | 390 |
389 /** | 391 /** |
390 * Initial compression dictionary. | 392 * Initial compression dictionary. |
391 * | 393 * |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 } | 580 } |
579 | 581 |
580 void _validateZLibStrategy(int strategy) { | 582 void _validateZLibStrategy(int strategy) { |
581 const strategies = const <int>[ZLibOption.STRATEGY_FILTERED, | 583 const strategies = const <int>[ZLibOption.STRATEGY_FILTERED, |
582 ZLibOption.STRATEGY_HUFFMAN_ONLY, ZLibOption.STRATEGY_RLE, | 584 ZLibOption.STRATEGY_HUFFMAN_ONLY, ZLibOption.STRATEGY_RLE, |
583 ZLibOption.STRATEGY_FIXED, ZLibOption.STRATEGY_DEFAULT]; | 585 ZLibOption.STRATEGY_FIXED, ZLibOption.STRATEGY_DEFAULT]; |
584 if (strategies.indexOf(strategy) == -1) { | 586 if (strategies.indexOf(strategy) == -1) { |
585 throw new ArgumentError("Unsupported 'strategy'"); | 587 throw new ArgumentError("Unsupported 'strategy'"); |
586 } | 588 } |
587 } | 589 } |
OLD | NEW |