source: appstream-generator/build/girepo/glib/Base64.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

File size: 6.0 KB
Line 
1/*
2 * Licensed under the GNU Lesser General Public License Version 3
3 *
4 * This library is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the license, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18// generated automatically - do not change
19
20
21module glib.Base64;
22
23private import gi.glib;
24public  import gi.glibtypes;
25private import glib.Str;
26
27
28/** */
29public struct Base64
30{
31        /**
32         * Incrementally decode a sequence of binary data from its Base-64 stringified
33         * representation. By calling this function multiple times you can convert
34         * data in chunks to avoid having to have the full encoded data in memory.
35         *
36         * The output buffer must be large enough to fit all the data that will
37         * be written to it. Since base64 encodes 3 bytes in 4 chars you need
38         * at least: (@len / 4) * 3 + 3 bytes (+ 3 may be needed in case of non-zero
39         * state).
40         *
41         * Params:
42         *     inn = binary input data
43         *     len = max length of @in data to decode
44         *     output = output buffer
45         *     state = Saved state between steps, initialize to 0
46         *     save = Saved state between steps, initialize to 0
47         *
48         * Return: The number of bytes of output that was written
49         *
50         * Since: 2.12
51         */
52        public static size_t decodeStep(string inn, ref ubyte[] output, ref int state, ref uint save)
53        {
54                auto p = g_base64_decode_step(Str.toStringz(inn), cast(int)inn.length, cast(char*)output.ptr, &state, &save);
55               
56                return p;
57        }
58
59        /**
60         */
61
62        /**
63         * Decode a sequence of Base-64 encoded text into binary data
64         * by overwriting the input data.
65         *
66         * Params:
67         *     text = zero-terminated
68         *         string with base64 text to decode
69         *
70         * Returns: The binary data that @text responds. This pointer
71         *     is the same as the input @text.
72         *
73         * Since: 2.20
74         */
75        public static char[] decodeInplace(ref char[] text)
76        {
77                size_t outLen = cast(size_t)text.length;
78               
79                auto p = g_base64_decode_inplace(text.ptr, &outLen);
80               
81                text = text[0..outLen];
82               
83                return p[0 .. outLen];
84        }
85
86        /**
87         * Decode a sequence of Base-64 encoded text into binary data.  Note
88         * that the returned binary data is not necessarily zero-terminated,
89         * so it should not be used as a character string.
90         *
91         * Params:
92         *     text = zero-terminated string with base64 text to decode
93         *
94         * Returns: newly allocated buffer containing the binary data
95         *     that @text represents. The returned buffer must
96         *     be freed with g_free().
97         *
98         * Since: 2.12
99         */
100        public static char[] decode(string text)
101        {
102                size_t outLen;
103               
104                auto p = g_base64_decode(Str.toStringz(text), &outLen);
105               
106                return cast(char[])p[0 .. outLen];
107        }
108
109        /**
110         * Encode a sequence of binary data into its Base-64 stringified
111         * representation.
112         *
113         * Params:
114         *     data = the binary data to encode
115         *     len = the length of @data
116         *
117         * Returns: a newly allocated, zero-terminated Base-64
118         *     encoded string representing @data. The returned string must
119         *     be freed with g_free().
120         *
121         * Since: 2.12
122         */
123        public static string encode(char[] data)
124        {
125                auto retStr = g_base64_encode(data.ptr, cast(size_t)data.length);
126               
127                scope(exit) Str.freeString(retStr);
128                return Str.toString(retStr);
129        }
130
131        /**
132         * Flush the status from a sequence of calls to g_base64_encode_step().
133         *
134         * The output buffer must be large enough to fit all the data that will
135         * be written to it. It will need up to 4 bytes, or up to 5 bytes if
136         * line-breaking is enabled.
137         *
138         * Params:
139         *     breakLines = whether to break long lines
140         *     output = pointer to destination buffer
141         *     state = Saved state from g_base64_encode_step()
142         *     save = Saved state from g_base64_encode_step()
143         *
144         * Returns: The number of bytes of output that was written
145         *
146         * Since: 2.12
147         */
148        public static size_t encodeClose(bool breakLines, out char[] output, ref int state, ref int save)
149        {
150                return g_base64_encode_close(breakLines, output.ptr, &state, &save);
151        }
152
153        /**
154         * Incrementally encode a sequence of binary data into its Base-64 stringified
155         * representation. By calling this function multiple times you can convert
156         * data in chunks to avoid having to have the full encoded data in memory.
157         *
158         * When all of the data has been converted you must call
159         * g_base64_encode_close() to flush the saved state.
160         *
161         * The output buffer must be large enough to fit all the data that will
162         * be written to it. Due to the way base64 encodes you will need
163         * at least: (@len / 3 + 1) * 4 + 4 bytes (+ 4 may be needed in case of
164         * non-zero state). If you enable line-breaking you will need at least:
165         * ((@len / 3 + 1) * 4 + 4) / 72 + 1 bytes of extra space.
166         *
167         * @break_lines is typically used when putting base64-encoded data in emails.
168         * It breaks the lines at 72 columns instead of putting all of the text on
169         * the same line. This avoids problems with long lines in the email system.
170         * Note however that it breaks the lines with `LF` characters, not
171         * `CR LF` sequences, so the result cannot be passed directly to SMTP
172         * or certain other protocols.
173         *
174         * Params:
175         *     inn = the binary data to encode
176         *     len = the length of @in
177         *     breakLines = whether to break long lines
178         *     output = pointer to destination buffer
179         *     state = Saved state between steps, initialize to 0
180         *     save = Saved state between steps, initialize to 0
181         *
182         * Returns: The number of bytes of output that was written
183         *
184         * Since: 2.12
185         */
186        public static size_t encodeStep(char[] inn, bool breakLines, out char[] output, ref int state, ref int save)
187        {
188                return g_base64_encode_step(inn.ptr, cast(size_t)inn.length, breakLines, output.ptr, &state, &save);
189        }
190}
Note: See TracBrowser for help on using the repository browser.