Add Compressor.detect(data) -> CompressBase impl

This commit is contained in:
Marian Beermann 2016-07-31 22:00:58 +02:00
parent c2c90645ad
commit 5433b1a1e4
1 changed files with 6 additions and 1 deletions

View File

@ -194,9 +194,14 @@ class Compressor:
return self.compressor.compress(data)
def decompress(self, data):
compressor_cls = self.detect(data)
return compressor_cls(**self.params).decompress(data)
@staticmethod
def detect(data):
hdr = bytes(data[:2]) # detect() does not work with memoryview
for cls in COMPRESSOR_LIST:
if cls.detect(hdr):
return cls(**self.params).decompress(data)
return cls
else:
raise ValueError('No decompressor for this data found: %r.', data[:2])