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>#
abstractmethod 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

abstractmethod 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

flush()View on GitHub#

Flushes any remaining compressed data and returns the final bytes.

This method should be called after all data has been compressed with add_chunk() to ensure any buffered data and end markers are written. The default implementation returns an empty bytes object.

Returns:

Any remaining compressed data

Return type:

bytes

class barman.clients.cloud_compression.Lz4CompressorView on GitHub#

Bases: ChunkedCompressor

A ChunkedCompressor implementation based on lz4.

Uses lz4.frame for streaming compression and decompression. The compressor maintains state across add_chunk() calls and requires flush() to be called at the end to write the frame end marker.

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

Compresses the supplied data and returns the compressed bytes.

On the first call, this initializes the lz4 frame and writes the header. Subsequent calls compress additional data within the same frame.

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 the uncompressed data.

The LZ4FrameDecompressor handles streaming decompression and buffering of partial frames automatically.

Parameters:

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

Returns:

The decompressed data

Return type:

bytes

flush()View on GitHub#

Flushes any remaining data and returns the frame end marker.

This must be called after all data has been compressed to ensure the lz4 frame is properly terminated. Subsequent calls return empty bytes.

Returns:

The frame end marker bytes

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.compress(wal_file, compression, compression_level)View on GitHub#

Compresses the supplied wal_file and returns a file-like object containing the compressed data.

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

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

  • str|int|None – The compression level for the specified algorithm.

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. Snappy and lz4 are 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, lz4, 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, lz4, or any compression supported by the TarFile mode string.

Returns:

The full filemode for a streaming tar file

Return type:

str