6 #endif /* HAVE_BZLIB */
8 #include "transformation.h"
14 bzlib_initialize(Transformation *xform, int enc)
23 bzlib_shutdown(Transformation *xform)
32 bzlib_startNewTape(Transformation *xform, struct tapebuf *tpbin,
33 unsigned long *destlen)
39 * Start slave process.
42 bzlib_startDiskIOProcess(Transformation *xform)
51 bzlib_endDiskIOProcess(Transformation *xform) {
63 bzlib_compress(Transformation *xform, struct tapebuf *tpbin, unsigned long *destlen,
64 const char *src, int srclen) {
67 unsigned int destlen2 = *destlen;
68 compresult = BZ2_bzBuffToBuffCompress(
73 xform->state.bzlib.complvl,
76 return compresult == BZ_OK ? 1 : 0;
79 #endif /* HAVE_BZLIB */
83 * Decompress a buffer.
86 bzlib_decompress(Transformation *xform, struct tapebuf *tpbin,
87 unsigned long *destlen, const char *src, int srclen, char **reason) {
90 unsigned int destlen2 = *destlen;
91 cresult = BZ2_bzBuffToBuffDecompress(tpbin->buf, &destlen2, (char *) src, srclen,
99 *reason = "not enough memory";
101 case BZ_OUTBUFF_FULL:
102 *reason = "buffer too small";
105 case BZ_DATA_ERROR_MAGIC:
106 case BZ_UNEXPECTED_EOF:
107 *reason = "data error";
112 return (cresult == BZ_OK) ? 1 : 0;
122 *transformation_bzlib_factory(int enc, int complvl)
124 Transformation *t = (Transformation *) malloc(sizeof (Transformation));
127 t->state.bzlib.complvl = complvl;
131 t->initialize = &bzlib_initialize;
132 t->shutdown = &bzlib_shutdown;
133 t->startNewTape = &bzlib_startNewTape;
134 t->startDiskIOProcess = &bzlib_startDiskIOProcess;
135 t->endDiskIOProcess = &bzlib_endDiskIOProcess;
136 t->compress = &bzlib_compress;
137 t->decompress = &bzlib_decompress;