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 26 Lines | class NullCompressor: | ||||
def flush(self): | def flush(self): | ||||
return b'' | return b'' | ||||
decompressors = { | decompressors = { | ||||
'bz2': bz2.decompress, | 'bz2': bz2.decompress, | ||||
'lzma': lzma.decompress, | 'lzma': lzma.decompress, | ||||
'gzip': gzip.decompress, | |||||
'zlib': zlib.decompress, | 'zlib': zlib.decompress, | ||||
None: lambda x: x, | None: lambda x: x, | ||||
} | } | ||||
compressors = { | compressors = { | ||||
'bz2': bz2.BZ2Compressor, | 'bz2': bz2.BZ2Compressor, | ||||
'lzma': lzma.LZMACompressor, | 'lzma': lzma.LZMACompressor, | ||||
'gzip': lambda: zlib.compressobj(wbits=31), | |||||
'zlib': zlib.compressobj, | 'zlib': zlib.compressobj, | ||||
None: NullCompressor, | None: NullCompressor, | ||||
} | } | ||||
class ObjStorage(metaclass=abc.ABCMeta): | class ObjStorage(metaclass=abc.ABCMeta): | ||||
""" High-level API to manipulate the Software Heritage object storage. | """ High-level API to manipulate the Software Heritage object storage. | ||||
▲ Show 20 Lines • Show All 266 Lines • Show Last 20 Lines |