2007-10-13 03:36:03 +00:00
|
|
|
/*
|
|
|
|
* bzip2 is written by Julian Seward <jseward@bzip.org>.
|
|
|
|
* Adapted for busybox by Denys Vlasenko <vda.linux@googlemail.com>.
|
|
|
|
* See README and LICENSE files in this directory for more information.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------*/
|
|
|
|
/*--- Library top-level functions. ---*/
|
|
|
|
/*--- bzlib.c ---*/
|
|
|
|
/*-------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------
|
|
|
|
This file is part of bzip2/libbzip2, a program and library for
|
|
|
|
lossless, block-sorting data compression.
|
|
|
|
|
|
|
|
bzip2/libbzip2 version 1.0.4 of 20 December 2006
|
|
|
|
Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
|
|
|
|
|
|
|
|
Please read the WARNING, DISCLAIMER and PATENTS sections in the
|
|
|
|
README file.
|
|
|
|
|
|
|
|
This program is released under the terms of the license contained
|
|
|
|
in the file LICENSE.
|
|
|
|
------------------------------------------------------------------ */
|
|
|
|
|
|
|
|
/* CHANGES
|
|
|
|
* 0.9.0 -- original version.
|
|
|
|
* 0.9.0a/b -- no changes in this file.
|
|
|
|
* 0.9.0c -- made zero-length BZ_FLUSH work correctly in bzCompress().
|
|
|
|
* fixed bzWrite/bzRead to ignore zero-length requests.
|
2010-10-29 09:46:52 +00:00
|
|
|
* fixed bzread to correctly handle read requests after EOF.
|
2007-10-13 03:36:03 +00:00
|
|
|
* wrong parameter order in call to bzDecompressInit in
|
|
|
|
* bzBuffToBuffDecompress. Fixed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* #include "bzlib_private.h" */
|
|
|
|
|
|
|
|
/*---------------------------------------------------*/
|
|
|
|
/*--- Compression stuff ---*/
|
|
|
|
/*---------------------------------------------------*/
|
|
|
|
|
|
|
|
/*---------------------------------------------------*/
|
2007-10-14 00:43:01 +00:00
|
|
|
#if BZ_LIGHT_DEBUG
|
|
|
|
static
|
|
|
|
void bz_assert_fail(int errcode)
|
2007-10-13 03:36:03 +00:00
|
|
|
{
|
|
|
|
/* if (errcode == 1007) bb_error_msg_and_die("probably bad RAM"); */
|
2007-10-14 00:43:01 +00:00
|
|
|
bb_error_msg_and_die("internal error %d", errcode);
|
2007-10-13 03:36:03 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*---------------------------------------------------*/
|
|
|
|
static
|
|
|
|
void prepare_new_block(EState* s)
|
|
|
|
{
|
2007-10-14 00:43:01 +00:00
|
|
|
int i;
|
2007-10-13 03:36:03 +00:00
|
|
|
s->nblock = 0;
|
|
|
|
s->numZ = 0;
|
|
|
|
s->state_out_pos = 0;
|
|
|
|
BZ_INITIALISE_CRC(s->blockCRC);
|
2007-10-14 00:43:01 +00:00
|
|
|
/* inlined memset would be nice to have here */
|
|
|
|
for (i = 0; i < 256; i++)
|
|
|
|
s->inUse[i] = 0;
|
2007-10-13 03:36:03 +00:00
|
|
|
s->blockNo++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------*/
|
|
|
|
static
|
|
|
|
ALWAYS_INLINE
|
|
|
|
void init_RL(EState* s)
|
|
|
|
{
|
|
|
|
s->state_in_ch = 256;
|
|
|
|
s->state_in_len = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static
|
2007-10-17 10:14:11 +00:00
|
|
|
int isempty_RL(EState* s)
|
2007-10-13 03:36:03 +00:00
|
|
|
{
|
2007-10-17 10:14:11 +00:00
|
|
|
return (s->state_in_ch >= 256 || s->state_in_len <= 0);
|
2007-10-13 03:36:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------*/
|
|
|
|
static
|
|
|
|
void BZ2_bzCompressInit(bz_stream *strm, int blockSize100k)
|
|
|
|
{
|
|
|
|
int32_t n;
|
|
|
|
EState* s;
|
|
|
|
|
|
|
|
s = xzalloc(sizeof(EState));
|
|
|
|
s->strm = strm;
|
|
|
|
|
|
|
|
n = 100000 * blockSize100k;
|
|
|
|
s->arr1 = xmalloc(n * sizeof(uint32_t));
|
|
|
|
s->mtfv = (uint16_t*)s->arr1;
|
|
|
|
s->ptr = (uint32_t*)s->arr1;
|
|
|
|
s->arr2 = xmalloc((n + BZ_N_OVERSHOOT) * sizeof(uint32_t));
|
2007-10-14 00:43:01 +00:00
|
|
|
s->block = (uint8_t*)s->arr2;
|
2007-10-13 03:36:03 +00:00
|
|
|
s->ftab = xmalloc(65537 * sizeof(uint32_t));
|
|
|
|
|
2007-10-14 00:43:01 +00:00
|
|
|
s->crc32table = crc32_filltable(NULL, 1);
|
|
|
|
|
2007-10-13 03:36:03 +00:00
|
|
|
s->state = BZ_S_INPUT;
|
|
|
|
s->mode = BZ_M_RUNNING;
|
|
|
|
s->blockSize100k = blockSize100k;
|
|
|
|
s->nblockMAX = n - 19;
|
|
|
|
|
|
|
|
strm->state = s;
|
|
|
|
/*strm->total_in = 0;*/
|
2007-10-14 00:43:01 +00:00
|
|
|
strm->total_out = 0;
|
2007-10-13 03:36:03 +00:00
|
|
|
init_RL(s);
|
|
|
|
prepare_new_block(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------*/
|
|
|
|
static
|
|
|
|
void add_pair_to_block(EState* s)
|
|
|
|
{
|
|
|
|
int32_t i;
|
2007-10-14 00:43:01 +00:00
|
|
|
uint8_t ch = (uint8_t)(s->state_in_ch);
|
2007-10-13 03:36:03 +00:00
|
|
|
for (i = 0; i < s->state_in_len; i++) {
|
2007-10-14 00:43:01 +00:00
|
|
|
BZ_UPDATE_CRC(s, s->blockCRC, ch);
|
2007-10-13 03:36:03 +00:00
|
|
|
}
|
2007-10-14 00:43:01 +00:00
|
|
|
s->inUse[s->state_in_ch] = 1;
|
2007-10-13 03:36:03 +00:00
|
|
|
switch (s->state_in_len) {
|
|
|
|
case 3:
|
2007-10-14 00:43:01 +00:00
|
|
|
s->block[s->nblock] = (uint8_t)ch; s->nblock++;
|
|
|
|
/* fall through */
|
|
|
|
case 2:
|
|
|
|
s->block[s->nblock] = (uint8_t)ch; s->nblock++;
|
|
|
|
/* fall through */
|
|
|
|
case 1:
|
|
|
|
s->block[s->nblock] = (uint8_t)ch; s->nblock++;
|
2007-10-13 03:36:03 +00:00
|
|
|
break;
|
|
|
|
default:
|
2007-10-14 00:43:01 +00:00
|
|
|
s->inUse[s->state_in_len - 4] = 1;
|
|
|
|
s->block[s->nblock] = (uint8_t)ch; s->nblock++;
|
|
|
|
s->block[s->nblock] = (uint8_t)ch; s->nblock++;
|
|
|
|
s->block[s->nblock] = (uint8_t)ch; s->nblock++;
|
|
|
|
s->block[s->nblock] = (uint8_t)ch; s->nblock++;
|
|
|
|
s->block[s->nblock] = (uint8_t)(s->state_in_len - 4);
|
2007-10-13 03:36:03 +00:00
|
|
|
s->nblock++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------*/
|
|
|
|
static
|
|
|
|
void flush_RL(EState* s)
|
|
|
|
{
|
|
|
|
if (s->state_in_ch < 256) add_pair_to_block(s);
|
|
|
|
init_RL(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------*/
|
|
|
|
#define ADD_CHAR_TO_BLOCK(zs, zchh0) \
|
|
|
|
{ \
|
|
|
|
uint32_t zchh = (uint32_t)(zchh0); \
|
|
|
|
/*-- fast track the common case --*/ \
|
|
|
|
if (zchh != zs->state_in_ch && zs->state_in_len == 1) { \
|
2007-10-14 00:43:01 +00:00
|
|
|
uint8_t ch = (uint8_t)(zs->state_in_ch); \
|
|
|
|
BZ_UPDATE_CRC(zs, zs->blockCRC, ch); \
|
|
|
|
zs->inUse[zs->state_in_ch] = 1; \
|
|
|
|
zs->block[zs->nblock] = (uint8_t)ch; \
|
2007-10-13 03:36:03 +00:00
|
|
|
zs->nblock++; \
|
|
|
|
zs->state_in_ch = zchh; \
|
|
|
|
} \
|
|
|
|
else \
|
|
|
|
/*-- general, uncommon cases --*/ \
|
2007-10-14 00:43:01 +00:00
|
|
|
if (zchh != zs->state_in_ch || zs->state_in_len == 255) { \
|
2007-10-13 03:36:03 +00:00
|
|
|
if (zs->state_in_ch < 256) \
|
|
|
|
add_pair_to_block(zs); \
|
|
|
|
zs->state_in_ch = zchh; \
|
|
|
|
zs->state_in_len = 1; \
|
|
|
|
} else { \
|
|
|
|
zs->state_in_len++; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------*/
|
|
|
|
static
|
2007-10-14 00:43:01 +00:00
|
|
|
void /*Bool*/ copy_input_until_stop(EState* s)
|
2007-10-13 03:36:03 +00:00
|
|
|
{
|
2007-10-14 00:43:01 +00:00
|
|
|
/*Bool progress_in = False;*/
|
2007-10-13 03:36:03 +00:00
|
|
|
|
2007-10-14 00:43:01 +00:00
|
|
|
#ifdef SAME_CODE_AS_BELOW
|
2007-10-13 03:36:03 +00:00
|
|
|
if (s->mode == BZ_M_RUNNING) {
|
|
|
|
/*-- fast track the common case --*/
|
|
|
|
while (1) {
|
|
|
|
/*-- no input? --*/
|
|
|
|
if (s->strm->avail_in == 0) break;
|
2007-10-14 00:43:01 +00:00
|
|
|
/*-- block full? --*/
|
|
|
|
if (s->nblock >= s->nblockMAX) break;
|
|
|
|
/*progress_in = True;*/
|
|
|
|
ADD_CHAR_TO_BLOCK(s, (uint32_t)(*(uint8_t*)(s->strm->next_in)));
|
2007-10-13 03:36:03 +00:00
|
|
|
s->strm->next_in++;
|
|
|
|
s->strm->avail_in--;
|
|
|
|
/*s->strm->total_in++;*/
|
|
|
|
}
|
2007-10-14 00:43:01 +00:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
2007-10-13 03:36:03 +00:00
|
|
|
/*-- general, uncommon case --*/
|
|
|
|
while (1) {
|
|
|
|
/*-- no input? --*/
|
|
|
|
if (s->strm->avail_in == 0) break;
|
2007-10-14 00:43:01 +00:00
|
|
|
/*-- block full? --*/
|
|
|
|
if (s->nblock >= s->nblockMAX) break;
|
|
|
|
//# /*-- flush/finish end? --*/
|
|
|
|
//# if (s->avail_in_expect == 0) break;
|
|
|
|
/*progress_in = True;*/
|
|
|
|
ADD_CHAR_TO_BLOCK(s, *(uint8_t*)(s->strm->next_in));
|
2007-10-13 03:36:03 +00:00
|
|
|
s->strm->next_in++;
|
|
|
|
s->strm->avail_in--;
|
|
|
|
/*s->strm->total_in++;*/
|
2007-10-14 00:43:01 +00:00
|
|
|
//# s->avail_in_expect--;
|
2007-10-13 03:36:03 +00:00
|
|
|
}
|
|
|
|
}
|
2007-10-14 00:43:01 +00:00
|
|
|
/*return progress_in;*/
|
2007-10-13 03:36:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------*/
|
|
|
|
static
|
2007-10-14 00:43:01 +00:00
|
|
|
void /*Bool*/ copy_output_until_stop(EState* s)
|
2007-10-13 03:36:03 +00:00
|
|
|
{
|
2007-10-14 00:43:01 +00:00
|
|
|
/*Bool progress_out = False;*/
|
2007-10-13 03:36:03 +00:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
/*-- no output space? --*/
|
|
|
|
if (s->strm->avail_out == 0) break;
|
|
|
|
|
|
|
|
/*-- block done? --*/
|
|
|
|
if (s->state_out_pos >= s->numZ) break;
|
|
|
|
|
2007-10-14 00:43:01 +00:00
|
|
|
/*progress_out = True;*/
|
2007-10-13 03:36:03 +00:00
|
|
|
*(s->strm->next_out) = s->zbits[s->state_out_pos];
|
|
|
|
s->state_out_pos++;
|
|
|
|
s->strm->avail_out--;
|
|
|
|
s->strm->next_out++;
|
|
|
|
s->strm->total_out++;
|
|
|
|
}
|
2007-10-14 00:43:01 +00:00
|
|
|
/*return progress_out;*/
|
2007-10-13 03:36:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------*/
|
|
|
|
static
|
2007-10-14 00:43:01 +00:00
|
|
|
void /*Bool*/ handle_compress(bz_stream *strm)
|
2007-10-13 03:36:03 +00:00
|
|
|
{
|
2007-10-14 00:43:01 +00:00
|
|
|
/*Bool progress_in = False;*/
|
|
|
|
/*Bool progress_out = False;*/
|
2007-10-13 03:36:03 +00:00
|
|
|
EState* s = strm->state;
|
2007-10-14 04:55:59 +00:00
|
|
|
|
2007-10-13 03:36:03 +00:00
|
|
|
while (1) {
|
|
|
|
if (s->state == BZ_S_OUTPUT) {
|
2007-10-14 00:43:01 +00:00
|
|
|
/*progress_out |=*/ copy_output_until_stop(s);
|
2007-10-13 03:36:03 +00:00
|
|
|
if (s->state_out_pos < s->numZ) break;
|
|
|
|
if (s->mode == BZ_M_FINISHING
|
2007-10-14 00:43:01 +00:00
|
|
|
//# && s->avail_in_expect == 0
|
|
|
|
&& s->strm->avail_in == 0
|
2007-10-13 03:36:03 +00:00
|
|
|
&& isempty_RL(s))
|
|
|
|
break;
|
|
|
|
prepare_new_block(s);
|
|
|
|
s->state = BZ_S_INPUT;
|
2007-10-14 00:43:01 +00:00
|
|
|
#ifdef FLUSH_IS_UNUSED
|
2007-10-13 03:36:03 +00:00
|
|
|
if (s->mode == BZ_M_FLUSHING
|
|
|
|
&& s->avail_in_expect == 0
|
|
|
|
&& isempty_RL(s))
|
|
|
|
break;
|
2007-10-14 00:43:01 +00:00
|
|
|
#endif
|
2007-10-13 03:36:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (s->state == BZ_S_INPUT) {
|
2007-10-14 00:43:01 +00:00
|
|
|
/*progress_in |=*/ copy_input_until_stop(s);
|
|
|
|
//#if (s->mode != BZ_M_RUNNING && s->avail_in_expect == 0) {
|
|
|
|
if (s->mode != BZ_M_RUNNING && s->strm->avail_in == 0) {
|
2007-10-13 03:36:03 +00:00
|
|
|
flush_RL(s);
|
2007-10-14 00:43:01 +00:00
|
|
|
BZ2_compressBlock(s, (s->mode == BZ_M_FINISHING));
|
2007-10-13 03:36:03 +00:00
|
|
|
s->state = BZ_S_OUTPUT;
|
|
|
|
} else
|
|
|
|
if (s->nblock >= s->nblockMAX) {
|
2007-10-14 00:43:01 +00:00
|
|
|
BZ2_compressBlock(s, 0);
|
2007-10-13 03:36:03 +00:00
|
|
|
s->state = BZ_S_OUTPUT;
|
|
|
|
} else
|
|
|
|
if (s->strm->avail_in == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-14 00:43:01 +00:00
|
|
|
/*return progress_in || progress_out;*/
|
2007-10-13 03:36:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------*/
|
|
|
|
static
|
|
|
|
int BZ2_bzCompress(bz_stream *strm, int action)
|
|
|
|
{
|
2007-10-14 00:43:01 +00:00
|
|
|
/*Bool progress;*/
|
2007-10-13 03:36:03 +00:00
|
|
|
EState* s;
|
2007-10-14 00:43:01 +00:00
|
|
|
|
2007-10-13 03:36:03 +00:00
|
|
|
s = strm->state;
|
|
|
|
|
|
|
|
switch (s->mode) {
|
|
|
|
case BZ_M_RUNNING:
|
|
|
|
if (action == BZ_RUN) {
|
2007-10-14 00:43:01 +00:00
|
|
|
/*progress =*/ handle_compress(strm);
|
|
|
|
/*return progress ? BZ_RUN_OK : BZ_PARAM_ERROR;*/
|
|
|
|
return BZ_RUN_OK;
|
2007-10-13 03:36:03 +00:00
|
|
|
}
|
2007-10-14 00:43:01 +00:00
|
|
|
#ifdef FLUSH_IS_UNUSED
|
2007-10-13 03:36:03 +00:00
|
|
|
else
|
|
|
|
if (action == BZ_FLUSH) {
|
2007-10-14 00:43:01 +00:00
|
|
|
//#s->avail_in_expect = strm->avail_in;
|
2007-10-13 03:36:03 +00:00
|
|
|
s->mode = BZ_M_FLUSHING;
|
2007-10-14 00:43:01 +00:00
|
|
|
goto case_BZ_M_FLUSHING;
|
2007-10-13 03:36:03 +00:00
|
|
|
}
|
2007-10-14 00:43:01 +00:00
|
|
|
#endif
|
2007-10-13 03:36:03 +00:00
|
|
|
else
|
2007-10-14 00:43:01 +00:00
|
|
|
/*if (action == BZ_FINISH)*/ {
|
|
|
|
//#s->avail_in_expect = strm->avail_in;
|
2007-10-13 03:36:03 +00:00
|
|
|
s->mode = BZ_M_FINISHING;
|
2007-10-14 00:43:01 +00:00
|
|
|
goto case_BZ_M_FINISHING;
|
2007-10-13 03:36:03 +00:00
|
|
|
}
|
|
|
|
|
2007-10-14 00:43:01 +00:00
|
|
|
#ifdef FLUSH_IS_UNUSED
|
2007-10-17 10:14:11 +00:00
|
|
|
case_BZ_M_FLUSHING:
|
2007-10-13 03:36:03 +00:00
|
|
|
case BZ_M_FLUSHING:
|
2007-10-14 00:43:01 +00:00
|
|
|
/*if (s->avail_in_expect != s->strm->avail_in)
|
|
|
|
return BZ_SEQUENCE_ERROR;*/
|
|
|
|
/*progress =*/ handle_compress(strm);
|
2007-10-13 03:36:03 +00:00
|
|
|
if (s->avail_in_expect > 0 || !isempty_RL(s) || s->state_out_pos < s->numZ)
|
|
|
|
return BZ_FLUSH_OK;
|
|
|
|
s->mode = BZ_M_RUNNING;
|
|
|
|
return BZ_RUN_OK;
|
2007-10-14 00:43:01 +00:00
|
|
|
#endif
|
2007-10-13 03:36:03 +00:00
|
|
|
|
2007-10-14 00:43:01 +00:00
|
|
|
case_BZ_M_FINISHING:
|
|
|
|
/*case BZ_M_FINISHING:*/
|
|
|
|
default:
|
|
|
|
/*if (s->avail_in_expect != s->strm->avail_in)
|
|
|
|
return BZ_SEQUENCE_ERROR;*/
|
|
|
|
/*progress =*/ handle_compress(strm);
|
|
|
|
/*if (!progress) return BZ_SEQUENCE_ERROR;*/
|
|
|
|
//#if (s->avail_in_expect > 0 || !isempty_RL(s) || s->state_out_pos < s->numZ)
|
|
|
|
//# return BZ_FINISH_OK;
|
|
|
|
if (s->strm->avail_in > 0 || !isempty_RL(s) || s->state_out_pos < s->numZ)
|
2007-10-13 03:36:03 +00:00
|
|
|
return BZ_FINISH_OK;
|
2007-10-14 00:43:01 +00:00
|
|
|
/*s->mode = BZ_M_IDLE;*/
|
2007-10-13 03:36:03 +00:00
|
|
|
return BZ_STREAM_END;
|
|
|
|
}
|
2007-10-14 00:43:01 +00:00
|
|
|
/* return BZ_OK; --not reached--*/
|
2007-10-13 03:36:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------*/
|
|
|
|
static
|
2007-10-14 00:43:01 +00:00
|
|
|
void BZ2_bzCompressEnd(bz_stream *strm)
|
2007-10-13 03:36:03 +00:00
|
|
|
{
|
|
|
|
EState* s;
|
|
|
|
|
2007-10-14 00:43:01 +00:00
|
|
|
s = strm->state;
|
|
|
|
free(s->arr1);
|
|
|
|
free(s->arr2);
|
|
|
|
free(s->ftab);
|
|
|
|
free(s->crc32table);
|
2010-12-30 03:43:35 +00:00
|
|
|
free(s);
|
2007-10-13 03:36:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------*/
|
|
|
|
/*--- Misc convenience stuff ---*/
|
|
|
|
/*---------------------------------------------------*/
|
|
|
|
|
|
|
|
/*---------------------------------------------------*/
|
|
|
|
#ifdef EXAMPLE_CODE_FOR_MEM_TO_MEM_COMPRESSION
|
|
|
|
static
|
|
|
|
int BZ2_bzBuffToBuffCompress(char* dest,
|
|
|
|
unsigned int* destLen,
|
|
|
|
char* source,
|
|
|
|
unsigned int sourceLen,
|
|
|
|
int blockSize100k)
|
|
|
|
{
|
|
|
|
bz_stream strm;
|
|
|
|
int ret;
|
|
|
|
|
2010-01-28 01:24:24 +00:00
|
|
|
if (dest == NULL || destLen == NULL
|
|
|
|
|| source == NULL
|
|
|
|
|| blockSize100k < 1 || blockSize100k > 9
|
|
|
|
) {
|
2007-10-13 03:36:03 +00:00
|
|
|
return BZ_PARAM_ERROR;
|
2010-01-28 01:24:24 +00:00
|
|
|
}
|
2007-10-13 03:36:03 +00:00
|
|
|
|
|
|
|
BZ2_bzCompressInit(&strm, blockSize100k);
|
|
|
|
|
|
|
|
strm.next_in = source;
|
|
|
|
strm.next_out = dest;
|
|
|
|
strm.avail_in = sourceLen;
|
|
|
|
strm.avail_out = *destLen;
|
|
|
|
|
|
|
|
ret = BZ2_bzCompress(&strm, BZ_FINISH);
|
|
|
|
if (ret == BZ_FINISH_OK) goto output_overflow;
|
|
|
|
if (ret != BZ_STREAM_END) goto errhandler;
|
|
|
|
|
|
|
|
/* normal termination */
|
|
|
|
*destLen -= strm.avail_out;
|
|
|
|
BZ2_bzCompressEnd(&strm);
|
|
|
|
return BZ_OK;
|
|
|
|
|
2007-10-14 00:43:01 +00:00
|
|
|
output_overflow:
|
2007-10-13 03:36:03 +00:00
|
|
|
BZ2_bzCompressEnd(&strm);
|
|
|
|
return BZ_OUTBUFF_FULL;
|
|
|
|
|
2007-10-14 00:43:01 +00:00
|
|
|
errhandler:
|
2007-10-13 03:36:03 +00:00
|
|
|
BZ2_bzCompressEnd(&strm);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------*/
|
|
|
|
/*--- end bzlib.c ---*/
|
|
|
|
/*-------------------------------------------------------------*/
|