mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-02 15:33:39 +02:00
Add GBase64Encoder and Decoder
These are GConverter implementations that convert to/from base64 encoding. Originally written by Christian Persch. Fixes: #305
This commit is contained in:
@@ -47,6 +47,9 @@ static gboolean decompress = FALSE;
|
||||
static gboolean compress = FALSE;
|
||||
static gboolean gzip = FALSE;
|
||||
static gboolean fallback = FALSE;
|
||||
static gboolean base64_decode = FALSE;
|
||||
static gboolean base64_encode = FALSE;
|
||||
static gboolean base64_break_lines = FALSE;
|
||||
|
||||
static GOptionEntry entries[] = {
|
||||
{"decompress", 0, 0, G_OPTION_ARG_NONE, &decompress, "decompress", NULL},
|
||||
@@ -55,6 +58,9 @@ static GOptionEntry entries[] = {
|
||||
{"from-charset", 0, 0, G_OPTION_ARG_STRING, &from_charset, "from charset", NULL},
|
||||
{"to-charset", 0, 0, G_OPTION_ARG_STRING, &to_charset, "to charset", NULL},
|
||||
{"fallback", 0, 0, G_OPTION_ARG_NONE, &fallback, "use fallback", NULL},
|
||||
{"from-base64", 0, 0, G_OPTION_ARG_NONE, &base64_decode, "decode from Base-64", NULL},
|
||||
{"to-base64", 0, 0, G_OPTION_ARG_NONE, &base64_encode, "encode to Base-64", NULL},
|
||||
{"break-lines", 0, 0, G_OPTION_ARG_NONE, &base64_break_lines, "break lines in Base-64", NULL},
|
||||
{G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &locations, "locations", NULL},
|
||||
G_OPTION_ENTRY_NULL
|
||||
};
|
||||
@@ -100,6 +106,16 @@ cat (GFile * file)
|
||||
return;
|
||||
}
|
||||
|
||||
if (base64_decode)
|
||||
{
|
||||
GInputStream *old;
|
||||
conv = (GConverter *)g_base64_decoder_new();
|
||||
old = in;
|
||||
in = (GInputStream *) g_converter_input_stream_new (in, conv);
|
||||
g_object_unref (conv);
|
||||
g_object_unref (old);
|
||||
}
|
||||
|
||||
if (decompress)
|
||||
{
|
||||
GInputStream *old;
|
||||
@@ -161,6 +177,16 @@ cat (GFile * file)
|
||||
g_object_unref (in_file_info);
|
||||
}
|
||||
|
||||
if (base64_encode)
|
||||
{
|
||||
GInputStream *old;
|
||||
conv = (GConverter *)g_base64_encoder_new(base64_break_lines);
|
||||
old = in;
|
||||
in = (GInputStream *) g_converter_input_stream_new (in, conv);
|
||||
g_object_unref (conv);
|
||||
g_object_unref (old);
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
res =
|
||||
|
Reference in New Issue
Block a user