diff options
author | Henri Sivonen <hsivonen@hsivonen.fi> | 2015-10-17 20:37:55 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2015-10-19 22:13:20 +0300 |
commit | d884dfa978bbcbaa18c8f0548172e0cad111ecee (patch) | |
tree | f8b594190459dde51d2c739953165458f7ecc4e9 | |
parent | 5f1da1126eee0c3326c194b38d88197c821fafe9 (diff) | |
download | obnam-d884dfa978bbcbaa18c8f0548172e0cad111ecee.tar.gz |
Avoid storing compressed data when the tagged compressed data would be longer than the uncompressed data.
-rw-r--r-- | obnamlib/plugins/compression_plugin.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/obnamlib/plugins/compression_plugin.py b/obnamlib/plugins/compression_plugin.py index a9eb2d21..eba3210d 100644 --- a/obnamlib/plugins/compression_plugin.py +++ b/obnamlib/plugins/compression_plugin.py @@ -31,14 +31,21 @@ class DeflateCompressionFilter(object): def filter_write(self, data, repo, toplevel): how = self.app.settings['compress-with'] + compressed = None if how == 'deflate': - data = zlib.compress(data) + compressed = zlib.compress(data) elif how == 'gzip': if not self.warned: self.app.ts.notify("--compress-with=gzip is deprecated. " + "Use --compress-with=deflate instead") self.warned = True - data = zlib.compress(data) + compressed = zlib.compress(data) + + # If the compression result, the tag and the separator byte taken + # together are longer than the uncompressed input, let's store the + # uncompressed data to avoid waste upon transfer, storage and read. + if compressed and len(compressed) + len(self.tag) + 1 < len(data): + return compressed return data |