1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19  
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 /*
25  * Conversion parameters:
26  * inFile  = glib-Base64-Encoding.html
27  * outPack = glib
28  * outFile = Base64
29  * strct   = 
30  * realStrct=
31  * ctorStrct=
32  * clss    = Base64
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_base64_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.Str
47  * structWrap:
48  * module aliases:
49  * local aliases:
50  * overrides:
51  */
52 
53 module glib.Base64;
54 
55 public  import gtkc.glibtypes;
56 
57 private import gtkc.glib;
58 private import glib.ConstructionException;
59 
60 
61 private import glib.Str;
62 
63 
64 
65 
66 /**
67  * Base64 is an encoding that allows a sequence of arbitrary bytes to be
68  * encoded as a sequence of printable ASCII characters. For the definition
69  * of Base64, see RFC
70  * 1421 or RFC
71  * 2045. Base64 is most commonly used as a MIME transfer encoding
72  * for email.
73  *
74  * GLib supports incremental encoding using g_base64_encode_step() and
75  * g_base64_encode_close(). Incremental decoding can be done with
76  * g_base64_decode_step(). To encode or decode data in one go, use
77  * g_base64_encode() or g_base64_decode(). To avoid memory allocation when
78  * decoding, you can use g_base64_decode_inplace().
79  *
80  * Support for Base64 encoding has been added in GLib 2.12.
81  */
82 public class Base64
83 {
84 	
85 	/**
86 	 */
87 	
88 	/**
89 	 * Incrementally encode a sequence of binary data into its Base-64 stringified
90 	 * representation. By calling this function multiple times you can convert
91 	 * data in chunks to avoid having to have the full encoded data in memory.
92 	 * When all of the data has been converted you must call
93 	 * g_base64_encode_close() to flush the saved state.
94 	 * The output buffer must be large enough to fit all the data that will
95 	 * be written to it. Due to the way base64 encodes you will need
96 	 * at least: (len / 3 + 1) * 4 + 4 bytes (+ 4 may be needed in case of
97 	 * Since 2.12
98 	 * Params:
99 	 * in = the binary data to encode. [array length=len][element-type guint8]
100 	 * breakLines = whether to break long lines
101 	 * out = pointer to destination buffer. [out][array][element-type guint8]
102 	 * state = Saved state between steps, initialize to 0. [inout]
103 	 * save = Saved state between steps, initialize to 0. [inout]
104 	 * Returns: The number of bytes of output that was written
105 	 */
106 	public static gsize encodeStep(char[] inn, int breakLines, string f_out, ref int state, ref int save)
107 	{
108 		// gsize g_base64_encode_step (const guchar *in,  gsize len,  gboolean break_lines,  gchar *out,  gint *state,  gint *save);
109 		return g_base64_encode_step(inn.ptr, cast(int) inn.length, breakLines, Str.toStringz(f_out), &state, &save);
110 	}
111 	
112 	/**
113 	 * Flush the status from a sequence of calls to g_base64_encode_step().
114 	 * The output buffer must be large enough to fit all the data that will
115 	 * be written to it. It will need up to 4 bytes, or up to 5 bytes if
116 	 * line-breaking is enabled.
117 	 * Since 2.12
118 	 * Params:
119 	 * breakLines = whether to break long lines
120 	 * out = pointer to destination buffer. [out][array][element-type guint8]
121 	 * state = Saved state from g_base64_encode_step(). [inout]
122 	 * save = Saved state from g_base64_encode_step(). [inout]
123 	 * Returns: The number of bytes of output that was written
124 	 */
125 	public static gsize encodeClose(int breakLines, string f_out, ref int state, ref int save)
126 	{
127 		// gsize g_base64_encode_close (gboolean break_lines,  gchar *out,  gint *state,  gint *save);
128 		return g_base64_encode_close(breakLines, Str.toStringz(f_out), &state, &save);
129 	}
130 	
131 	/**
132 	 * Encode a sequence of binary data into its Base-64 stringified
133 	 * representation.
134 	 * Since 2.12
135 	 * Params:
136 	 * data = the binary data to encode. [array length=len][element-type guint8]
137 	 * Returns: a newly allocated, zero-terminated Base-64 encoded string representing data. The returned string must be freed with g_free(). [transfer full]
138 	 */
139 	public static string encode(char[] data)
140 	{
141 		// gchar * g_base64_encode (const guchar *data,  gsize len);
142 		return Str.toString(g_base64_encode(data.ptr, cast(int) data.length));
143 	}
144 	
145 	/**
146 	 * Incrementally decode a sequence of binary data from its Base-64 stringified
147 	 * representation. By calling this function multiple times you can convert
148 	 * data in chunks to avoid having to have the full encoded data in memory.
149 	 * The output buffer must be large enough to fit all the data that will
150 	 * be written to it. Since base64 encodes 3 bytes in 4 chars you need
151 	 * at least: (len / 4) * 3 + 3 bytes (+ 3 may be needed in case of non-zero
152 	 * state).
153 	 * Since 2.12
154 	 * Params:
155 	 * in = binary input data. [array length=len][element-type guint8]
156 	 * out = output buffer. [out][array][element-type guint8]
157 	 * state = Saved state between steps, initialize to 0. [inout]
158 	 * save = Saved state between steps, initialize to 0. [inout]
159 	 * Returns: The number of bytes of output that was written
160 	 */
161 	public static gsize decodeStep(string inn, char* f_out, ref int state, ref uint save)
162 	{
163 		// gsize g_base64_decode_step (const gchar *in,  gsize len,  guchar *out,  gint *state,  guint *save);
164 		return g_base64_decode_step(cast(char*)inn.ptr, cast(int) inn.length, f_out, &state, &save);
165 	}
166 	
167 	/**
168 	 * Decode a sequence of Base-64 encoded text into binary data. Note
169 	 * that the returned binary data is not necessarily zero-terminated,
170 	 * so it should not be used as a character string.
171 	 * Since 2.12
172 	 * Params:
173 	 * text = zero-terminated string with base64 text to decode
174 	 * Returns: newly allocated buffer containing the binary data that text represents. The returned buffer must be freed with g_free(). [transfer full][array length=out_len][element-type guint8]
175 	 */
176 	public static char[] decode(string text)
177 	{
178 		// guchar * g_base64_decode (const gchar *text,  gsize *out_len);
179 		gsize outLen;
180 		auto p = g_base64_decode(Str.toStringz(text), &outLen);
181 		
182 		if(p is null)
183 		{
184 			return null;
185 		}
186 		
187 		return p[0 .. outLen];
188 	}
189 	
190 	/**
191 	 * Decode a sequence of Base-64 encoded text into binary data
192 	 * by overwriting the input data.
193 	 * Since 2.20
194 	 * Params:
195 	 * text = zero-terminated
196 	 * string with base64 text to decode. [inout][array length=out_len][element-type guint8]
197 	 * Returns: The binary data that text responds. This pointer is the same as the input text. [transfer none]
198 	 */
199 	public static char[] decodeInplace(string text)
200 	{
201 		// guchar * g_base64_decode_inplace (gchar *text,  gsize *out_len);
202 		gsize outLen;
203 		auto p = g_base64_decode_inplace(Str.toStringz(text), &outLen);
204 		
205 		if(p is null)
206 		{
207 			return null;
208 		}
209 		
210 		return p[0 .. outLen];
211 	}
212 }