blob: aa68c044646110a01c20471a260640baecf276b2 [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{base64} ---
2 Encode and decode MIME base64 encoding.}
Fred Drakeb91e9341998-07-23 17:59:49 +00003\declaremodule{standard}{base64}
4
Fred Drake295da241998-08-10 19:42:37 +00005\modulesynopsis{Encode and decode files using the MIME base64
6encoding.}
Fred Drakeb91e9341998-07-23 17:59:49 +00007
Fred Drake674e0fd1998-04-02 16:24:29 +00008\indexii{base64}{encoding}
9\index{MIME!base64 encoding}
Guido van Rossume76b7a81997-04-27 21:25:52 +000010
Fred Drake6a50ba81998-05-22 18:19:19 +000011This module performs base64 encoding and decoding of arbitrary binary
Guido van Rossume76b7a81997-04-27 21:25:52 +000012strings into text strings that can be safely emailed or posted. The
Fred Drake674e0fd1998-04-02 16:24:29 +000013encoding scheme is defined in \rfc{1421} (``Privacy Enhancement for
14Internet Electronic Mail: Part I: Message Encryption and
15Authentication Procedures'', section 4.3.2.4, ``Step 4: Printable
16Encoding'') and is used for MIME email and
Guido van Rossume76b7a81997-04-27 21:25:52 +000017various other Internet-related applications; it is not the same as the
Fred Drake674e0fd1998-04-02 16:24:29 +000018output produced by the \program{uuencode} program. For example, the
Guido van Rossume76b7a81997-04-27 21:25:52 +000019string \code{'www.python.org'} is encoded as the string
20\code{'d3d3LnB5dGhvbi5vcmc=\e n'}.
Guido van Rossume76b7a81997-04-27 21:25:52 +000021
Fred Drake798654f1997-11-30 05:53:22 +000022
Fred Drake79948431998-01-07 03:47:10 +000023\begin{funcdesc}{decode}{input, output}
Guido van Rossume76b7a81997-04-27 21:25:52 +000024Decode the contents of the \var{input} file and write the resulting
25binary data to the \var{output} file.
26\var{input} and \var{output} must either be file objects or objects that
27mimic the file object interface. \var{input} will be read until
28\code{\var{input}.read()} returns an empty string.
29\end{funcdesc}
30
31\begin{funcdesc}{decodestring}{s}
32Decode the string \var{s}, which must contain one or more lines of
Fred Drake674e0fd1998-04-02 16:24:29 +000033base64 encoded data, and return a string containing the resulting
Guido van Rossume76b7a81997-04-27 21:25:52 +000034binary data.
35\end{funcdesc}
36
Fred Drake79948431998-01-07 03:47:10 +000037\begin{funcdesc}{encode}{input, output}
Guido van Rossume76b7a81997-04-27 21:25:52 +000038Encode the contents of the \var{input} file and write the resulting
Fred Drake674e0fd1998-04-02 16:24:29 +000039base64 encoded data to the \var{output} file.
Guido van Rossume76b7a81997-04-27 21:25:52 +000040\var{input} and \var{output} must either be file objects or objects that
41mimic the file object interface. \var{input} will be read until
42\code{\var{input}.read()} returns an empty string.
43\end{funcdesc}
44
45\begin{funcdesc}{encodestring}{s}
46Encode the string \var{s}, which can contain arbitrary binary data,
47and return a string containing one or more lines of
Fred Drake674e0fd1998-04-02 16:24:29 +000048base64 encoded data.
Guido van Rossume76b7a81997-04-27 21:25:52 +000049\end{funcdesc}