My favorites | Sign in
Project Home Downloads Wiki Issues Source
Repository:
Checkout   Browse   Changes   Clones  
Changes to /classification/libncd/z/zlib.c
000000000000 vs. 0136ea839f68 Compare: vs.  Format:
Revision 0136ea839f68
Go to: 
Project members, sign in to write a code review
/classification/libncd/z/zlib.c /classification/libncd/z/zlib.c   0136ea839f68
  1 #include "bz2.h"
  2
  3 #include <bzlib.h>
  4
  5 int bz2Compress(int blockSize100k, int verbosity, int workFactor, void *data, unsigned int avail_in, void *odata, unsigned int *avail_out)
  6 {
  7 int ret;
  8 bz_stream strm;
  9
  10 strm.bzalloc = NULL;
  11 strm.bzfree = NULL;
  12 strm.opaque = NULL;
  13
  14 ret = BZ2_bzCompressInit(&strm, blockSize100k, verbosity, workFactor);
  15 if (ret != BZ_OK) return ret;
  16
  17 strm.next_in = data;
  18 strm.next_out = odata;
  19 strm.avail_in = avail_in;
  20 strm.avail_out = *avail_out;
  21
  22 ret = BZ2_bzCompress ( &strm, BZ_FINISH );
  23 if (ret == BZ_FINISH_OK) goto output_overflow;
  24 if (ret != BZ_STREAM_END) goto errhandler;
  25
  26 /* normal termination */
  27 *avail_out -= strm.avail_out;
  28 BZ2_bzCompressEnd ( &strm );
  29 return BZ_OK;
  30
  31 output_overflow:
  32 BZ2_bzCompressEnd ( &strm );
  33 return BZ_OUTBUFF_FULL;
  34
  35 errhandler:
  36 BZ2_bzCompressEnd ( &strm );
  37
  38 return ret;
  39 }
  40
  41 int bz2Decompress(int small, int verbosity, void *data, unsigned int avail_in, void *odata, unsigned int *avail_out)
  42 {
  43 int ret;
  44 bz_stream strm;
  45
  46 strm.bzalloc = NULL;
  47 strm.bzfree = NULL;
  48 strm.opaque = NULL;
  49
  50 ret = BZ2_bzDecompressInit ( &strm, verbosity, small );
  51 if (ret != BZ_OK) return ret;
  52
  53
  54 strm.next_in = data;
  55 strm.next_out = odata;
  56 strm.avail_in = avail_in;
  57 strm.avail_out = *avail_out;
  58
  59 ret = BZ2_bzDecompress ( &strm );
  60 if (ret == BZ_OK) goto output_overflow_or_eof;
  61 if (ret != BZ_STREAM_END) goto errhandler;
  62
  63
  64 /* normal termination */
  65 *avail_out -= strm.avail_out;
  66 BZ2_bzDecompressEnd ( &strm );
  67 return BZ_OK;
  68
  69
  70
  71 output_overflow_or_eof:
  72 if (strm.avail_out > 0) {
  73 BZ2_bzDecompressEnd ( &strm );
  74 return BZ_UNEXPECTED_EOF;
  75 } else {
  76 BZ2_bzDecompressEnd ( &strm );
  77 return BZ_OUTBUFF_FULL;
  78 };
  79
  80 errhandler:
  81 BZ2_bzDecompressEnd ( &strm );
  82 return ret;
  83 }
Powered by Google Project Hosting