Comments. Lots of comments. :)
I think it is better with an abstract ZLib class containing the
constants.
It takes the same number of characters to write "ZLib." and "ZLIB_", and
it avoids polluting the top-level namespace of the entire dart:io
library.
BUT (capital!) I don't really want to have both "ZLib" and "ZLIB" in the
same scope. To avoid that, I'd prefer the wrapper class to be called
"ZLibOption", "ZLibFlag" or something similar, so you write ...
ZLibOption.MAX_WINDOW_BITS ...
https://codereview.chromium.org/130513003/diff/370001/sdk/lib/io/data_transformer.dart#newcode20
sdk/lib/io/data_transformer.dart:20: const int ZLIB_DFT_LEVEL = 6;
Maybe DFT -> DEFAULT (if that's what it stands for)
Ditto above.
I don't *really* mind having ZLIB be a non-const value.
It is intended to be used as a non-changing object, it's just not a
compile-time constant. I can't see a good use for it at compile-time, so
I would be inclined to let this slip for backwards compatibility, if
there wasn't a better solution.
But, preferably, make a private const constructor:
const ZLibCodec ZLIB = const ZLibCodec._default();
which doesn't have to validate its inputs because it initializes fields
with the default trusted values directly:
const ZLibCodec._default()
: level = ZLIB_DFT_LEVEL,
windowBits = ZLIB_DFR_WINDOW_BITS,
...
raw = false;
https://codereview.chromium.org/130513003/diff/370001/sdk/lib/io/data_transformer.dart#newcode54
sdk/lib/io/data_transformer.dart:54: * the default compression level.
Levels above `6` will have higher compression
long line.
https://codereview.chromium.org/130513003/diff/370001/sdk/lib/io/data_transformer.dart#newcode153
sdk/lib/io/data_transformer.dart:153: * the default compression level.
Levels above `6` will have higher compression
long line.
https://codereview.chromium.org/130513003/diff/370001/sdk/lib/io/data_transformer.dart#newcode165
sdk/lib/io/data_transformer.dart:165: * (1 << (windowBits + 2)) + (1
<< (memLevel + 9))
Indent by four spaces and put an empty line before this to make it a
"blockquote" code block.
https://codereview.chromium.org/130513003/diff/370001/sdk/lib/io/data_transformer.dart#newcode173
sdk/lib/io/data_transformer.dart:173: * STRATEGY_HUFFMAN_ONLY to force
Huffman encoding only (no string match), or
Use full names (ZLIB_*) for constants.
Use either [ZLIB_STRATEGY_DEFAULT] or `ZLIB_STRATEGY_DEFAULT` to refer
to the constant, preferably the former at least the first time it is
used in a doc-comment.
https://codereview.chromium.org/130513003/diff/370001/sdk/lib/io/data_transformer.dart#newcode204
sdk/lib/io/data_transformer.dart:204: this.windowBits:
ZLIB_DFT_WINDOW_BITS,
Arguably, I'd indent the lines so that "this" matches up with the one
above.
https://codereview.chromium.org/130513003/diff/370001/sdk/lib/io/data_transformer.dart#newcode221
sdk/lib/io/data_transformer.dart:221: dictionary: dictionary, raw: raw);
You can do the same const default constructor trick with ZLibEncoder
too, and return a const object here.
https://codereview.chromium.org/130513003/diff/370001/sdk/lib/io/data_transformer.dart#newcode242
sdk/lib/io/data_transformer.dart:242: * the default compression level.
Levels above `6` will have higher compression
long line.
https://codereview.chromium.org/130513003/diff/370001/sdk/lib/io/data_transformer.dart#newcode254
sdk/lib/io/data_transformer.dart:254: * (1 << (windowBits + 2)) + (1
<< (memLevel + 9))
Block-quote this.
https://codereview.chromium.org/130513003/diff/370001/sdk/lib/io/data_transformer.dart#newcode260
sdk/lib/io/data_transformer.dart:260: * Tunes the compression algorithm.
Use the value STRATEGY_DEFAULT for normal
Full constant references [ZLIB_STRATEGY_DEFAULT] (or, after introducing
ZLib: [Zlib.STATEGY_DEFAULT]).
https://codereview.chromium.org/130513003/diff/370001/sdk/lib/io/data_transformer.dart#newcode319
sdk/lib/io/data_transformer.dart:319: * Start a chunked conversion using
the options given to the ZLibEncoder
No need to remove '[' and ']'.
If you don't want a link, change them to backquotes: `ZLibEncoder`. We
generally format all code-names as code.
https://codereview.chromium.org/130513003/diff/370001/sdk/lib/io/data_transformer.dart#newcode365
sdk/lib/io/data_transformer.dart:365: ZLibDecoder({this.windowBits:
ZLIB_DFT_WINDOW_BITS, this.dictionary: null,
Could have const default constructor too.
https://codereview.chromium.org/130513003/diff/370001/sdk/lib/io/data_transformer.dart#newcode526
sdk/lib/io/data_transformer.dart:526: if (windowBits is! int ||
I wouldn't test for int-ness here. The type annotation already says it
must be an int.
Just to be devious, I might change one (or both) of the following
comparisons to have the integer constant first, so any non-num value
that gets in here in production mode will crash and burn.
Ditto for the next two as well.
https://codereview.chromium.org/130513003/diff/370001/sdk/lib/io/data_transformer.dart#newcode529
sdk/lib/io/data_transformer.dart:529: throw new
ArgumentError("'windowBits' must be in range "
You can also use
new RangeError.range(windowBits, ZLIB_MIN_WINDOW_BITS,
ZLIB_MAX_WINDOW_BITS)
here.
https://codereview.chromium.org/130513003/diff/370001/sdk/lib/io/data_transformer.dart#newcode553
sdk/lib/io/data_transformer.dart:553: var strategies =
<int>[ZLIB_STRATEGY_FILTERED, ZLIB_STRATEGY_HUFFMAN_ONLY,
Maybe make this list const. No need to allocate a new list every time
the function is called.
https://codereview.chromium.org/130513003/diff/370001/tests/standalone/io/zlib_test.dart
File tests/standalone/io/zlib_test.dart (right):
https://codereview.chromium.org/130513003/diff/370001/tests/standalone/io/zlib_test.dart#newcode35
tests/standalone/io/zlib_test.dart:35: Expect.listEquals([31, 139, 8, 0,
0, 0, 0, 0, 0, 3, 3, 0, 0, 0, 0, 0, 0, 0,
Long line.
https://codereview.chromium.org/130513003/