Gentoo Archives: gentoo-portage-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-portage-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-portage-dev] [PATCH] compression_probe: support lz4, lzip, lzop
Date: Sat, 17 Jan 2015 11:11:10
Message-Id: 1421493040-15079-1-git-send-email-mgorny@gentoo.org
1 ---
2 pym/portage/util/compression_probe.py | 13 ++++++++++++-
3 1 file changed, 12 insertions(+), 1 deletion(-)
4
5 diff --git a/pym/portage/util/compression_probe.py b/pym/portage/util/compression_probe.py
6 index 1dc3547..74f74b1 100644
7 --- a/pym/portage/util/compression_probe.py
8 +++ b/pym/portage/util/compression_probe.py
9 @@ -14,14 +14,22 @@ from portage.exception import FileNotFound, PermissionDenied
10 _decompressors = {
11 "bzip2": "${PORTAGE_BUNZIP2_COMMAND:-${PORTAGE_BZIP2_COMMAND} -d}",
12 "gzip": "gzip -d",
13 + "lz4": "lz4 -d",
14 + "lzip": "lzip -d",
15 + "lzop": "lzop -d",
16 "xz": "xz -d",
17 }
18
19 _compression_re = re.compile(b'^(' +
20 b'(?P<bzip2>\x42\x5a\x68\x39)|' +
21 b'(?P<gzip>\x1f\x8b)|' +
22 + b'(?P<lz4>(?:\x04\x22\x4d\x18|\x02\x21\x4c\x18))|' +
23 + b'(?P<lzip>LZIP)|' +
24 + b'(?P<lzop>\x89LZO\x00\x0d\x0a\x1a\x0a)|' +
25 b'(?P<xz>\xfd\x37\x7a\x58\x5a\x00))')
26
27 +_max_compression_re_len = 9
28 +
29 def compression_probe(f):
30 """
31 Identify the compression type of a file. Returns one of the
32 @@ -29,6 +37,9 @@ def compression_probe(f):
33
34 bzip2
35 gzip
36 + lz4
37 + lzip
38 + lzop
39 xz
40
41 @param f: a file path, or file-like object
42 @@ -59,7 +70,7 @@ def compression_probe(f):
43
44 def _compression_probe_file(f):
45
46 - m = _compression_re.match(f.read(6))
47 + m = _compression_re.match(f.read(_max_compression_re_len))
48 if m is not None:
49 for k, v in m.groupdict().items():
50 if v is not None:
51 --
52 2.2.1

Replies