changeset 42042:aaececb4b066

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.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 27 Mar 2019 19:34:10 +0100
parents 3e47d1ec9da5
children 1fac9b931d46
files mercurial/utils/compression.py
diffstat 1 files changed, 12 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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: