Gzip in Python

From NovaOrdis Knowledge Base
Jump to navigation Jump to search

Internal

Overview

Compress

import gzip
yaml = ...
compressed = gzip.compress(bytes(yaml), 'utf-8')

Uncompress

import gzip
binary_data =
uncompressed_binary = gzip.decompress(binary_data)

#
# if data is compressed text
#
uncompressed_text = gzip.decompress(binary_data).decode('utf-8')