blob: 2d34e1d8208f7e9f6da76fa0d4b83570a5ff7188 [file] [log] [blame]
Fred Drake674e0fd1998-04-02 16:24:29 +00001\section{Standard Module \module{base64}}
Fred Drakeb91e9341998-07-23 17:59:49 +00002\declaremodule{standard}{base64}
3
4\modulesynopsis{Encode/decode binary files using the MIME base64 encoding.}
5
Fred Drake674e0fd1998-04-02 16:24:29 +00006\indexii{base64}{encoding}
7\index{MIME!base64 encoding}
Guido van Rossume76b7a81997-04-27 21:25:52 +00008
Fred Drake6a50ba81998-05-22 18:19:19 +00009This module performs base64 encoding and decoding of arbitrary binary
Guido van Rossume76b7a81997-04-27 21:25:52 +000010strings into text strings that can be safely emailed or posted. The
Fred Drake674e0fd1998-04-02 16:24:29 +000011encoding scheme is defined in \rfc{1421} (``Privacy Enhancement for
12Internet Electronic Mail: Part I: Message Encryption and
13Authentication Procedures'', section 4.3.2.4, ``Step 4: Printable
14Encoding'') and is used for MIME email and
Guido van Rossume76b7a81997-04-27 21:25:52 +000015various other Internet-related applications; it is not the same as the
Fred Drake674e0fd1998-04-02 16:24:29 +000016output produced by the \program{uuencode} program. For example, the
Guido van Rossume76b7a81997-04-27 21:25:52 +000017string \code{'www.python.org'} is encoded as the string
18\code{'d3d3LnB5dGhvbi5vcmc=\e n'}.
Guido van Rossume76b7a81997-04-27 21:25:52 +000019
Fred Drake798654f1997-11-30 05:53:22 +000020
Fred Drake79948431998-01-07 03:47:10 +000021\begin{funcdesc}{decode}{input, output}
Guido van Rossume76b7a81997-04-27 21:25:52 +000022Decode the contents of the \var{input} file and write the resulting
23binary data to the \var{output} file.
24\var{input} and \var{output} must either be file objects or objects that
25mimic the file object interface. \var{input} will be read until
26\code{\var{input}.read()} returns an empty string.
27\end{funcdesc}
28
29\begin{funcdesc}{decodestring}{s}
30Decode the string \var{s}, which must contain one or more lines of
Fred Drake674e0fd1998-04-02 16:24:29 +000031base64 encoded data, and return a string containing the resulting
Guido van Rossume76b7a81997-04-27 21:25:52 +000032binary data.
33\end{funcdesc}
34
Fred Drake79948431998-01-07 03:47:10 +000035\begin{funcdesc}{encode}{input, output}
Guido van Rossume76b7a81997-04-27 21:25:52 +000036Encode the contents of the \var{input} file and write the resulting
Fred Drake674e0fd1998-04-02 16:24:29 +000037base64 encoded data to the \var{output} file.
Guido van Rossume76b7a81997-04-27 21:25:52 +000038\var{input} and \var{output} must either be file objects or objects that
39mimic the file object interface. \var{input} will be read until
40\code{\var{input}.read()} returns an empty string.
41\end{funcdesc}
42
43\begin{funcdesc}{encodestring}{s}
44Encode the string \var{s}, which can contain arbitrary binary data,
45and return a string containing one or more lines of
Fred Drake674e0fd1998-04-02 16:24:29 +000046base64 encoded data.
Guido van Rossume76b7a81997-04-27 21:25:52 +000047\end{funcdesc}