Changeset View
Changeset View
Standalone View
Standalone View
swh/objstorage/objstorage.py
# Copyright (C) 2015-2018 The Software Heritage developers | # Copyright (C) 2015-2018 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import abc | import abc | ||||
from itertools import dropwhile, islice | from itertools import dropwhile, islice | ||||
import bz2 | import bz2 | ||||
import gzip | |||||
import lzma | import lzma | ||||
import zlib | import zlib | ||||
from swh.model import hashutil | from swh.model import hashutil | ||||
from .exc import ObjNotFoundError | from .exc import ObjNotFoundError | ||||
Show All 23 Lines | |||||
class NullCompressor: | class NullCompressor: | ||||
def compress(self, data): | def compress(self, data): | ||||
return data | return data | ||||
def flush(self): | def flush(self): | ||||
return b'' | return b'' | ||||
class NullDecompressor: | |||||
def decompress(self, data): | |||||
return data | |||||
@property | |||||
def unused_data(self): | |||||
return b'' | |||||
decompressors = { | decompressors = { | ||||
'bz2': bz2.decompress, | 'bz2': bz2.BZ2Decompressor, | ||||
'lzma': lzma.decompress, | 'lzma': lzma.LZMADecompressor, | ||||
'gzip': gzip.decompress, | 'gzip': lambda: zlib.decompressobj(wbits=31), | ||||
'zlib': zlib.decompress, | 'zlib': zlib.decompressobj, | ||||
None: lambda x: x, | None: NullDecompressor, | ||||
} | } | ||||
compressors = { | compressors = { | ||||
'bz2': bz2.BZ2Compressor, | 'bz2': bz2.BZ2Compressor, | ||||
'lzma': lzma.LZMACompressor, | 'lzma': lzma.LZMACompressor, | ||||
'gzip': lambda: zlib.compressobj(wbits=31), | 'gzip': lambda: zlib.compressobj(wbits=31), | ||||
'zlib': zlib.compressobj, | 'zlib': zlib.compressobj, | ||||
None: NullCompressor, | None: NullCompressor, | ||||
} | } | ||||
▲ Show 20 Lines • Show All 271 Lines • Show Last 20 Lines |