Chromium Code Reviews| Index: sdk/lib/io/data_transformer.dart |
| diff --git a/sdk/lib/io/data_transformer.dart b/sdk/lib/io/data_transformer.dart |
| index 79df03cc140dfac3b857a07f297157d3dd0f219d..95ae03f0e4fb66414c70f3ef30d966aa202c110a 100644 |
| --- a/sdk/lib/io/data_transformer.dart |
| +++ b/sdk/lib/io/data_transformer.dart |
| @@ -22,23 +22,51 @@ class ZLibCodec extends Codec<List<int>, List<int>> { |
| final int level; |
| /** |
| + * The windowBits parameter is the base two logarithm of the window size (the |
| + * size of the history buffer). It should be in the range 8..15. Larger values |
| + * of this parameter result in better compression at the expense of memory |
| + * usage. The default value is 15 |
| + */ |
| + final int windowBits; |
| + |
| + /** |
| + * The [memLevel] parameter specifies how much memory should be allocated for |
| + * the internal compression state. [memLevel]=1 uses minimum memory but is slow |
| + * and reduces compression ratio; [memLevel]=9 uses maximum memory for optimal |
| + * speed. The default value is 8 |
| + * The memory requirements for deflate are (in bytes): |
| + * (1 << (windowBits + 2)) + (1 << (memLevel + 9)) |
| + * that is: 128K for windowBits = 15 + 128K for memLevel = 8 (default values) |
| + */ |
| + final int memLevel; |
| + |
| + /** |
| + * When [raw] is true, deflate generates raw data with no zlib header or |
| + * trailer, and will not compute an adler32 check value |
| + */ |
| + final bool raw; |
| + |
| + /** |
| * Get a [Converter] for encoding to `ZLib` compressed data. |
| */ |
| Converter<List<int>, List<int>> get encoder => |
| - new ZLibEncoder(gzip: false, level: level); |
| + new ZLibEncoder(gzip: false, level: level, windowBits: windowBits, |
| + raw: raw, memLevel: memLevel); |
| /** |
| * Get a [Converter] for decoding `ZLib` compressed data. |
| */ |
| - Converter<List<int>, List<int>> get decoder => const ZLibDecoder(); |
| + Converter<List<int>, List<int>> get decoder => new ZLibDecoder( |
| + windowBits: windowBits, raw: raw); |
| /** |
| - * The compression-[level] can be set in the range of `1..10`, with `6` being |
| + * The compression-[level] can be set in the range of `-1..9`, with `6` being |
| * the default compression level. Levels above 6 will have higher compression |
| * rates at the cost of more CPU and memory usage. Levels below 6 will use |
| * less CPU and memory, but at the cost of lower compression rates. |
| */ |
| - const ZLibCodec({this.level: 6}); |
| + const ZLibCodec({this.level: 6, this.windowBits: 15, this.raw: false, |
|
Anders Johnsen
2014/01/15 10:52:08
Please add some constants to ZLibCodec, ZLIB_LEVEL
Anders Johnsen
2014/01/15 10:52:08
Make raw the last argument.
vicb
2014/01/15 11:08:04
That's in the pipe
vicb
2014/01/15 11:08:04
Could I ask why ? (is order important for named pa
Anders Johnsen
2014/01/15 11:34:17
Matter of taste I suppose :) `raw` is kind of diff
vicb
2014/01/23 09:14:04
I've moved raw to be the last parameter everywhere
|
| + this.memLevel: 8}); |
| } |
| @@ -62,23 +90,52 @@ class GZipCodec extends Codec<List<int>, List<int>> { |
| final int level; |
| /** |
| + * The windowBits parameter is the base two logarithm of the window size (the |
| + * size of the history buffer). It should be in the range 8..15. Larger values |
| + * of this parameter result in better compression at the expense of memory |
| + * usage. The default value is 15 |
| + */ |
| + final int windowBits; |
| + |
| + /** |
| + * The [memLevel] parameter specifies how much memory should be allocated for |
| + * the internal compression state. [memLevel]=1 uses minimum memory but is slow |
| + * and reduces compression ratio; [memLevel]=9 uses maximum memory for optimal |
| + * speed. The default value is 8 |
| + * The memory requirements for deflate are (in bytes): |
| + * (1 << (windowBits + 2)) + (1 << (memLevel + 9)) |
| + * that is: 128K for windowBits = 15 + 128K for memLevel = 8 (default values) |
| + */ |
| + final int memLevel; |
| + |
| + /** |
| + * When [raw] is true, deflate generates raw data with no zlib header or |
| + * trailer, and will not compute an adler32 check value |
| + */ |
| + final bool raw; |
| + |
| + /** |
| * Get a [Converter] for encoding to `GZip` compressed data. |
| */ |
| Converter<List<int>, List<int>> get encoder => |
| - new ZLibEncoder(gzip: true, level: level); |
| + new ZLibEncoder(gzip: true, level: level, windowBits: windowBits, |
| + raw: raw, memLevel: memLevel); |
| /** |
| * Get a [Converter] for decoding `GZip` compressed data. |
| */ |
| - Converter<List<int>, List<int>> get decoder => const ZLibDecoder(); |
| + Converter<List<int>, List<int>> get decoder => new ZLibDecoder( |
| + windowBits: windowBits, raw: raw); |
| /** |
| - * The compression-[level] can be set in the range of `1..10`, with `6` being |
| - * the default compression level. Levels above 6 will have higher compression |
| - * rates at the cost of more CPU and memory usage. Levels below 6 will use |
| - * less CPU and memory, but at the cost of lower compression rates. |
| + * The compression-[level] can be set in the range of `-1..9`, with `6` being |
| + * the default compression level. Levels above `6` will have higher |
| + * compression rates at the cost of more CPU and memory usage. Levels below |
| + * `6` will use less CPU and memory, but at the cost of lower compression |
| + * rates. |
| */ |
| - const GZipCodec({this.level: 6}); |
| + const GZipCodec({this.level: 6, this.windowBits: 15, this.raw: false, |
| + this.memLevel: 8}); |
| } |
| @@ -98,11 +155,36 @@ class ZLibEncoder extends Converter<List<int>, List<int>> { |
| final int level; |
| /** |
| + * The windowBits parameter is the base two logarithm of the window size (the |
| + * size of the history buffer). It should be in the range 8..15. Larger values |
| + * of this parameter result in better compression at the expense of memory |
| + * usage. The default value is 15 |
| + */ |
| + final int windowBits; |
| + |
| + /** |
| + * The [memLevel] parameter specifies how much memory should be allocated for |
| + * the internal compression state. [memLevel]=1 uses minimum memory but is slow |
| + * and reduces compression ratio; [memLevel]=9 uses maximum memory for optimal |
| + * speed. The default value is 8 |
| + * The memory requirements for deflate are (in bytes): |
| + * (1 << (windowBits + 2)) + (1 << (memLevel + 9)) |
| + * that is: 128K for windowBits = 15 + 128K for memLevel = 8 (default values) |
| + */ |
| + final int memLevel; |
| + |
| + /** |
| + * When [raw] is true, deflate generates raw data with no zlib header or |
| + * trailer, and will not compute an adler32 check value |
| + */ |
| + final bool raw; |
| + |
| + /** |
| * Create a new [ZLibEncoder] converter. If the [gzip] flag is set, the |
| * encoder will wrap the encoded ZLib data in GZip frames. |
| */ |
| - const ZLibEncoder({this.gzip: false, this.level: 6}); |
| - |
| + const ZLibEncoder({this.gzip: false, this.level: 6, this.windowBits: 15, |
| + this.raw: false, this.memLevel: 8}); |
| /** |
| * Convert a list of bytes using the options given to the [ZLibEncoder] |
| @@ -127,7 +209,7 @@ class ZLibEncoder extends Converter<List<int>, List<int>> { |
| if (sink is! ByteConversionSink) { |
| sink = new ByteConversionSink.from(sink); |
| } |
| - return new _ZLibEncoderSink(sink, gzip, level); |
| + return new _ZLibEncoderSink(sink, gzip, level, windowBits, raw, memLevel); |
| } |
| } |
| @@ -137,11 +219,24 @@ class ZLibEncoder extends Converter<List<int>, List<int>> { |
| * decompress data. |
| */ |
| class ZLibDecoder extends Converter<List<int>, List<int>> { |
| + /** |
| + * The windowBits parameter is the base two logarithm of the window size (the |
| + * size of the history buffer). It should be in the range 8..15. Larger values |
| + * of this parameter result in better compression at the expense of memory |
| + * usage. The default value is 15 |
| + */ |
| + final int windowBits; |
| + |
| + /** |
| + * When [raw] is true, deflate generates raw data with no zlib header or |
| + * trailer, and will not compute an adler32 check value |
| + */ |
| + final bool raw; |
| /** |
| - * Create a new [ZLibEncoder] converter. |
| + * Create a new [ZLibDecoder] converter. |
| */ |
| - const ZLibDecoder(); |
| + const ZLibDecoder({this.windowBits: 15, this.raw: false}); |
| /** |
| * Convert a list of bytes using the options given to the [ZLibDecoder] |
| @@ -165,7 +260,7 @@ class ZLibDecoder extends Converter<List<int>, List<int>> { |
| if (sink is! ByteConversionSink) { |
| sink = new ByteConversionSink.from(sink); |
| } |
| - return new _ZLibDecoderSink(sink); |
| + return new _ZLibDecoderSink(sink, windowBits, raw); |
| } |
| } |
| @@ -191,14 +286,16 @@ class _BufferSink extends ByteConversionSink { |
| class _ZLibEncoderSink extends _FilterSink { |
| - _ZLibEncoderSink(ByteConversionSink sink, bool gzip, int level) |
| - : super(sink, _Filter.newZLibDeflateFilter(gzip, level)); |
| + _ZLibEncoderSink(ByteConversionSink sink, bool gzip, int level, |
| + int windowBits, bool raw, int memLevel) |
| + : super(sink, _Filter.newZLibDeflateFilter(gzip, level, windowBits, raw, |
| + memLevel)); |
| } |
| class _ZLibDecoderSink extends _FilterSink { |
| - _ZLibDecoderSink(ByteConversionSink sink) |
| - : super(sink, _Filter.newZLibInflateFilter()); |
| + _ZLibDecoderSink(ByteConversionSink sink, int windowBits, bool raw) |
| + : super(sink, _Filter.newZLibInflateFilter(windowBits, raw)); |
| } |
| @@ -208,7 +305,7 @@ class _FilterSink extends ByteConversionSink { |
| bool _closed = false; |
| bool _empty = true; |
| - _FilterSink(ByteConversionSink this._sink, _Filter this._filter); |
| + _FilterSink(this._sink, this._filter); |
| void add(List<int> data) { |
| addSlice(data, 0, data.length, false); |
| @@ -286,6 +383,8 @@ abstract class _Filter { |
| */ |
| void end(); |
| - external static _Filter newZLibDeflateFilter(bool gzip, int level); |
| - external static _Filter newZLibInflateFilter(); |
| + external static _Filter newZLibDeflateFilter(bool gzip, int level, |
| + int windowBits, bool raw, |
| + int memLevel); |
| + external static _Filter newZLibInflateFilter(int windowBits, bool raw); |
| } |