]> granicus.if.org Git - graphviz/commitdiff
in-memory compression - fake .gz file header
authorellson <devnull@localhost>
Sun, 24 Aug 2008 20:41:50 +0000 (20:41 +0000)
committerellson <devnull@localhost>
Sun, 24 Aug 2008 20:41:50 +0000 (20:41 +0000)
lib/gvc/gvdevice.c

index a91652a9bb7224bece8d575d256b58eea2e65004..30138f13fef301f566acb51fcb1eca5dd1d55695 100644 (file)
 
 #ifdef HAVE_LIBZ
 #include <zlib.h>
+
+#ifdef IN_MEM_COMPRESSION
+#ifndef OS_CODE
+#  define OS_CODE  0x03  /* assume Unix */
+#endif
+static unsigned char z_file_header[] =
+   {0x1f, 0x8b, /*magic*/ Z_DEFLATED, 0 /*flags*/, 0,0,0,0 /*time*/, 0 /*xflags*/, OS_CODE};
+#endif
 #endif
 
 #include "const.h"
@@ -358,8 +366,12 @@ void gvdevice_initialize(GVJ_t * job)
 #endif
 #endif
 
-#ifndef IN_MEM_COMPRESSION
         if (job->flags & GVDEVICE_COMPRESSED_FORMAT) {
+#ifdef IN_MEM_COMPRESSION
+           job->flags ^= GVDEVICE_COMPRESSED_FORMAT; /* don't complress header!!! */
+           gvdevice_write(job, z_file_header, sizeof(z_file_header));
+           job->flags ^= GVDEVICE_COMPRESSED_FORMAT;
+#else
 #if HAVE_LIBZ
            int fd;
 
@@ -374,8 +386,8 @@ void gvdevice_initialize(GVJ_t * job)
            (job->common->errorfn) ("No libz support.\n");
            exit(1);
 #endif
-        }
 #endif
+        }
     }
 }