[gedit] Support loading/saving gzip compressed files
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] Support loading/saving gzip compressed files
- Date: Thu, 13 May 2010 09:58:05 +0000 (UTC)
commit 852c3c676e3a588f42a7b2b429f78e7cee28d723
Author: Jesse van den Kieboom <jessevdk gnome org>
Date: Thu May 13 11:57:36 2010 +0200
Support loading/saving gzip compressed files
gedit/gedit-document-loader.c | 28 ++++++++++++++++++++++------
gedit/gedit-document-saver.c | 39 +++++++++++++++++++++++++++++++++------
2 files changed, 55 insertions(+), 12 deletions(-)
---
diff --git a/gedit/gedit-document-loader.c b/gedit/gedit-document-loader.c
index d6118af..4f54235 100644
--- a/gedit/gedit-document-loader.c
+++ b/gedit/gedit-document-loader.c
@@ -619,9 +619,9 @@ static void
finish_query_info (AsyncData *async)
{
GeditDocumentLoader *loader;
- GInputStream *conv_stream;
GFileInfo *info;
GSList *candidate_encodings;
+ GInputStream *base_stream;
loader = async->loader;
info = loader->priv->info;
@@ -652,12 +652,28 @@ finish_query_info (AsyncData *async)
loader->priv->converter = gedit_smart_charset_converter_new (candidate_encodings);
g_slist_free (candidate_encodings);
-
- conv_stream = g_converter_input_stream_new (loader->priv->stream,
- G_CONVERTER (loader->priv->converter));
- g_object_unref (loader->priv->stream);
- loader->priv->stream = conv_stream;
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE) &&
+ g_strcmp0 (g_file_info_get_content_type (info), "application/x-gzip") == 0)
+ {
+ GZlibDecompressor *decompressor;
+
+ decompressor = g_zlib_decompressor_new (G_ZLIB_COMPRESSOR_FORMAT_GZIP);
+
+ base_stream = g_converter_input_stream_new (loader->priv->stream,
+ G_CONVERTER (decompressor));
+
+ g_object_unref (decompressor);
+ }
+ else
+ {
+ base_stream = g_object_ref (loader->priv->stream);
+ }
+
+ g_object_unref (loader->priv->stream);
+ loader->priv->stream = g_converter_input_stream_new (base_stream,
+ G_CONVERTER (loader->priv->converter));
+ g_object_unref (base_stream);
/* Output stream */
loader->priv->output = gedit_document_output_stream_new (loader->priv->document);
diff --git a/gedit/gedit-document-saver.c b/gedit/gedit-document-saver.c
index 8dc29d3..9d7da09 100644
--- a/gedit/gedit-document-saver.c
+++ b/gedit/gedit-document-saver.c
@@ -694,6 +694,8 @@ async_replace_ready_callback (GFile *source,
GeditDocumentSaver *saver;
GCharsetConverter *converter;
GFileOutputStream *file_stream;
+ GOutputStream *base_stream;
+ gchar *content_type;
GError *error = NULL;
gedit_debug (DEBUG_SAVER);
@@ -707,7 +709,7 @@ async_replace_ready_callback (GFile *source,
saver = async->saver;
file_stream = g_file_replace_finish (source, res, &error);
-
+
/* handle any error that might occur */
if (!file_stream)
{
@@ -716,6 +718,30 @@ async_replace_ready_callback (GFile *source,
return;
}
+ content_type = gedit_document_get_content_type (saver->priv->document);
+
+ if (g_strcmp0 (content_type, "application/x-gzip") == 0)
+ {
+ GZlibCompressor *compressor;
+
+ gedit_debug_message (DEBUG_SAVER, "Use gzip compressor");
+
+ compressor = g_zlib_compressor_new (G_ZLIB_COMPRESSOR_FORMAT_GZIP,
+ -1);
+
+ base_stream = g_converter_output_stream_new (G_OUTPUT_STREAM (file_stream),
+ G_CONVERTER (compressor));
+
+ g_object_unref (compressor);
+ g_object_unref (file_stream);
+ }
+ else
+ {
+ base_stream = G_OUTPUT_STREAM (file_stream);
+ }
+
+ g_free (content_type);
+
/* FIXME: manage converter error? */
gedit_debug_message (DEBUG_SAVER, "Encoding charset: %s",
gedit_encoding_get_charset (saver->priv->encoding));
@@ -725,17 +751,18 @@ async_replace_ready_callback (GFile *source,
converter = g_charset_converter_new (gedit_encoding_get_charset (saver->priv->encoding),
"UTF-8",
NULL);
- saver->priv->stream = g_converter_output_stream_new (G_OUTPUT_STREAM (file_stream),
- G_CONVERTER (converter));
- g_object_unref (file_stream);
+ saver->priv->stream = g_converter_output_stream_new (base_stream,
+ G_CONVERTER (converter));
+
g_object_unref (converter);
+ g_object_unref (base_stream);
}
else
{
- saver->priv->stream = G_OUTPUT_STREAM (file_stream);
+ saver->priv->stream = G_OUTPUT_STREAM (base_stream);
}
-
+
saver->priv->input = gedit_document_input_stream_new (GTK_TEXT_BUFFER (saver->priv->document),
saver->priv->newline_type);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]