本文整理汇总了C++中BZ2_bzDecompressInit函数的典型用法代码示例。如果您正苦于以下问题:C++ BZ2_bzDecompressInit函数的具体用法?C++ BZ2_bzDecompressInit怎么用?C++ BZ2_bzDecompressInit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了BZ2_bzDecompressInit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MojoInput_bzip2_seek
static boolean MojoInput_bzip2_seek(MojoInput *io, uint64 offset)
{
// This is all really expensive.
BZIP2info *info = (BZIP2info *) io->opaque;
/*
* If seeking backwards, we need to redecode the file
* from the start and throw away the compressed bits until we hit
* the offset we need. If seeking forward, we still need to
* decode, but we don't rewind first.
*/
if (offset < info->uncompressed_position)
{
#if 0
/* we do a copy so state is sane if inflateInit2() fails. */
bz_stream str;
initializeBZ2Stream(&str);
if (BZ2_bzDecompressInit(&str, 0, 0) != BZ_OK)
return false;
if (!info->origio->seek(info->origio, 0))
return false; // !!! FIXME: leaking (str)?
BZ2_bzDecompressEnd(&info->stream);
memcpy(&info->stream, &str, sizeof (bz_stream));
#endif
if (!info->origio->seek(info->origio, 0))
return false;
BZ2_bzDecompressEnd(&info->stream);
initializeBZ2Stream(&info->stream);
if (BZ2_bzDecompressInit(&info->stream, 0, 0) != BZ_OK)
return false;
info->uncompressed_position = 0;
} // if
while (info->uncompressed_position != offset)
{
uint8 buf[512];
uint32 maxread;
int64 br;
maxread = (uint32) (offset - info->uncompressed_position);
if (maxread > sizeof (buf))
maxread = sizeof (buf);
br = io->read(io, buf, maxread);
if (br != maxread)
return false;
} /* while */
return true;
} // MojoInput_bzip2_seek
示例2: memzero
UnBZFilter::UnBZFilter() {
memzero(&zs, sizeof(zs));
if(BZ2_bzDecompressInit(&zs, 0, 0) != BZ_OK)
throw Exception(STRING(DECOMPRESSION_ERROR));
}
示例3: BufFilePushBZIP2
_X_HIDDEN BufFilePtr
BufFilePushBZIP2 (BufFilePtr f)
{
xzip_buf *x;
x = malloc (sizeof (xzip_buf));
if (!x) return NULL;
bzero(&(x->z), sizeof(bz_stream));
x->f = f;
x->zstat = BZ2_bzDecompressInit(&(x->z),
0, /* verbosity: 0 silent, 4 max */
0); /* 0: go faster, 1: use less memory */
if (x->zstat != BZ_OK) {
free(x);
return NULL;
}
/* now that the history buffer is allocated, we provide the data buffer */
x->z.next_out = (char *) x->b;
x->z.avail_out = BUFFILESIZE;
x->z.next_in = (char *) x->b_in;
x->z.avail_in = 0;
return BufFileCreate((char *)x,
BufBzip2FileFill,
NULL,
BufBzip2FileSkip,
BufBzip2FileClose);
}
示例4: ft_bzip2_file_reset
static FT_Error
ft_bzip2_file_reset( FT_BZip2File zip )
{
FT_Stream stream = zip->source;
FT_Error error;
if ( !FT_STREAM_SEEK( 0 ) )
{
bz_stream* bzstream = &zip->bzstream;
BZ2_bzDecompressEnd( bzstream );
bzstream->avail_in = 0;
bzstream->next_in = (char*)zip->input;
bzstream->avail_out = 0;
bzstream->next_out = (char*)zip->buffer;
zip->limit = zip->buffer + FT_BZIP2_BUFFER_SIZE;
zip->cursor = zip->limit;
zip->pos = 0;
BZ2_bzDecompressInit( bzstream, 0, 0 );
}
return error;
}
示例5: squash_bz2_stream_new
static SquashBZ2Stream*
squash_bz2_stream_new (SquashCodec* codec, SquashStreamType stream_type, SquashOptions* options) {
int bz2_e = 0;
SquashBZ2Stream* stream;
assert (codec != NULL);
assert (stream_type == SQUASH_STREAM_COMPRESS || stream_type == SQUASH_STREAM_DECOMPRESS);
stream = squash_malloc (sizeof (SquashBZ2Stream));
squash_bz2_stream_init (stream, codec, stream_type, options, squash_bz2_stream_destroy);
if (stream_type == SQUASH_STREAM_COMPRESS) {
bz2_e = BZ2_bzCompressInit (&(stream->stream),
squash_codec_get_option_int_index (codec, options, SQUASH_BZ2_OPT_LEVEL),
0,
squash_codec_get_option_int_index (codec, options, SQUASH_BZ2_OPT_WORK_FACTOR));
} else if (stream_type == SQUASH_STREAM_DECOMPRESS) {
bz2_e = BZ2_bzDecompressInit (&(stream->stream),
0,
squash_codec_get_option_int_index (codec, options, SQUASH_BZ2_OPT_SMALL));
} else {
squash_assert_unreachable();
}
if (bz2_e != BZ_OK) {
/* We validate the params so OOM is really the only time this
should happen, and that really shouldn't be happening here. */
stream = squash_object_unref (stream);
}
return stream;
}
示例6: malloc
io_t *bz_open(io_t *parent)
{
io_t *io;
if (!parent)
return NULL;
io = malloc(sizeof(io_t));
io->source = &bz_source;
io->data = malloc(sizeof(struct bz_t));
DATA(io)->parent = parent;
DATA(io)->strm.next_in = NULL;
DATA(io)->strm.avail_in = 0;
DATA(io)->strm.next_out = NULL;
DATA(io)->strm.avail_out = 0;
DATA(io)->strm.bzalloc = NULL;
DATA(io)->strm.bzfree = NULL;
DATA(io)->strm.opaque = NULL;
DATA(io)->err = ERR_OK;
BZ2_bzDecompressInit(&DATA(io)->strm,
0, /* Verbosity */
0); /* small */
return io;
}
示例7: squash_bz2_stream_new
static SquashBZ2Stream*
squash_bz2_stream_new (SquashCodec* codec, SquashStreamType stream_type, SquashBZ2Options* options) {
int bz2_e = 0;
SquashBZ2Stream* stream;
assert (codec != NULL);
assert (stream_type == SQUASH_STREAM_COMPRESS || stream_type == SQUASH_STREAM_DECOMPRESS);
stream = (SquashBZ2Stream*) malloc (sizeof (SquashBZ2Stream));
squash_bz2_stream_init (stream, codec, stream_type, options, squash_bz2_stream_free);
if (stream_type == SQUASH_STREAM_COMPRESS) {
bz2_e = BZ2_bzCompressInit (&(stream->stream),
squash_bz2_options_get_block_size_100k (options),
0,
squash_bz2_options_get_work_factor (options));
} else if (stream_type == SQUASH_STREAM_DECOMPRESS) {
bz2_e = BZ2_bzDecompressInit (&(stream->stream),
0,
squash_bz2_options_get_small (options) ? 1 : 0);
} else {
assert (false);
}
if (bz2_e != BZ_OK) {
/* We validate the params so OOM is really the only time this
should happen, and that really shouldn't be happening here. */
stream = squash_object_unref (stream);
}
return stream;
}
示例8: libmpq__decompress_bzip2
/* this function decompress a stream using bzip2 library. */
int32_t libmpq__decompress_bzip2(uint8_t *in_buf, uint32_t in_size, uint8_t *out_buf, uint32_t out_size) {
/* some common variables. */
int32_t result = 0;
int32_t tb = 0;
bz_stream strm;
/* initialize the bzlib decompression. */
strm.bzalloc = NULL;
strm.bzfree = NULL;
/* initialize the structure. */
if ((result = BZ2_bzDecompressInit(&strm, 0, 0)) != BZ_OK) {
/* something on bzlib initialization failed. */
return result;
}
/* fill the stream structure for bzlib. */
strm.next_in = (char *)in_buf;
strm.avail_in = in_size;
strm.next_out = (char *)out_buf;
strm.avail_out = out_size;
/* do the decompression. */
while (BZ2_bzDecompress(&strm) != BZ_STREAM_END);
/* save transferred bytes. */
tb = strm.total_out_lo32;
/* cleanup of bzip stream. */
BZ2_bzDecompressEnd(&strm);
/* return transferred bytes. */
return tb;
}
示例9: BZ2_bzCompressInit
void bzip2_base::do_init
( bool compress,
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
bzip2::alloc_func alloc,
bzip2::free_func free,
#endif
void* derived )
{
bz_stream* s = static_cast<bz_stream*>(stream_);
// Current interface for customizing memory management
// is non-conforming and has been disabled:
//#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
// s->bzalloc = alloc;
// s->bzfree = free;
//#else
s->bzalloc = 0;
s->bzfree = 0;
//#endif
s->opaque = derived;
bzip2_error::check(
compress ?
BZ2_bzCompressInit( s,
params_.block_size,
0,
params_.work_factor ) :
BZ2_bzDecompressInit( s,
0,
params_.small )
);
ready_ = true;
}
示例10: start
static bool
start(void *ud) {
struct ctx *ctx = (struct ctx *)ud;
int ret;
ctx->zstr.avail_in = 0;
ctx->zstr.next_in = NULL;
ctx->zstr.avail_out = 0;
ctx->zstr.next_out = NULL;
if (ctx->compress) {
ret = BZ2_bzCompressInit(&ctx->zstr, ctx->compression_flags, 0, 30);
}
else {
ret = BZ2_bzDecompressInit(&ctx->zstr, 0, 0);
}
if (ret != BZ_OK) {
zip_error_set(ctx->error, map_error(ret), 0);
return false;
}
return true;
}
示例11: xmalloc
static MojoInput *make_bzip2_input(MojoInput *origio)
{
MojoInput *io = NULL;
BZIP2info *info = (BZIP2info *) xmalloc(sizeof (BZIP2info));
initializeBZ2Stream(&info->stream);
if (BZ2_bzDecompressInit(&info->stream, 0, 0) != BZ_OK)
{
free(info);
return NULL;
} // if
info->origio = origio;
io = (MojoInput *) xmalloc(sizeof (MojoInput));
io->ready = MojoInput_bzip2_ready;
io->read = MojoInput_bzip2_read;
io->seek = MojoInput_bzip2_seek;
io->tell = MojoInput_bzip2_tell;
io->length = MojoInput_bzip2_length;
io->duplicate = MojoInput_bzip2_duplicate;
io->close = MojoInput_bzip2_close;
io->opaque = info;
return io;
} // make_bzip2_input
示例12: open
// Try open file stream
bool FXBZFileStream::open(const FXString& filename,FXStreamDirection save_or_load,FXuval size){
if(FXFileStream::open(filename,save_or_load,size)){
if(FXCALLOC(&bz,BZBlock,1)){
int bzerror;
bz->stream.next_in=NULL;
bz->stream.avail_in=0;
bz->stream.next_out=NULL;
bz->stream.avail_out=0;
ac=BZ_RUN;
if(save_or_load==FXStreamLoad){
bzerror=BZ2_bzDecompressInit(&bz->stream,VERBOSITY,0);
if(bzerror==BZ_OK) return true;
code=FXStreamNoRead;
}
else{
bzerror=BZ2_bzCompressInit(&bz->stream,BLOCKSIZE100K,VERBOSITY,WORKFACTOR);
if(bzerror==BZ_OK) return true;
code=FXStreamNoWrite;
}
FXFREE(&bz);
}
FXFileStream::close();
}
return false;
}
示例13: larc_bzip2_decompressor
/**
* Create an decompress function.
* options:
*/
static int larc_bzip2_decompressor(lua_State *L)
{
bz_userdata *ud;
ud = (bz_userdata*)lua_newuserdata(L, sizeof(bz_userdata));
luaL_getmetatable(L, BZ2DECOMPRESS_MT);
lua_setmetatable(L, -2);
ud->z.bzalloc = NULL;
ud->z.bzfree = NULL;
ud->z.opaque = NULL;
ud->z.next_in = NULL;
ud->z.avail_in = 0;
ud->status = BZ2_bzDecompressInit(&ud->z, 0, USE_SMALL_DECOMPRESS);
if (ud->status != BZ_OK)
{
lua_pushnil(L);
lua_pushstring(L, bz2_error(ud->status));
lua_pushinteger(L, ud->status);
return 3;
}
lua_pushcclosure(L, decompress_call, 1);
return 1;
}
示例14: BZ2_bzDecompressInit
JNIEXPORT jbyteArray JNICALL Java_cn_reactnative_modules_update_DownloadTask_bsdiffPatch
(JNIEnv *env, jobject self, jbyteArray origin, jbyteArray patch){
jclass newExcCls;
jbyte* outPtr;
struct bspatch_stream stream;
bz_stream zip;
jbyte* originPtr = (*env)->GetByteArrayElements(env, origin, NULL);
size_t originLength = (*env)->GetArrayLength(env, origin);
jbyte* patchPtr = (*env)->GetByteArrayElements(env, patch, NULL);
size_t patchLength = (*env)->GetArrayLength(env, patch);
jbyteArray ret = NULL;
if (patchLength < 32) {
newExcCls = (*env)->FindClass(env,"java/lang/Error");
if (newExcCls != NULL) /* Unable to find the new exception class, give up. */
(*env)->ThrowNew(env,newExcCls, "Corrupt patch");
(*env)->ReleaseByteArrayElements(env, origin, originPtr, JNI_ABORT);
(*env)->ReleaseByteArrayElements(env, patch, patchPtr, JNI_ABORT);
return NULL;
}
int64_t newsize=offtin((uint8_t*)patchPtr + 16);
if (memcmp(patchPtr, "ENDSLEY/BSDIFF43", 16) != 0 || newsize<0) {
newExcCls = (*env)->FindClass(env, "java/lang/Error");
if (newExcCls != NULL) /* Unable to find the new exception class, give up. */
(*env)->ThrowNew(env, newExcCls, "Corrupt patch");
(*env)->ReleaseByteArrayElements(env, origin, originPtr, JNI_ABORT);
(*env)->ReleaseByteArrayElements(env, patch, patchPtr, JNI_ABORT);
return NULL;
}
ret = (*env)->NewByteArray(env, newsize);
if (ret == NULL) {
return NULL; // out of memory error thrown
}
outPtr = (*env)->GetByteArrayElements(env, ret, NULL);
zip.bzalloc = NULL;
zip.bzfree = NULL;
zip.opaque = NULL;
BZ2_bzDecompressInit(&zip, 0, 1);
zip.next_in = (char*)patchPtr + 32;
zip.avail_in = patchLength - 32;
stream.read = bz2_read;
stream.opaque = &zip;
if (bspatch((const uint8_t*)originPtr, originLength, (uint8_t*)outPtr, newsize, &stream)) {
newExcCls = (*env)->FindClass(env, "java/lang/Error");
if (newExcCls != NULL) /* Unable to find the new exception class, give up. */
(*env)->ThrowNew(env, newExcCls, "bspatch");
}
BZ2_bzDecompressEnd(&zip);
(*env)->ReleaseByteArrayElements(env, ret, outPtr, 0);
(*env)->ReleaseByteArrayElements(env, origin, originPtr, JNI_ABORT);
(*env)->ReleaseByteArrayElements(env, patch, patchPtr, JNI_ABORT);
return ret;
}
示例15: bz2_decompress_xml
bool bz2_decompress_xml(char *in_data, int in_data_length, BYTE **pDat, int *data_length) {
const int BLOCKSIZE = 1024 * 100;
bz_stream bzs = {0};
switch(BZ2_bzDecompressInit(&bzs, 0, 0)) {
case BZ_CONFIG_ERROR:
//MessageBox(0, "Configuration Error", "BZ2 Decompres Init", MB_OK | MB_ICONERROR);
ShowError(TranslateT("BZ2 Decompression, configuration error"));
return false;
case BZ_PARAM_ERROR:
//MessageBox(0, "Parameters Error", "BZ2 Decompres Init", MB_OK | MB_ICONERROR);
ShowError(TranslateT("BZ2 Decompression, parameter error"));
return false;
case BZ_MEM_ERROR:
//MessageBox(0, "Memory Error", "BZ2 Decompres Init", MB_OK | MB_ICONERROR);
ShowError(TranslateT("DB2 Decompression, memory error"));
return false;
}
bzs.avail_in = in_data_length;
bzs.next_in = in_data;
bzs.avail_out = BLOCKSIZE;
*pDat = (BYTE *)malloc(bzs.avail_out + 1); // allocate 100k (at present, xml data is about 87k) (1 byte extra for a terminating 0 for safety)
bzs.next_out = (char *)*pDat;
int blocknum = 0;
int ret;
while((ret = BZ2_bzDecompress(&bzs)) == BZ_OK && bzs.avail_in > 0) {
if(bzs.avail_out == 0) {
blocknum++;
*pDat = (BYTE *)realloc(*pDat, (blocknum + 1) * BLOCKSIZE + 1);
bzs.next_out = (char *)(*pDat + (blocknum * BLOCKSIZE));
bzs.avail_out = BLOCKSIZE;
}
}
BZ2_bzDecompressEnd(&bzs);
if(ret != BZ_STREAM_END) {
// char msg[512];
// sprintf(msg, "Error decompressing, code: %d", ret);
// MessageBox(0, msg, "Error Decompressing BZ2 XML data", MB_OK);
free(*pDat);
*pDat = 0;
*data_length = 0;
return false;
}
*data_length = bzs.total_out_lo32; // assume it's not too massive!
(*pDat)[*data_length] = 0; // for safety - last char shouldn't matter to us
//char msg[256];
//sprintf(msg, "Bytes decompressed: %d", data_length);
//MessageBox(0, msg, "msg", MB_OK);
return true;
}