commit: e30ad8803d82f11776f2da55b6650dee715154fa Author: Michał Górny <mgorny <AT> gentoo <DOT> org> AuthorDate: Sat Jan 17 11:10:23 2015 +0000 Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> CommitDate: Sun Jan 18 18:04:24 2015 +0000 URL: http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=e30ad880
compression_probe: support lz4, lzip, lzop --- pym/portage/util/compression_probe.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pym/portage/util/compression_probe.py b/pym/portage/util/compression_probe.py index 1dc3547..74f74b1 100644 --- a/pym/portage/util/compression_probe.py +++ b/pym/portage/util/compression_probe.py @@ -14,14 +14,22 @@ from portage.exception import FileNotFound, PermissionDenied _decompressors = { "bzip2": "${PORTAGE_BUNZIP2_COMMAND:-${PORTAGE_BZIP2_COMMAND} -d}", "gzip": "gzip -d", + "lz4": "lz4 -d", + "lzip": "lzip -d", + "lzop": "lzop -d", "xz": "xz -d", } _compression_re = re.compile(b'^(' + b'(?P<bzip2>\x42\x5a\x68\x39)|' + b'(?P<gzip>\x1f\x8b)|' + + b'(?P<lz4>(?:\x04\x22\x4d\x18|\x02\x21\x4c\x18))|' + + b'(?P<lzip>LZIP)|' + + b'(?P<lzop>\x89LZO\x00\x0d\x0a\x1a\x0a)|' + b'(?P<xz>\xfd\x37\x7a\x58\x5a\x00))') +_max_compression_re_len = 9 + def compression_probe(f): """ Identify the compression type of a file. Returns one of the @@ -29,6 +37,9 @@ def compression_probe(f): bzip2 gzip + lz4 + lzip + lzop xz @param f: a file path, or file-like object @@ -59,7 +70,7 @@ def compression_probe(f): def _compression_probe_file(f): - m = _compression_re.match(f.read(6)) + m = _compression_re.match(f.read(_max_compression_re_len)) if m is not None: for k, v in m.groupdict().items(): if v is not None: