Python Glossary Русский

Python 3.4+base64function

base64.a85encode()

Ascii85 and Base85

Encodes bytes as Ascii85: 5 characters per 4 bytes, denser than Base64. It is used in PostScript and PDF.

Syntax

base64.a85encode(b, *, foldspaces=False, wrapcol=0, pad=False, adobe=False)

The size grows by 25% versus 33% for Base64, but the alphabet includes quotes and the backslash, so the result is unsafe to put into JSON, a URL or a string literal without escaping. Four zero bytes collapse into a single 'z'. The Adobe-style '<~ … ~>' framing is added only with adobe=True.

Examples

import base64
print(base64.a85encode(b'hello'), base64.a85encode(b'hello', adobe=True))  # → b'BOu!rDZ' b'<~BOu!rDZ~>'
print(base64.a85encode(b'\0\0\0\0'))  # → b'z'
print(base64.a85encode(b'say "hi"'))  # → b"F('>:,%t[7" — кавычка внутри

See also

Open in the full glossarydocs.python.orgReport an inaccuracy