📄 glib-base64-encoding.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"><title>Base64 Encoding</title><meta name="generator" content="DocBook XSL Stylesheets V1.73.2"><link rel="start" href="index.html" title="GLib Reference Manual"><link rel="up" href="glib-utilities.html" title="GLib Utilities"><link rel="prev" href="glib-Unicode-Manipulation.html" title="Unicode Manipulation"><link rel="next" href="glib-Data-Checksums.html" title="Data Checksums"><meta name="generator" content="GTK-Doc V1.9 (XML mode)"><link rel="stylesheet" href="style.css" type="text/css"><link rel="chapter" href="glib.html" title="GLib Overview"><link rel="chapter" href="glib-fundamentals.html" title="GLib Fundamentals"><link rel="chapter" href="glib-core.html" title="GLib Core Application Support"><link rel="chapter" href="glib-utilities.html" title="GLib Utilities"><link rel="chapter" href="glib-data-types.html" title="GLib Data Types"><link rel="chapter" href="tools.html" title="GLib Tools"><link rel="index" href="ix01.html" title="Index"><link rel="index" href="ix02.html" title="Index of deprecated symbols"><link rel="index" href="ix03.html" title="Index of new symbols in 2.2"><link rel="index" href="ix04.html" title="Index of new symbols in 2.4"><link rel="index" href="ix05.html" title="Index of new symbols in 2.6"><link rel="index" href="ix06.html" title="Index of new symbols in 2.8"><link rel="index" href="ix07.html" title="Index of new symbols in 2.10"><link rel="index" href="ix08.html" title="Index of new symbols in 2.12"><link rel="index" href="ix09.html" title="Index of new symbols in 2.14"><link rel="index" href="ix10.html" title="Index of new symbols in 2.16"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle"><td><a accesskey="p" href="glib-Unicode-Manipulation.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td><td><a accesskey="u" href="glib-utilities.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td><td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td><th width="100%" align="center">GLib Reference Manual</th><td><a accesskey="n" href="glib-Data-Checksums.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td></tr><tr><td colspan="5" class="shortcuts"><nobr><a href="#id3024734" class="shortcut">Top</a>  |  <a href="#id3024972" class="shortcut">Description</a></nobr></td></tr></table><div class="refentry" lang="en"><a name="glib-Base64-Encoding"></a><div class="titlepage"></div><div class="refnamediv"><table width="100%"><tr><td valign="top"><h2><a name="id3024734"></a><span class="refentrytitle">Base64 Encoding</span></h2><p>Base64 Encoding — encodes and decodes data in Base64 format</p></td><td valign="top" align="right"></td></tr></table></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">#include <glib.h><a class="link" href="glib-Basic-Types.html#gsize">gsize</a> <a class="link" href="glib-Base64-Encoding.html#g-base64-encode-step">g_base64_encode_step</a> (const <a class="link" href="glib-Basic-Types.html#guchar">guchar</a> *in, <a class="link" href="glib-Basic-Types.html#gsize">gsize</a> len, <a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a> break_lines, <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *out, <a class="link" href="glib-Basic-Types.html#gint">gint</a> *state, <a class="link" href="glib-Basic-Types.html#gint">gint</a> *save);<a class="link" href="glib-Basic-Types.html#gsize">gsize</a> <a class="link" href="glib-Base64-Encoding.html#g-base64-encode-close">g_base64_encode_close</a> (<a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a> break_lines, <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *out, <a class="link" href="glib-Basic-Types.html#gint">gint</a> *state, <a class="link" href="glib-Basic-Types.html#gint">gint</a> *save);<a class="link" href="glib-Basic-Types.html#gchar">gchar</a>* <a class="link" href="glib-Base64-Encoding.html#g-base64-encode">g_base64_encode</a> (const <a class="link" href="glib-Basic-Types.html#guchar">guchar</a> *data, <a class="link" href="glib-Basic-Types.html#gsize">gsize</a> len);<a class="link" href="glib-Basic-Types.html#gsize">gsize</a> <a class="link" href="glib-Base64-Encoding.html#g-base64-decode-step">g_base64_decode_step</a> (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *in, <a class="link" href="glib-Basic-Types.html#gsize">gsize</a> len, <a class="link" href="glib-Basic-Types.html#guchar">guchar</a> *out, <a class="link" href="glib-Basic-Types.html#gint">gint</a> *state, <a class="link" href="glib-Basic-Types.html#guint">guint</a> *save);<a class="link" href="glib-Basic-Types.html#guchar">guchar</a>* <a class="link" href="glib-Base64-Encoding.html#g-base64-decode">g_base64_decode</a> (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *text, <a class="link" href="glib-Basic-Types.html#gsize">gsize</a> *out_len);</pre></div><div class="refsect1" lang="en"><a name="id3024972"></a><h2>Description</h2><p>Base64 is an encoding that allows to encode a sequence of arbitrarybytes as a sequence of printable ASCII characters. For the definitionof Base64, see <a class="ulink" href="http://www.ietf.org/rfc/rfc1421.txt" target="_top">RFC 1421</a> or <a class="ulink" href="http://www.ietf.org/rfc/rfc2045.txt" target="_top">RFC2045</a>. Base64 is most commonly used as a MIME transfer encodingfor email.</p><p>GLib supports incremental encoding using <a class="link" href="glib-Base64-Encoding.html#g-base64-encode-step"><code class="function">g_base64_encode_step()</code></a> and<a class="link" href="glib-Base64-Encoding.html#g-base64-encode-close"><code class="function">g_base64_encode_close()</code></a>. Incremental decoding can be done with<a class="link" href="glib-Base64-Encoding.html#g-base64-decode-step"><code class="function">g_base64_decode_step()</code></a>. To encode or decode data in one go, use <a class="link" href="glib-Base64-Encoding.html#g-base64-encode"><code class="function">g_base64_encode()</code></a> or <a class="link" href="glib-Base64-Encoding.html#g-base64-decode"><code class="function">g_base64_decode()</code></a>. </p><p>Support for Base64 encoding has been added in GLib 2.12.</p></div><div class="refsect1" lang="en"><a name="id3025067"></a><h2>Details</h2><div class="refsect2" lang="en"><a name="id3025077"></a><h3><a name="g-base64-encode-step"></a>g_base64_encode_step ()</h3><a class="indexterm" name="id3025093"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gsize">gsize</a> g_base64_encode_step (const <a class="link" href="glib-Basic-Types.html#guchar">guchar</a> *in, <a class="link" href="glib-Basic-Types.html#gsize">gsize</a> len, <a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a> break_lines, <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *out, <a class="link" href="glib-Basic-Types.html#gint">gint</a> *state, <a class="link" href="glib-Basic-Types.html#gint">gint</a> *save);</pre><p>Incrementally encode a sequence of binary data into it's Base-64 stringifiedrepresentation. By calling this function multiple times you can convert data in chunks to avoid having to have the full encoded data in memory.</p><p>When all of the data has been converted you must call <a class="link" href="glib-Base64-Encoding.html#g-base64-encode-close"><code class="function">g_base64_encode_close()</code></a> to flush the saved state.</p><p>The output buffer must be large enough to fit all the data that willbe written to it. Due to the way base64 encodes you will needat least: <em class="parameter"><code>len</code></em> * 4 / 3 + 6 bytes. If you enable line-breaking you willneed at least: <em class="parameter"><code>len</code></em> * 4 / 3 + <em class="parameter"><code>len</code></em> * 4 / (3 * 72) + 7 bytes.</p><p><em class="parameter"><code>break_lines</code></em> is typically used when putting base64-encoded data in emails.It breaks the lines at 72 columns instead of putting all of the text on the same line. This avoids problems with long lines in the email system.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>in</code></em> :</span></p></td><td> the binary data to encode</td></tr><tr><td><p><span class="term"><em class="parameter"><code>len</code></em> :</span></p></td><td> the length of <em class="parameter"><code>in</code></em></td></tr><tr><td><p><span class="term"><em class="parameter"><code>break_lines</code></em> :</span></p></td><td> whether to break long lines</td></tr><tr><td><p><span class="term"><em class="parameter"><code>out</code></em> :</span></p></td><td> pointer to destination buffer</td></tr><tr><td><p><span class="term"><em class="parameter"><code>state</code></em> :</span></p></td><td> Saved state between steps, initialize to 0</td></tr><tr><td><p><span class="term"><em class="parameter"><code>save</code></em> :</span></p></td><td> Saved state between steps, initialize to 0</td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td><td> The number of bytes of output that was written</td></tr></tbody></table></div><p class="since">Since 2.12</p></div><hr><div class="refsect2" lang="en"><a name="id3025332"></a><h3><a name="g-base64-encode-close"></a>g_base64_encode_close ()</h3><a class="indexterm" name="id3025348"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gsize">gsize</a> g_base64_encode_close (<a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a> break_lines, <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *out, <a class="link" href="glib-Basic-Types.html#gint">gint</a> *state,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -