本文整理汇总了C++中BZ2_bzDecompressEnd函数的典型用法代码示例。如果您正苦于以下问题:C++ BZ2_bzDecompressEnd函数的具体用法?C++ BZ2_bzDecompressEnd怎么用?C++ BZ2_bzDecompressEnd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了BZ2_bzDecompressEnd函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: larc_bzip2_decompress
/**
* Inflate a string.
* options:
*/
static int larc_bzip2_decompress(lua_State *L)
{
size_t len;
const char *str = luaL_checklstring(L, 1, &len);
bz_userdata ud;
ud.z.bzalloc = NULL;
ud.z.bzfree = NULL;
ud.z.opaque = NULL;
ud.z.next_in = (char*)str;
ud.z.avail_in = len;
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;
}
ud.result = -1;
if (0 != lua_cpcall(L, protected_decompress_to_buffer, &ud))
{
BZ2_bzDecompressEnd(&ud.z);
return lua_error(L);
}
BZ2_bzDecompressEnd(&ud.z);
if (ud.result != -1)
{
lua_rawgeti(L, LUA_REGISTRYINDEX, ud.result);
luaL_unref(L, LUA_REGISTRYINDEX, ud.result);
lua_pushinteger(L, len - ud.z.avail_in);
}
else
{
lua_pushnil(L);
lua_pushstring(L, bz2_error(ud.status));
}
lua_pushinteger(L, ud.status);
return 3;
}
示例2: KBZipFileDestroy
/* Destroy
* destroy file
*/
static rc_t CC KBZipFileDestroy (KBZipFile *self)
{
rc_t rc = 0, orc = 0;
if (self)
{
if (self->file != NULL)
{
int zret = BZ_OK;
if (self->dad.write_enabled)
{
/* flush out end of compressed data */
/* if (self->completed == false) */
/* { */
size_t ignored;
bz_stream* strm = &self->strm;
strm->avail_in = 0;
strm->next_in = NULL;
rc = KBZipFileWriteInt(self, BZ_FINISH, &ignored);
/* assert (zret == BZ_STREAM_END); */ /* stream will be complete */
/* } */
zret = BZ2_bzCompressEnd(&self->strm); /* clean up */
self->completed = true;
}
else if (self->dad.read_enabled)
{
zret = BZ2_bzDecompressEnd (&self->strm);
}
else
{
rc = RC (rcFS, rcFile, rcDestroying, rcSelf, rcInvalid);
LOGERR (klogInt, orc, "corrupt object "
"closing bzip file object");
}
if (zret != BZ_OK)
{
orc = RC (rcFS, rcFile, rcDestroying, rcParam, rcInvalid);
LOGERR (klogInt, orc, "bad parameters - coding error on "
"closing bzip file object");
if (rc == 0)
rc = orc;
}
orc = KFileRelease (self->file);
if (rc == 0)
rc = orc;
}
free (self);
}
return rc;
}
示例3: BZ2Decompress
String BZ2Decompress(String s, Gate2<int, int> progress)
{
if(s.IsEmpty())
return s;
bz_stream z;
Zero(z);
z.bzalloc = bzalloc_new;
z.bzfree = bzfree_new;
z.opaque = 0;
if(BZ2_bzDecompressInit(&z, 0, 0) != BZ_OK)
return String::GetVoid();
int buf_size = minmax(s.GetLength() / 2, 1024, 65536);
Buffer<char> output(buf_size);
z.next_in = (char *)s.Begin();
z.avail_in = s.GetLength();
z.next_out = output;
z.avail_out = buf_size;
String out;
while(BZ2_bzDecompress(&z) == BZ_OK)
{
if(z.avail_out == (dword)buf_size)
{ // no output generated - assume error
BZ2_bzDecompressEnd(&z);
return String::GetVoid();
}
out.Cat(output, buf_size - z.avail_out);
z.next_out = output;
z.avail_out = buf_size;
if(progress((int)(uintptr_t)((const char *)z.next_in - ~s), s.GetLength()))
{
BZ2_bzDecompressEnd(&z);
return String::GetVoid();
}
}
if(z.avail_out < (unsigned)buf_size)
out.Cat(output, buf_size - z.avail_out);
BZ2_bzDecompressEnd(&z);
return out;
}
示例4: camlzip_bzDecompressEnd
value camlzip_bzDecompressEnd(value stream) {
#ifdef USE_BZIP2
int err;
if ((err = BZ2_bzDecompressEnd(BZStream_val(stream))) != BZ_OK)
camlzip_bzerror("Bzlib.decompressEnd", err);
free(BZStream_val(stream));
#else
failwith("Bzip2 compression not supported");
#endif
return Val_unit;
}
示例5: gst_bz2dec_decompress_end
static void
gst_bz2dec_decompress_end (GstBz2dec * b)
{
g_return_if_fail (GST_IS_BZ2DEC (b));
if (b->ready) {
BZ2_bzDecompressEnd (&b->stream);
memset (&b->stream, 0, sizeof (b->stream));
b->ready = FALSE;
}
}
示例6: free
void MemoryDecompressor::Clear(void)
{
if (output)
{
free(output);
output=0;
}
if (streamInited)
BZ2_bzDecompressEnd( &stream );
}
示例7: memset
int
ArchiveReader::ExtractItemToStream(const MarItem *item, FILE *fp)
{
/* decompress the data chunk by chunk */
bz_stream strm;
int offset, inlen, outlen, ret = OK;
memset(&strm, 0, sizeof(strm));
if (BZ2_bzDecompressInit(&strm, 0, 0) != BZ_OK)
return UNEXPECTED_BZIP_ERROR;
offset = 0;
for (;;) {
if (!item->length) {
ret = UNEXPECTED_MAR_ERROR;
break;
}
if (offset < (int) item->length && strm.avail_in == 0) {
inlen = mar_read(mArchive, item, offset, inbuf, inbuf_size);
if (inlen <= 0)
return READ_ERROR;
offset += inlen;
strm.next_in = inbuf;
strm.avail_in = inlen;
}
strm.next_out = outbuf;
strm.avail_out = outbuf_size;
ret = BZ2_bzDecompress(&strm);
if (ret != BZ_OK && ret != BZ_STREAM_END) {
ret = UNEXPECTED_BZIP_ERROR;
break;
}
outlen = outbuf_size - strm.avail_out;
if (outlen) {
if (fwrite(outbuf, outlen, 1, fp) != 1) {
ret = WRITE_ERROR_EXTRACT;
break;
}
}
if (ret == BZ_STREAM_END) {
ret = OK;
break;
}
}
BZ2_bzDecompressEnd(&strm);
return ret;
}
示例8: php_bz2_decompress_dtor
static void php_bz2_decompress_dtor(php_stream_filter *thisfilter)
{
if (thisfilter && Z_PTR(thisfilter->abstract)) {
php_bz2_filter_data *data = Z_PTR(thisfilter->abstract);
if (data->status == PHP_BZ2_RUNNING) {
BZ2_bzDecompressEnd(&(data->strm));
}
pefree(data->inbuf, data->persistent);
pefree(data->outbuf, data->persistent);
pefree(data, data->persistent);
}
}
示例9: i_stream_bzlib_close
static void i_stream_bzlib_close(struct iostream_private *stream,
bool close_parent)
{
struct bzlib_istream *zstream = (struct bzlib_istream *)stream;
if (!zstream->zs_closed) {
(void)BZ2_bzDecompressEnd(&zstream->zs);
zstream->zs_closed = TRUE;
}
if (close_parent)
i_stream_close(zstream->istream.parent);
}
示例10: throw
void CryptoManager::decodeBZ2(const u_int8_t* is, size_t sz, string& os) throw (CryptoException) {
bz_stream bs = { 0 };
if(BZ2_bzDecompressInit(&bs, 0, 0) != BZ_OK)
throw(CryptoException(STRING(DECOMPRESSION_ERROR)));
// We assume that the files aren't compressed more than 2:1...if they are it'll work anyway,
// but we'll have to do multiple passes...
size_t bufsize = 2*sz;
AutoArray<char> buf(bufsize);
bs.avail_in = sz;
bs.avail_out = bufsize;
bs.next_in = (char*)(const_cast<u_int8_t*>(is));
bs.next_out = buf;
int err;
os.clear();
while((err = BZ2_bzDecompress(&bs)) == BZ_OK) {
if (bs.avail_in == 0 && bs.avail_out > 0) { // error: BZ_UNEXPECTED_EOF
BZ2_bzDecompressEnd(&bs);
throw CryptoException(STRING(DECOMPRESSION_ERROR));
}
os.append(buf, bufsize-bs.avail_out);
bs.avail_out = bufsize;
bs.next_out = buf;
}
if(err == BZ_STREAM_END)
os.append(buf, bufsize-bs.avail_out);
BZ2_bzDecompressEnd(&bs);
if(err < 0) {
// This was a real error
throw CryptoException(STRING(DECOMPRESSION_ERROR));
}
}
示例11: HHVM_FUNCTION
Variant HHVM_FUNCTION(bzdecompress, const String& source, int small /* = 0 */) {
int source_len = source.length();
int error;
uint64_t size = 0;
bz_stream bzs;
bzs.bzalloc = nullptr;
bzs.bzfree = nullptr;
if (BZ2_bzDecompressInit(&bzs, 0, small) != BZ_OK) {
return false;
}
bzs.next_in = (char *) source.c_str();
bzs.avail_in = source_len;
// in most cases bz2 offers at least 2:1 compression, so we use that as our
// base
bzs.avail_out = source_len * 2;
String ret(bzs.avail_out, ReserveString);
bzs.next_out = ret.bufferSlice().ptr;
while ((error = BZ2_bzDecompress(&bzs)) == BZ_OK && bzs.avail_in > 0) {
/* compression is better then 2:1, need to allocate more memory */
bzs.avail_out = source_len;
size = (bzs.total_out_hi32 * (unsigned int) -1) + bzs.total_out_lo32;
ret.setSize(size); // needs to be null-terminated before the reserve call
bzs.next_out = ret.reserve(size + bzs.avail_out).ptr + size;
}
if (error == BZ_STREAM_END || error == BZ_OK) {
size = (bzs.total_out_hi32 * (unsigned int) -1) + bzs.total_out_lo32;
BZ2_bzDecompressEnd(&bzs);
ret.shrink(size);
return ret;
} else {
BZ2_bzDecompressEnd(&bzs);
return error;
}
}
示例12: squash_bz2_stream_destroy
static void
squash_bz2_stream_destroy (void* stream) {
switch (((SquashStream*) stream)->stream_type) {
case SQUASH_STREAM_COMPRESS:
BZ2_bzCompressEnd (&(((SquashBZ2Stream*) stream)->stream));
break;
case SQUASH_STREAM_DECOMPRESS:
BZ2_bzDecompressEnd (&(((SquashBZ2Stream*) stream)->stream));
break;
}
squash_stream_destroy (stream);
}
示例13: BZ_API
/*---------------------------------------------------*/
void BZ_API(BZ2_bzReadClose) ( int *bzerror, BZFILE *b )
{
bzFile* bzf = (bzFile*)b;
BZ_SETERR(BZ_OK);
if (bzf == NULL)
{ BZ_SETERR(BZ_OK); return; };
if (bzf->writing)
{ BZ_SETERR(BZ_SEQUENCE_ERROR); return; };
if (bzf->initialisedOk)
(void)BZ2_bzDecompressEnd ( &(bzf->strm) );
free ( bzf );
}
示例14: BZ2_bzDecompressEnd
// Close file stream
bool FXBZFileStream::close(){
if(dir){
if(dir==FXStreamLoad){
FXFileStream::close();
BZ2_bzDecompressEnd(&bz->stream);
}
else{
ac=BZ_FINISH;
FXFileStream::close();
BZ2_bzCompressEnd(&bz->stream);
}
FXFREE(&bz);
return true;
}
return false;
}
示例15: tear_down_mode
static tsf_bool_t tear_down_mode(tsf_adpt_rdr_t *reader,
uint8_t **spillover,
uint32_t *spillover_len) {
tsf_bool_t stillok=tsf_true;
if (reader->mode==TSF_ZIP_ZLIB) {
#ifdef HAVE_ZLIB
inflateEnd(Cz(reader));
#endif
} else if (reader->mode==TSF_ZIP_BZIP2) {
#ifdef HAVE_BZIP2
BZ2_bzDecompressEnd(Cbz(reader));
#endif
}
if (reader->mode==TSF_ZIP_ZLIB ||
reader->mode==TSF_ZIP_BZIP2) {
free(reader->stream);
if (spillover!=NULL && spillover_len!=NULL) {
*spillover=malloc(reader->abstract.avail_in);
if (*spillover==NULL) {
tsf_set_errno("Could not allocate spillover buffer");
stillok=tsf_false;
} else {
*spillover_len=reader->abstract.avail_in;
memcpy(*spillover,reader->abstract.next_in,*spillover_len);
}
}
} else if (reader->mode==TSF_ZIP_NONE) {
if (spillover!=NULL && spillover_len!=NULL) {
*spillover=malloc(reader->puti-reader->geti);
if (*spillover==NULL) {
tsf_set_errno("Could not allocate spillover buffer");
stillok=tsf_false;
} else {
*spillover_len=reader->puti-reader->geti;
memcpy(*spillover,reader->buf+reader->geti,*spillover_len);
}
}
}
if (reader->mode!=TSF_ZIP_UNKNOWN) {
free(reader->buf);
}
reader->stream=NULL;
reader->buf=NULL;
reader->buf_size=0;
reader->mode=TSF_ZIP_UNKNOWN;
return stillok;
}