mirror of https://github.com/borgbackup/borg.git
Add Compressor.detect(data) -> CompressBase impl
This commit is contained in:
parent
c2c90645ad
commit
5433b1a1e4
|
@ -194,9 +194,14 @@ class Compressor:
|
||||||
return self.compressor.compress(data)
|
return self.compressor.compress(data)
|
||||||
|
|
||||||
def decompress(self, 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
|
hdr = bytes(data[:2]) # detect() does not work with memoryview
|
||||||
for cls in COMPRESSOR_LIST:
|
for cls in COMPRESSOR_LIST:
|
||||||
if cls.detect(hdr):
|
if cls.detect(hdr):
|
||||||
return cls(**self.params).decompress(data)
|
return cls
|
||||||
else:
|
else:
|
||||||
raise ValueError('No decompressor for this data found: %r.', data[:2])
|
raise ValueError('No decompressor for this data found: %r.', data[:2])
|
||||||
|
|
Loading…
Reference in New Issue