[librsvg] rsvg-convert: Handle gzip compressed input



commit 07e79f07ef789a9bc0b9fb94c41f2af211570889
Author: Christian Persch <chpe gnome org>
Date:   Mon Sep 1 20:29:34 2014 +0200

    rsvg-convert: Handle gzip compressed input
    
    Code copied from rsvg-view.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=735836

 rsvg-convert.c |   31 ++++++++++++++++++++++++++++++-
 1 files changed, 30 insertions(+), 1 deletions(-)
---
diff --git a/rsvg-convert.c b/rsvg-convert.c
index b3d3575..4c3c9a5 100644
--- a/rsvg-convert.c
+++ b/rsvg-convert.c
@@ -215,8 +215,37 @@ main (int argc, char **argv)
             file = NULL;
             stream = g_unix_input_stream_new (STDIN_FILENO, FALSE);
         } else {
-            file = g_file_new_for_commandline_arg (args[i]);
+            GFileInfo *file_info;
+            gboolean compressed = FALSE;
+
+            file = g_file_new_for_commandline_arg (args[0]);
             stream = (GInputStream *) g_file_read (file, NULL, &error);
+
+            if ((file_info = g_file_query_info (file,
+                                                G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
+                                                G_FILE_QUERY_INFO_NONE,
+                                                NULL,
+                                                NULL))) {
+                const char *content_type;
+                char *gz_content_type;
+
+                content_type = g_file_info_get_content_type (file_info);
+                gz_content_type = g_content_type_from_mime_type ("application/x-gzip");
+                compressed = (content_type != NULL && g_content_type_is_a (content_type, gz_content_type));
+                g_free (gz_content_type);
+                g_object_unref (file_info);
+            }
+
+            if (compressed) {
+                GZlibDecompressor *decompressor;
+                GInputStream *converter_stream;
+
+                decompressor = g_zlib_decompressor_new (G_ZLIB_COMPRESSOR_FORMAT_GZIP);
+                converter_stream = g_converter_input_stream_new (stream, G_CONVERTER (decompressor));
+                g_object_unref (stream);
+                stream = converter_stream;
+            }
+
             if (stream == NULL)
                 goto done;
         }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]