]> git.street.me.uk Git - andy/viking.git/commitdiff
Read zip files contents which are stored with no compression.
authorRob Norris <rw_norris@hotmail.com>
Tue, 7 Jul 2015 21:01:00 +0000 (22:01 +0100)
committerRob Norris <rw_norris@hotmail.com>
Tue, 7 Jul 2015 21:01:00 +0000 (22:01 +0100)
src/compression.c

index 7e1f370a4634da1ebabeb2db74843ab712e66dcb..1d53d96db051b19c0d74bc33b5d85648d4af7bbc 100644 (file)
@@ -35,6 +35,7 @@
 #endif
 
 #include "compression.h"
+#include "string.h"
 #include <gio/gio.h>
 #include <glib/gstdio.h>
 
@@ -119,6 +120,17 @@ void *unzip_file(gchar *zip_file, gulong *unzip_size)
        if ( !unzip_data )
                goto end;
 
+       g_debug ("%s: method %d: from size %d to %ld", __FUNCTION__, GUINT16_FROM_LE(local_file_header->comp_method), GUINT32_FROM_LE(local_file_header->compressed_size), uncompressed_size);
+
+       if ( GUINT16_FROM_LE(local_file_header->comp_method) == 0 &&
+               (uncompressed_size == GUINT32_FROM_LE(local_file_header->compressed_size)) ) {
+               // Stored only - no need to 'uncompress'
+               // Thus just copy
+               memcpy ( unzip_data, zip_data, uncompressed_size );
+               *unzip_size = uncompressed_size;
+               goto end;
+       }
+
        if (!(*unzip_size = uncompress_data(unzip_data, uncompressed_size, zip_data, GUINT32_FROM_LE(local_file_header->compressed_size)))) {
                g_free(unzip_data);
                unzip_data = NULL;