changeset 30368:38130a0bbb99

hgweb: use compression engine API for zlib compression More low-level compression code elimination because we now have nice APIs. This patch also demonstrates why we needed and implemented the "level" option on the "compressstream" API.
author Gregory Szorc <gregory.szorc@gmail.com>
date Mon, 07 Nov 2016 18:54:35 -0800
parents 5925bda42dbd
children 673f0fdc1046
files mercurial/hgweb/protocol.py
diffstat 1 files changed, 2 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hgweb/protocol.py	Mon Nov 07 18:46:37 2016 -0800
+++ b/mercurial/hgweb/protocol.py	Mon Nov 07 18:54:35 2016 -0800
@@ -88,14 +88,8 @@
         # Don't allow untrusted settings because disabling compression or
         # setting a very high compression level could lead to flooding
         # the server's network or CPU.
-        z = zlib.compressobj(self.ui.configint('server', 'zliblevel', -1))
-        for chunk in chunks:
-            data = z.compress(chunk)
-            # Not all calls to compress() emit data. It is cheaper to inspect
-            # that here than to send it via the generator.
-            if data:
-                yield data
-        yield z.flush()
+        opts = {'level': self.ui.configint('server', 'zliblevel', -1)}
+        return util.compengines['zlib'].compressstream(chunks, opts)
 
     def _client(self):
         return 'remote:%s:%s:%s' % (