[libgsf] Zip: add support for non-default compression level.



commit dfe43e78bfc77e3788c05e9bc893cecc13bda56e
Author: Morten Welinder <terra gnome org>
Date:   Thu Apr 17 19:35:56 2014 -0400

    Zip: add support for non-default compression level.

 ChangeLog             |    5 +++++
 NEWS                  |    3 +++
 gsf/gsf-outfile-zip.c |   44 +++++++++++++++++++++++++++++++++++---------
 3 files changed, 43 insertions(+), 9 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 795e618..439aec3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2014-04-17  Morten Welinder  <terra gnome org>
+
+       * gsf/gsf-outfile-zip.c (gsf_outfile_zip_set_property): Add new
+       property default-level.
+
 2014-03-19  Morten Welinder <terra gnome org>
 
        * configure.ac: Post-release bump.
diff --git a/NEWS b/NEWS
index 327e913..c134561 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,8 @@
 libgsf 1.14.31
 
+Allin Cottrell:
+       * Add support for non-default zip compression level.  [#722470]
+
 --------------------------------------------------------------------------
 libgsf 1.14.30
 
diff --git a/gsf/gsf-outfile-zip.c b/gsf/gsf-outfile-zip.c
index a511717..cbafee5 100644
--- a/gsf/gsf-outfile-zip.c
+++ b/gsf/gsf-outfile-zip.c
@@ -36,7 +36,8 @@ enum {
        PROP_0,
        PROP_SINK,
        PROP_ENTRY_NAME,
-       PROP_COMPRESSION_LEVEL
+       PROP_COMPRESSION_METHOD,
+        PROP_DEFLATE_LEVEL
 };
 
 static GObjectClass *parent_class;
@@ -54,6 +55,7 @@ struct _GsfOutfileZip {
 
        z_stream  *stream;
        GsfZipCompressionMethod compression_method;
+       gint deflate_level;
 
        gboolean   writing;
 
@@ -371,7 +373,7 @@ zip_init_write (GsfOutput *output)
                if (!zip->stream) {
                        zip->stream = g_new0 (z_stream, 1);
                }
-               ret = deflateInit2 (zip->stream, Z_DEFAULT_COMPRESSION,
+               ret = deflateInit2 (zip->stream, zip->deflate_level,
                                    Z_DEFLATED, -MAX_WBITS, MAX_MEM_LEVEL,
                                    Z_DEFAULT_STRATEGY);
                if (ret != Z_OK)
@@ -645,6 +647,7 @@ gsf_outfile_zip_init (GObject *obj)
        zip->root_order = NULL;
        zip->stream = NULL;
        zip->compression_method = GSF_ZIP_DEFLATED;
+       zip->deflate_level = Z_DEFAULT_COMPRESSION;
        zip->writing = FALSE;
        zip->buf = NULL;
        zip->buf_size = 0;
@@ -665,12 +668,15 @@ gsf_outfile_zip_get_property (GObject     *object,
        case PROP_ENTRY_NAME:
                g_value_set_string (value, zip->entry_name);
                break;
-       case PROP_COMPRESSION_LEVEL:
+       case PROP_COMPRESSION_METHOD:
                g_value_set_int (value,
                                 zip->vdir->dirent
                                 ? zip->vdir->dirent->compr_method
                                 : 0);
                break;
+       case PROP_DEFLATE_LEVEL:
+                g_value_set_int (value, zip->deflate_level);
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                break;
@@ -692,18 +698,26 @@ gsf_outfile_zip_set_property (GObject      *object,
        case PROP_ENTRY_NAME:
                zip->entry_name = g_strdup (g_value_get_string (value));
                break;
-       case PROP_COMPRESSION_LEVEL: {
-               int level = g_value_get_int (value);
-               switch (level) {
+       case PROP_COMPRESSION_METHOD: {
+               int method = g_value_get_int (value);
+               switch (method) {
                case GSF_ZIP_STORED:
                case GSF_ZIP_DEFLATED:
-                       zip->compression_method = level;
+                       zip->compression_method = method;
                        break;
                default:
-                       g_warning ("Unsupported compression level %d", level);
+                       g_warning ("Unsupported compression level %d", method);
                }
                break;
        }
+       case PROP_DEFLATE_LEVEL: {
+               int level = g_value_get_int (value);
+                if (level == Z_DEFAULT_COMPRESSION || (level >= 0 && level <= 9))
+                       zip->deflate_level = level;
+                else
+                       g_warning ("Unsupported deflate level %d", level);
+               }
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                break;
@@ -750,7 +764,7 @@ gsf_outfile_zip_class_init (GObjectClass *gobject_class)
                                      G_PARAM_CONSTRUCT_ONLY));
        g_object_class_install_property
                (gobject_class,
-                PROP_COMPRESSION_LEVEL,
+                PROP_COMPRESSION_METHOD,
                 g_param_spec_int ("compression-level",
                                   _("Compression Level"),
                                   _("The level of compression used, zero meaning none"),
@@ -759,6 +773,18 @@ gsf_outfile_zip_class_init (GObjectClass *gobject_class)
                                   GSF_PARAM_STATIC |
                                   G_PARAM_READWRITE |
                                   G_PARAM_CONSTRUCT_ONLY));
+       g_object_class_install_property
+               (gobject_class,
+                PROP_DEFLATE_LEVEL,
+                g_param_spec_int ("deflate-level",
+                                  _("Deflate Level"),
+                                  _("The level of deflate compression used, zero meaning none "
+                                    "and -1 meaning the zlib default"),
+                                  -1, 9,
+                                  Z_DEFAULT_COMPRESSION,
+                                  GSF_PARAM_STATIC |
+                                  G_PARAM_READWRITE |
+                                  G_PARAM_CONSTRUCT_ONLY));
 }
 
 GSF_CLASS (GsfOutfileZip, gsf_outfile_zip,


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