Skip to content

Commit f2ba1a4

Browse files
committed
add additional docs on base-85, refactor
1 parent 8d490b3 commit f2ba1a4

File tree

1 file changed

+40
-12
lines changed

1 file changed

+40
-12
lines changed

Doc/library/base64.rst

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,17 @@
1414
--------------
1515

1616
This module provides functions for encoding binary data to printable
17-
ASCII characters and decoding such encodings back to binary data.
18-
It provides encoding and decoding functions for the encodings specified in
19-
:rfc:`4648`, which defines the Base16, Base32, and Base64 algorithms,
20-
and for the de-facto standard Ascii85 and Base85 encodings.
21-
22-
The :rfc:`4648` encodings are suitable for encoding binary data so that it can be
23-
safely sent by email, used as parts of URLs, or included as part of an HTTP
24-
POST request. The encoding algorithm is not the same as the
25-
:program:`uuencode` program.
17+
ASCII characters and decoding such encodings back to binary data,
18+
such as :ref:`those specified in RFC 4648 <base_64_rfc_4648>` and
19+
:ref:`Base-85 encodings <base_64_base_85>`.
2620

2721
There are two interfaces provided by this module. The modern interface
2822
supports encoding :term:`bytes-like objects <bytes-like object>` to ASCII
2923
:class:`bytes`, and decoding :term:`bytes-like objects <bytes-like object>` or
3024
strings containing ASCII to :class:`bytes`. Both base-64 alphabets
3125
defined in :rfc:`4648` (normal, and URL- and filesystem-safe) are supported.
3226

33-
The legacy interface does not support decoding from strings, but it does
27+
The :ref:`legacy interface <base_64_legacy>` does not support decoding from strings, but it does
3428
provide functions for encoding and decoding to and from :term:`file objects
3529
<file object>`. It only supports the Base64 standard alphabet, and it adds
3630
newlines every 76 characters as per :rfc:`2045`. Note that if you are looking
@@ -46,7 +40,16 @@ package instead.
4640
Any :term:`bytes-like objects <bytes-like object>` are now accepted by all
4741
encoding and decoding functions in this module. Ascii85/Base85 support added.
4842

49-
The modern interface provides:
43+
44+
.. _base_64_rfc_4648:
45+
46+
RFC 4648 Encodings
47+
^^^^^^^^^^^^^^^^^^
48+
49+
The :rfc:`4648` encodings are suitable for encoding binary data so that it can be
50+
safely sent by email, used as parts of URLs, or included as part of an HTTP
51+
POST request. The encoding algorithm is not the same as the
52+
:program:`uuencode` program.
5053

5154
.. function:: b64encode(s, altchars=None)
5255

@@ -181,6 +184,28 @@ The modern interface provides:
181184
incorrectly padded or if there are non-alphabet characters present in the
182185
input.
183186

187+
.. _base_64_base_85:
188+
189+
Base 85 Encodings
190+
^^^^^^^^^^^^^^^^^
191+
192+
Base-85 encoding is not formally specified. Base-85 encoding is a de facto standard
193+
originating from the ASCII Base-85 Strings encoding defined by the
194+
`PostScript Language <https://web.archive.org/web/20161222092741/https://www.adobe.com/products/postscript/pdfs/PLRM.pdf>`_.
195+
196+
The Ascii85 and Base85 functions in this module are two implementations of
197+
the de facto standard. Which function you should use depends on how the other
198+
software you use implements the Base-85 encoding.
199+
200+
The two functions present in this module provide options
201+
to configure the encoding in the following ways:
202+
203+
* Whether to include enclosing `<~` and `~>` markers
204+
* Whether to include newline characters
205+
* The set of ASCII characters used for encoding
206+
* Handling of null bytes
207+
208+
Refer to the documentation of the individual functions for more information.
184209

185210
.. function:: a85encode(b, *, foldspaces=False, wrapcol=0, pad=False, adobe=False)
186211

@@ -262,7 +287,10 @@ The modern interface provides:
262287
.. versionadded:: 3.13
263288

264289

265-
The legacy interface:
290+
.. _base_64_legacy:
291+
292+
Legacy Interface
293+
^^^^^^^^^^^^^^^^
266294

267295
.. function:: decode(input, output)
268296

0 commit comments

Comments
 (0)