From 12c89ebaf67b5a55ea23af3ed47038968870f309 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Thu, 21 Feb 2013 17:33:27 +0100 Subject: move compression functions to module dedup.compression --- importpkg.py | 87 ++---------------------------------------------------------- 1 file changed, 2 insertions(+), 85 deletions(-) (limited to 'importpkg.py') diff --git a/importpkg.py b/importpkg.py index eb3b3ec..89020b9 100755 --- a/importpkg.py +++ b/importpkg.py @@ -19,6 +19,7 @@ from debian import deb822 import lzma from dedup.hashing import HashBlacklist, DecompressedHash, SuppressingHash, hash_file +from dedup.compression import GzipDecompressor, DecompressedStream class ArReader(object): global_magic = b"!\n" @@ -72,31 +73,6 @@ class ArReader(object): self.remaining -= len(data) return data -class XzStream(object): - blocksize = 65536 - - def __init__(self, fileobj): - self.fileobj = fileobj - self.decomp = lzma.LZMADecompressor() - self.buff = b"" - - def read(self, length): - data = True - while True: - if len(self.buff) >= length: - ret = self.buff[:length] - self.buff = self.buff[length:] - return ret - elif not data: # read EOF in last iteration - ret = self.buff - self.buff = b"" - return ret - data = self.fileobj.read(self.blocksize) - if data: - self.buff += self.decomp.decompress(data) - else: - self.buff += self.decomp.flush() - class MultiHash(object): def __init__(self, *hashes): self.hashes = hashes @@ -105,65 +81,6 @@ class MultiHash(object): for hasher in self.hashes: hasher.update(data) -class GzipDecompressor(object): - def __init__(self): - self.inbuffer = b"" - self.decompressor = None # zlib.decompressobj(-zlib.MAX_WBITS) - - def decompress(self, data): - if self.decompressor: - data = self.decompressor.decompress(data) - if not self.decompressor.unused_data: - return data - unused_data = self.decompressor.unused_data - self.decompressor = None - return data + self.decompress(unused_data) - self.inbuffer += data - skip = 10 - if len(self.inbuffer) < skip: - return b"" - if not self.inbuffer.startswith(b"\037\213\010"): - raise ValueError("gzip magic not found") - flag = ord(self.inbuffer[3]) - if flag & 4: - if len(self.inbuffer) < skip + 2: - return b"" - length, = struct.unpack("