compression: accept level management for zlib compression
We update the zlib related class to be support setting the compression level.
This changeset focus on updating the internal only. A way to configure this
level will be introduced in the next changeset.
--- a/mercurial/utils/compression.py Wed Mar 27 16:45:14 2019 +0100
+++ b/mercurial/utils/compression.py Wed Mar 27 19:34:10 2019 +0100
@@ -456,6 +456,10 @@
return _GzipCompressedStreamReader(fh)
class zlibrevlogcompressor(object):
+
+ def __init__(self, level=None):
+ self._level = level
+
def compress(self, data):
insize = len(data)
# Caller handles empty input case.
@@ -465,7 +469,10 @@
return None
elif insize <= 1000000:
- compressed = zlib.compress(data)
+ if self._level is None:
+ compressed = zlib.compress(data)
+ else:
+ compressed = zlib.compress(data, self._level)
if len(compressed) < insize:
return compressed
return None
@@ -474,7 +481,10 @@
# memory usage for large inputs. So do streaming compression
# on large inputs.
else:
- z = zlib.compressobj()
+ if self._level is None:
+ z = zlib.compressobj()
+ else:
+ z = zlib.compressobj(level=self._level)
parts = []
pos = 0
while pos < insize: