#include "config.h"
#endif
-/* experimenting with in-memory deflation so as to write compressed files to channels and strings */
-#define IN_MEM_COMPRESSION
-
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_LIBZ
#include <zlib.h>
-#ifdef IN_MEM_COMPRESSION
#ifndef OS_CODE
# define OS_CODE 0x03 /* assume Unix */
#endif
static unsigned char *df;
static unsigned int dfallocated;
static unsigned long int crc;
-#endif
-#endif
+#endif /* HAVE_LIBZ */
#include "const.h"
#include "gvplugin_device.h"
if (job->flags & GVDEVICE_BINARY_FORMAT)
setmode(fileno(job->output_file), O_BINARY);
#endif
-#endif
-
-#ifndef IN_MEM_COMPRESSION
- if (job->flags & GVDEVICE_COMPRESSED_FORMAT) {
-#if HAVE_LIBZ
- int fd;
-
- /* open dup so can gzclose independent of FILE close */
- fd = dup(fileno(job->output_file));
- job->output_file = (FILE *) (gzdopen(fd, "wb"));
- if (!job->output_file) {
- (job->common->errorfn) ("Error initializing deflation on output file\n");
- exit(1);
- }
-#else
- (job->common->errorfn) ("No libz support.\n");
- exit(1);
-#endif
- }
#endif
}
-#ifdef IN_MEM_COMPRESSION
if (job->flags & GVDEVICE_COMPRESSED_FORMAT) {
#ifdef HAVE_LIBZ
z_stream *z = &z_strm;
exit(1);
#endif
}
-#endif
}
size_t gvwrite (GVJ_t * job, const char *s, size_t len)
{
+ size_t olen;
+
if (!len || !s)
return 0;
-#ifdef IN_MEM_COMPRESSION
if (job->flags & GVDEVICE_COMPRESSED_FORMAT) {
#ifdef HAVE_LIBZ
z_streamp z = &z_strm;
}
}
+ crc = crc32(crc, (unsigned char*)s, len);
+
z->next_in = (unsigned char*)s;
z->avail_in = len;
- z->next_out = df;
- z->avail_out = dfallocated;
- ret=deflate (z, Z_NO_FLUSH);
- if (ret != Z_OK) {
- (job->common->errorfn) ("deflation problem %d\n", ret);
- exit(1);
+ while (z->avail_in) {
+ z->next_out = df;
+ z->avail_out = dfallocated;
+ ret=deflate (z, Z_NO_FLUSH);
+ if (ret != Z_OK) {
+ (job->common->errorfn) ("deflation problem %d\n", ret);
+ exit(1);
+ }
+
+ if ((olen = z->next_out - df)) {
+ if (olen != (gvwrite_no_z (job, (char*)df, olen))) {
+ (job->common->errorfn) ("gvwrite_no_z problem %d\n", ret);
+ exit(1);
+ }
+ }
}
- crc = crc32(crc, (unsigned char*)s, len);
- len = z->next_out - df;
- s = (char*)df;
-#endif
- }
+
#else
- if (!(job->gvc->write_fn) && (job->flags & GVDEVICE_COMPRESSED_FORMAT)) {
-#ifdef HAVE_LIBZ
- return gzwrite((gzFile *) (job->output_file), s, len);
+ (job->common->errorfn) ("No libz support.\n");
+ exit(1);
#endif
}
-#endif
- return gvwrite_no_z (job, s, len);
+ return len;
}
int gvputs(GVJ_t * job, const char *s)
gvdevice_engine_t *gvde = job->device.engine;
boolean finalized_p = FALSE;
-#ifdef IN_MEM_COMPRESSION
if (job->flags & GVDEVICE_COMPRESSED_FORMAT) {
#ifdef HAVE_LIBZ
z_streamp z = &z_strm;
exit(1);
#endif
}
-#endif
if (gvde) {
if (gvde->finalize) {
if (! finalized_p) {
/* if the device has no finalization then it uses file output */
-#ifndef IN_MEM_COMPRESSION
- if (job->flags & GVDEVICE_COMPRESSED_FORMAT) {
-#ifdef HAVE_LIBZ
- gzclose((gzFile *) (job->output_file));
- job->output_file = NULL;
-#else
- (job->common->errorfn) ("No libz support\n");
- exit(1);
-#endif
- }
-#endif
gvdevice_flush(job);
gvdevice_close(job);
}