Browse Source

for zero compression (and decompression), avoid going through zlib

for level 0, zlib.compress is still at some cost, it doesn't just give back the data 1:1.
in fact, it even does add some overhead, creating larger output than input.

thus, it is replaced by NullCompressor, which really does nothing.
Thomas Waldmann 10 years ago
parent
commit
99daa2794d
2 changed files with 18 additions and 5 deletions
  1. 3 2
      attic/archiver.py
  2. 15 3
      attic/key.py

+ 3 - 2
attic/archiver.py

@@ -484,8 +484,9 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
 
         --compression METHODs (default: %02d):
 
-        - 00..09  zlib levels 0..9 (0 means no compression, 9 max. compression)
-        - 10..19  lzma levels 0..9 (0 means no compression, 9 max. compression)
+        - 00      no compression
+        - 01..09  zlib levels 1..9 (1 means low compression, 9 max. compression)
+        - 10..19  lzma levels 0..9 (0 means low compression, 9 max. compression)
 
         --cipher METHODs (default: %02d or %02d)
 

+ 15 - 3
attic/key.py

@@ -151,7 +151,17 @@ MAC_DEFAULT = GMAC.TYPE
 # compressor classes, all same interface
 # special case: zlib level 0 is "no compression"
 
-class ZlibCompressor(object):  # uses 0..9 in the mapping
+class NullCompressor(object):  # uses 0 in the mapping
+    TYPE = 0
+
+    def compress(self, data):
+        return bytes(data)
+
+    def decompress(self, data):
+        return bytes(data)
+
+
+class ZlibCompressor(object):  # uses 1..9 in the mapping
     TYPE = 0
     LEVELS = range(10)
 
@@ -179,8 +189,8 @@ class LzmaCompressor(object):  # uses 10..19 in the mapping
         return lzma.decompress(data)
 
 
-# default is optimized for speed (and a little compression)
-COMPR_DEFAULT = ZlibCompressor.TYPE + 1 # zlib level 1
+# default is optimized for speed
+COMPR_DEFAULT = NullCompressor.TYPE # no compression
 
 
 # ciphers - AEAD (authenticated encryption with assoc. data) style interface
@@ -559,6 +569,8 @@ for level in ZlibCompressor.LEVELS:
 for preset in LzmaCompressor.PRESETS:
     compressor_mapping[LzmaCompressor.TYPE + preset] = \
         type('LzmaCompressorPreset%d' % preset, (LzmaCompressor, ), dict(TYPE=LzmaCompressor.TYPE + preset))
+# overwrite 0 with NullCompressor
+compressor_mapping[NullCompressor.TYPE] = NullCompressor
 
 
 keyer_mapping = {