barman.clients.cloud_compression module#

class barman.clients.cloud_compression.ChunkedCompressorView on GitHub#

Bases: object

Base class for all ChunkedCompressors

_abc_impl = <_abc._abc_data object>#
abstract add_chunk(data)View on GitHub#

Compresses the supplied data and returns all the compressed bytes.

Parameters:

data (bytes) – The chunk of data to be compressed

Returns:

The compressed data

Return type:

bytes

abstract decompress(data)View on GitHub#

Decompresses the supplied chunk of data and returns at least part of the uncompressed data.

Parameters:

data (bytes) – The chunk of data to be decompressed

Returns:

The decompressed data

Return type:

bytes

class barman.clients.cloud_compression.SnappyCompressorView on GitHub#

Bases: ChunkedCompressor

A ChunkedCompressor implementation based on python-snappy

__init__()View on GitHub#
_abc_impl = <_abc._abc_data object>#
add_chunk(data)View on GitHub#

Compresses the supplied data and returns all the compressed bytes.

Parameters:

data (bytes) – The chunk of data to be compressed

Returns:

The compressed data

Return type:

bytes

decompress(data)View on GitHub#

Decompresses the supplied chunk of data and returns at least part of the uncompressed data.

Parameters:

data (bytes) – The chunk of data to be decompressed

Returns:

The decompressed data

Return type:

bytes

barman.clients.cloud_compression._try_import_snappy()View on GitHub#
barman.clients.cloud_compression.compress(wal_file, compression)View on GitHub#

Compresses the supplied wal_file and returns a file-like object containing the compressed data. :param IOBase wal_file: A file-like object containing the WAL file data. :param str compression: The compression algorithm to apply. Can be one of:

bzip2, gzip, snappy, zstd, lz4, xz.

Returns:

The compressed data

Return type:

BytesIO

barman.clients.cloud_compression.decompress_to_file(blob, dest_file, compression)View on GitHub#

Decompresses the supplied blob of data into the dest_file file-like object using the specified compression.

Parameters:
  • blob (IOBase) – A file-like object containing the compressed data.

  • dest_file (IOBase) – A file-like object into which the uncompressed data should be written.

  • compression (str) – The compression algorithm to apply. Can be one of: bzip2, gzip, snappy, zstd, lz4, xz.

Return type:

None

barman.clients.cloud_compression.get_compressor(compression)View on GitHub#

Helper function which returns a ChunkedCompressor for the specified compression algorithm. Currently only snappy is supported. The other compression algorithms supported by barman cloud use the decompression built into TarFile.

Parameters:

compression (str) – The compression algorithm to use. Can be set to snappy or any compression supported by the TarFile mode string.

Returns:

A ChunkedCompressor capable of compressing and decompressing using the specified compression.

Return type:

ChunkedCompressor

barman.clients.cloud_compression.get_streaming_tar_mode(mode, compression)View on GitHub#

Helper function used in streaming uploads and downloads which appends the supplied compression to the raw filemode (either r or w) and returns the result. Any compression algorithms supported by barman-cloud but not Python TarFile are ignored so that barman-cloud can apply them itself.

Parameters:
  • mode (str) – The file mode to use, either r or w.

  • compression (str) – The compression algorithm to use. Can be set to snappy or any compression supported by the TarFile mode string.

Returns:

The full filemode for a streaming tar file

Return type:

str