Gzip in Python: Difference between revisions
Jump to navigation
Jump to search
(Created page with "=Internal= * Python Code Examples") |
|||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
=Internal= | =Internal= | ||
* [[Python_Code_Examples#Code_Examples|Python Code Examples]] | * [[Python_Code_Examples#Code_Examples|Python Code Examples]] | ||
=Overview= | |||
=Compress= | |||
<syntaxhighlight lang='py'> | |||
import gzip | |||
yaml = ... | |||
compressed = gzip.compress(bytes(yaml), 'utf-8') | |||
</syntaxhighlight> | |||
=Uncompress= | |||
<syntaxhighlight lang='py'> | |||
import gzip | |||
binary_data = | |||
uncompressed_binary = gzip.decompress(binary_data) | |||
# | |||
# if data is compressed text | |||
# | |||
uncompressed_text = gzip.decompress(binary_data).decode('utf-8') | |||
</syntaxhighlight> |
Latest revision as of 05:36, 10 June 2022
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')