8 #include "transformation.h"
14 zlib_initialize(Transformation *xform)
23 zlib_shutdown(Transformation *xform)
32 zlib_startNewTape(Transformation *xform, struct tapebuf *bin,
33 unsigned long *destlen)
42 zlib_startDiskIOProcess(Transformation *xform)
51 zlib_endDiskIOProcess(Transformation *xform)
69 zlib_compress(Transformation *xform, struct tapebuf *tpbin,
70 unsigned long *destlen, const char *src, int srclen)
74 compresult = compress2(tpbin->buf, destlen, src, srclen, xform->state.zlib.complvl);
75 return compresult == Z_OK ? 1 : 0;
78 #endif /* HAVE_ZLIB */
82 * Decompress a buffer.
85 zlib_decompress(Transformation *xform, struct tapebuf *tpbin,
86 unsigned long *destlen, const char *src, int srclen, char **reason)
90 cresult = uncompress(tpbin->buf, destlen, src, srclen);
96 *reason = "not enough memory";
99 *reason = "buffer too small";
102 *reason = "data error";
107 return (cresult == Z_OK) ? 1 : 0;
110 #endif /* HAVE_ZLIB */
118 *transformation_zlib_factory(int enc, int complvl)
120 Transformation *t = (Transformation *) malloc(sizeof (Transformation));
123 t->state.zlib.complvl = complvl;
127 t->initialize = &zlib_initialize;
128 t->shutdown = &zlib_shutdown;
129 t->startNewTape = &zlib_startNewTape;
130 t->startDiskIOProcess = &zlib_startDiskIOProcess;
131 t->endDiskIOProcess = &zlib_endDiskIOProcess;
132 t->compress = &zlib_compress;
133 t->decompress = &zlib_decompress;