当前位置: 首页>>代码示例>>C++>>正文


C++ deflateInit函数代码示例

本文整理汇总了C++中deflateInit函数的典型用法代码示例。如果您正苦于以下问题:C++ deflateInit函数的具体用法?C++ deflateInit怎么用?C++ deflateInit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了deflateInit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: memset

BUFFER* BUFFER::compressZlib()
{
	z_stream strm;
	int ret;
	memset(&strm, 0, sizeof(z_stream));
	char* dest = (char*)malloc(_size);
	if(deflateInit(&strm, Z_BEST_COMPRESSION) != Z_OK) { Com_Error(false, "Failed to compress zlib buffer!"); return NULL; }
	strm.next_out = (Bytef*)dest;
	strm.next_in = (Bytef*)_origin;
	strm.avail_out = _size;
	strm.avail_in = _size;
	
	ret = deflate(&strm, Z_FINISH);
	if(ret != Z_STREAM_END) { Com_Error(false, "Failed to compress zlib buffer!"); return NULL; }
	ret = deflateEnd(&strm);
	if(ret != Z_OK) { Com_Error(false, "Failed to compress zlib buffer!"); return NULL; }
	return new BUFFER(dest, strm.total_out);
}
开发者ID:DidUknowiPwn,项目名称:zonebuilder,代码行数:18,代码来源:Buffers.cpp

示例2:

/*************************************************************************
 *
 * NAME  DeflateStream::DeflateStream()
 *
 * SYNOPSIS
 *   DeflateStream::DeflateStream (ofs)
 *   DeflateStream::DeflateStream (ofstream &)
 *
 * DESCRIPTION
 *   Constructor for DeflateStream, assign the ofstream ofs to be deflated
 *
 * INPUTS
 *   ofs                    - an ofstream
 *           
 * RESULT    
 *   none
 *           
 * KNOWN BUGS
 *   none
 *           
 ******/     
DeflateStream::DeflateStream(std::ofstream *ofs)
{
    int status;
    this->errornum=0;
    this->ofs=ofs;

    this->zstrm.next_out=this->output_buffer;
    this->zstrm.avail_out=BUFFER_SIZE;
    this->zstrm.opaque=Z_NULL;
    this->zstrm.zalloc=Z_NULL;
    this->zstrm.zfree=Z_NULL;
    this->zstrm.opaque=Z_NULL;

    status=deflateInit(&this->zstrm,Z_DEFAULT_COMPRESSION);
    if (status!=Z_OK)
        this->errornum=1;

}
开发者ID:m6502,项目名称:ztrackerprime,代码行数:39,代码来源:zlib_wrapper.cpp

示例3: lz_deflate_new

static int lz_deflate_new(lua_State *L) {
    int level = luaL_optint(L, 1, Z_DEFAULT_COMPRESSION);

    /*  Allocate the stream: */
    z_stream* stream = (z_stream*)lua_newuserdata(L, sizeof(z_stream));

    stream->zalloc = Z_NULL;
    stream->zfree  = Z_NULL;
    lz_assert(L, deflateInit(stream, level), stream, __FILE__, __LINE__);

    /*  Don't allow destructor to execute unless deflateInit was successful: */
    luaL_getmetatable(L, "lz.deflate.meta");
    lua_setmetatable(L, -2);

    lua_pushnil(L);
    lua_pushcclosure(L, lz_deflate, 2);
    return 1;
}
开发者ID:zorbathut,项目名称:lua-zlib,代码行数:18,代码来源:lua_zlib.c

示例4: deflate_init

int deflate_init(struct comp_ctx **comp_ctx, int level)
{
	z_stream *strm;

	if (init_comp_ctx(comp_ctx) < 0)
		return -1;

	strm = &(*comp_ctx)->strm;

	if (deflateInit(strm, level) != Z_OK) {
		deinit_comp_ctx(comp_ctx);
		return -1;
	}

	(*comp_ctx)->cur_lvl = level;

	return 0;
}
开发者ID:btorch,项目名称:haproxy,代码行数:18,代码来源:compression.c

示例5: zlib_deflate

static void zlib_deflate(ge_Buffer* b_out, ge_Buffer* b_in){
	int ret, flush;
	unsigned have;
	z_stream strm;
	unsigned char in[CHUNK];
	unsigned char out[CHUNK];

	/* allocate deflate state */
	strm.zalloc = Z_NULL;
	strm.zfree = Z_NULL;
	strm.opaque = Z_NULL;
	ret = deflateInit(&strm, Z_DEFAULT_COMPRESSION);
	if (ret != Z_OK){
		return;
	}

	/* compress until end of file */
	do {
		strm.avail_in = geBufferRead(b_in, in, CHUNK);
		if (strm.avail_in < 0){
			break;
		}
		flush = (strm.avail_in == 0) ? Z_FINISH : Z_NO_FLUSH;
		strm.next_in = in;

		/* run deflate() on input until output buffer not full, finish
		   compression if all of source has been read in */
		do {
			strm.avail_out = CHUNK;
			strm.next_out = out;
			ret = deflate(&strm, flush);	/* no bad return value */
			have = CHUNK - strm.avail_out;
			if(geBufferWrite(b_out, out, have) != have){
				(void)deflateEnd(&strm);
				return;
			}
		} while (strm.avail_out == 0);

		/* done when last data in file processed */
	} while (flush != Z_FINISH);

	/* clean up and return */
	(void)deflateEnd(&strm);
}
开发者ID:drewet,项目名称:libge,代码行数:44,代码来源:geutils.c

示例6: zfwrite

void zfwrite(char* p_ptr, int p_size, FILE* p_fp, int p_sig)
{
	if (p_ptr && p_fp)
	{
		const int	bufsize = 1024 * 512; // 512kb
		char		buf[bufsize];

		z_stream z;
		
		z.zalloc = Z_NULL;
		z.zfree  = Z_NULL;
		z.opaque = Z_NULL;
		
		if (deflateInit(&z, Z_DEFAULT_COMPRESSION) != Z_OK && z.msg) OutputDebugString(z.msg);

		z.next_in	= (Bytef*)p_ptr;
		z.avail_in	= p_size;
		z.next_out	= (Bytef*)buf;
		z.avail_out = bufsize;
		
		/* 識別子 */
		int fsig = p_sig;
		fwrite(&fsig, 1, 4, p_fp);

		/* 元のサイズ */
		fwrite(&p_size, 1, 4, p_fp);
		
		int status = Z_OK;
		while (status != Z_STREAM_END)
		{
			status = deflate(&z, Z_FINISH);
			if (status < Z_OK && z.msg) OutputDebugString(z.msg);
			
			if (z.avail_out == 0 || status == Z_STREAM_END)
			{
				fwrite(buf, 1, bufsize - z.avail_out, p_fp);
				z.next_out = (Bytef*)buf;
				z.avail_out = bufsize;
			}
		}
		
		if (deflateEnd(&z) != Z_OK && z.msg) OutputDebugString(z.msg);
	}
}
开发者ID:ggnauthor,项目名称:ggxxnet,代码行数:44,代码来源:zlib.cpp

示例7: switch

int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size,Mode p_mode) {

	switch(p_mode) {
		case MODE_FASTLZ: {

			if (p_src_size<16) {
				uint8_t src[16];
				zeromem(&src[p_src_size],16-p_src_size);
				copymem(src,p_src,p_src_size);
				return fastlz_compress(src,16,p_dst);
			} else {
				return fastlz_compress(p_src,p_src_size,p_dst);
			}

		} break;
		case MODE_DEFLATE: {

			z_stream strm;
			strm.zalloc = zipio_alloc;
			strm.zfree = zipio_free;
			strm.opaque = Z_NULL;
			int err = deflateInit(&strm,Z_DEFAULT_COMPRESSION);
			if (err!=Z_OK)
			    return -1;

			strm.avail_in=p_src_size;
			int aout = deflateBound(&strm,p_src_size);;
			/*if (aout>p_src_size) {
				deflateEnd(&strm);
				return -1;
			}*/
			strm.avail_out=aout;
			strm.next_in=(Bytef*)p_src;
			strm.next_out=p_dst;
			deflate(&strm,Z_FINISH);
			aout = aout - strm.avail_out;
			deflateEnd(&strm);
			return aout;

		} break;
	}

	ERR_FAIL_V(-1);
}
开发者ID:lonesurvivor,项目名称:godot,代码行数:44,代码来源:compression.cpp

示例8: squeeze

static SCM squeeze(SCM source, int method) {
	z_stream strm;
	DEFLATE_BLOB *blob;
	int ret;
	size_t inlen, outlen;
	char *inbuf, *outbuf;
	strm.zalloc = Z_NULL;
	strm.zfree = Z_NULL;
	strm.opaque = Z_NULL;
	if (method == SQUEEZE_GZIP) {
		ret = deflateInit2(&strm, Z_DEFAULT_COMPRESSION,
				Z_DEFLATED, 31, 8, Z_DEFAULT_STRATEGY);
		}
	else {
		ret = deflateInit(&strm, Z_DEFAULT_COMPRESSION);
		}
	if (ret != Z_OK) {
		log_msg("zlib: deflate init failed\n");
		return SCM_BOOL_F;
		}
	inbuf = scm_to_utf8_stringn(source, &inlen);
	strm.total_in = strm.avail_in = inlen;
	strm.next_in = (unsigned char*)inbuf;
	outlen = deflateBound(&strm, inlen);
	outbuf = (char *)malloc(outlen);
	strm.total_out = 0;
	strm.avail_out = outlen;
	strm.next_out = (unsigned char *)outbuf;
	ret = deflate(&strm, Z_FINISH);
	free(inbuf);
	blob = (DEFLATE_BLOB *)scm_gc_malloc(sizeof(DEFLATE_BLOB) +
						strm.total_out, "gzip-blob");
	blob->zip_len = strm.total_out;
	blob->orig_len = inlen;
	log_msg("compress %s %d -> %d\n",
		(method == SQUEEZE_GZIP ? "gzip" : "deflate"),
		blob->orig_len, blob->zip_len);
	blob->method = method;
	ret = deflateEnd(&strm);
	if (ret != Z_OK) printf("deflateEnd: %d\n", ret);
	memcpy(blob->payload, outbuf, blob->zip_len);
	free(outbuf);
	SCM_RETURN_NEWSMOB(deflate_tag, blob);
	}
开发者ID:pmyadlowsky,项目名称:gusher,代码行数:44,代码来源:cache.c

示例9: gen_new_zstreams

/* Set up new zlib compression streams, close the old ones. Only
 * called from gen_new_keys() */
static void gen_new_zstreams() {

	/* create new zstreams */
	if (ses.newkeys->recv_algo_comp == DROPBEAR_COMP_ZLIB) {
		ses.newkeys->recv_zstream = (z_streamp)m_malloc(sizeof(z_stream));
		ses.newkeys->recv_zstream->zalloc = Z_NULL;
		ses.newkeys->recv_zstream->zfree = Z_NULL;
		
		if (inflateInit(ses.newkeys->recv_zstream) != Z_OK) {
			dropbear_exit("zlib error");
		}
	} else {
		ses.newkeys->recv_zstream = NULL;
	}

	if (ses.newkeys->trans_algo_comp == DROPBEAR_COMP_ZLIB) {
		ses.newkeys->trans_zstream = (z_streamp)m_malloc(sizeof(z_stream));
		ses.newkeys->trans_zstream->zalloc = Z_NULL;
		ses.newkeys->trans_zstream->zfree = Z_NULL;
	
		if (deflateInit(ses.newkeys->trans_zstream, Z_DEFAULT_COMPRESSION) 
				!= Z_OK) {
			dropbear_exit("zlib error");
		}
	} else {
		ses.newkeys->trans_zstream = NULL;
	}
	
	/* clean up old keys */
	if (ses.keys->recv_zstream != NULL) {
		if (inflateEnd(ses.keys->recv_zstream) == Z_STREAM_ERROR) {
			/* Z_DATA_ERROR is ok, just means that stream isn't ended */
			dropbear_exit("crypto error");
		}
		m_free(ses.keys->recv_zstream);
	}
	if (ses.keys->trans_zstream != NULL) {
		if (deflateEnd(ses.keys->trans_zstream) == Z_STREAM_ERROR) {
			/* Z_DATA_ERROR is ok, just means that stream isn't ended */
			dropbear_exit("crypto error");
		}
		m_free(ses.keys->trans_zstream);
	}
}
开发者ID:TheTypoMaster,项目名称:AH4222,代码行数:46,代码来源:kex.c

示例10: compressZlib

void compressZlib(SharedBuffer<u8> data, std::ostream &os)
{
	z_stream z;
	const s32 bufsize = 16384;
	char output_buffer[bufsize];
	int status = 0;
	int ret;

	z.zalloc = Z_NULL;
	z.zfree = Z_NULL;
	z.opaque = Z_NULL;

	ret = deflateInit(&z, -1);
	if(ret != Z_OK)
		throw SerializationError("compressZlib: deflateInit failed");
	
	// Point zlib to our input buffer
	z.next_in = (Bytef*)&data[0];
	z.avail_in = data.getSize();
	// And get all output
	for(;;)
	{
		z.next_out = (Bytef*)output_buffer;
		z.avail_out = bufsize;
		
		status = deflate(&z, Z_FINISH);
		if(status == Z_NEED_DICT || status == Z_DATA_ERROR
				|| status == Z_MEM_ERROR)
		{
			zerr(status);
			throw SerializationError("compressZlib: deflate failed");
		}
		int count = bufsize - z.avail_out;
		if(count)
			os.write(output_buffer, count);
		// This determines zlib has given all output
		if(status == Z_STREAM_END)
			break;
	}

	deflateEnd(&z);

}
开发者ID:AMDmi3,项目名称:minetest,代码行数:43,代码来源:serialization.cpp

示例11: inflateInit

// Don't call this outside of the constructor.
void TZlibTransport::initZlib() {
  int rv;
  bool r_init = false;
  try {
    rstream_ = new z_stream;
    wstream_ = new z_stream;

    rstream_->zalloc = Z_NULL;
    wstream_->zalloc = Z_NULL;
    rstream_->zfree  = Z_NULL;
    wstream_->zfree  = Z_NULL;
    rstream_->opaque = Z_NULL;
    wstream_->opaque = Z_NULL;

    rstream_->next_in   = crbuf_;
    wstream_->next_in   = uwbuf_;
    rstream_->next_out  = urbuf_;
    wstream_->next_out  = cwbuf_;
    rstream_->avail_in  = 0;
    wstream_->avail_in  = 0;
    rstream_->avail_out = urbuf_size_;
    wstream_->avail_out = cwbuf_size_;

    rv = inflateInit(rstream_);
    checkZlibRv(rv, rstream_->msg);

    // Have to set this flag so we know whether to de-initialize.
    r_init = true;

    rv = deflateInit(wstream_, Z_DEFAULT_COMPRESSION);
    checkZlibRv(rv, wstream_->msg);
  }

  catch (...) {
    if (r_init) {
      rv = inflateEnd(rstream_);
      checkZlibRvNothrow(rv, rstream_->msg);
    }
    // There is no way we can get here if wstream_ was initialized.

    throw;
  }
}
开发者ID:ahfeel,项目名称:thrift,代码行数:44,代码来源:TZlibTransport.cpp

示例12: block_deflate

size_t
block_deflate(uint8_t *uncompr, uint8_t *compr, const size_t len)
{
	z_stream c_stream;
	int err;

	if (len == 0)
		return (0);

	c_stream.zalloc = myalloc;
	c_stream.zfree = myfree;
	c_stream.opaque = NULL;

	err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
	check_err(err, "deflateInit");

	c_stream.next_in  = uncompr;
	c_stream.next_out = compr;
	c_stream.avail_in = len;
	c_stream.avail_out = len*2u +512u;

	while (c_stream.total_in != len && c_stream.total_out < (len*2u + 512u)) {
		err = deflate(&c_stream, Z_NO_FLUSH);
#ifdef DEBUG
		printf("deflate progress: len = %zd  total_in = %lu  total_out = %lu\n", len, c_stream.total_in, c_stream.total_out);
#endif
		check_err(err, "deflate(..., Z_NO_FLUSH)");
	}

	for (;;) {
		err = deflate(&c_stream, Z_FINISH);
#ifdef DEBUG
		printf("deflate    final: len = %zd  total_in = %lu  total_out = %lu\n", len, c_stream.total_in, c_stream.total_out);
#endif
		if (err == Z_STREAM_END) break;
		check_err(err, "deflate(..., Z_STREAM_END)");
	}

	err = deflateEnd(&c_stream);
	check_err(err, "deflateEnd");

	return ((size_t)c_stream.total_out);
}
开发者ID:hmatyschok,项目名称:MeshBSD,代码行数:43,代码来源:unit_test.c

示例13: DATA

IoObject *IoZlibEncoder_beginProcessing(IoZlibEncoder *self, IoObject *locals, IoMessage *m)
{
	/*doc ZlibEncoder beginProcessing
	Initializes the algorithm.
	*/
	
	z_stream *strm = DATA(self)->strm;
	int ret;

	strm->zalloc = Z_NULL;
	strm->zfree = Z_NULL;
	strm->opaque = Z_NULL;
	strm->avail_in = 0;
	strm->next_in = Z_NULL;
	ret = deflateInit(strm, DATA(self)->level);
	IOASSERT(ret == Z_OK, "unable to initialize zlib via inflateInit()");

	return self;
}
开发者ID:ADTSH,项目名称:io,代码行数:19,代码来源:IoZlibEncoder.c

示例14: zip_init

/*
** zip_init
**      Initialize compression structures for a server.
**      If failed, zip_free() has to be called.
*/
int     zip_init(aClient *cptr, int compressionlevel)
{
  cptr->zip  = (aZdata *) MyMalloc(sizeof(aZdata));
  cptr->zip->incount = 0;
  cptr->zip->outcount = 0;

  cptr->zip->in  = (z_stream *) MyMalloc(sizeof(z_stream));
  bzero(cptr->zip->in, sizeof(z_stream)); /* Just to be sure -- Syzop */
  cptr->zip->in->total_in = 0;
  cptr->zip->in->total_out = 0;
  cptr->zip->in->zalloc = NULL;
  cptr->zip->in->zfree = NULL;
  cptr->zip->in->data_type = Z_ASCII;
  if (inflateInit(cptr->zip->in) != Z_OK)
    {
      cptr->zip->out = NULL;
      return -1;
    }

  cptr->zip->out = (z_stream *) MyMalloc(sizeof(z_stream));
  bzero(cptr->zip->out, sizeof(z_stream)); /* Just to be sure -- Syzop */
  cptr->zip->out->total_in = 0;
  cptr->zip->out->total_out = 0;
  cptr->zip->out->zalloc = NULL;
  cptr->zip->out->zfree = NULL;
  cptr->zip->out->data_type = Z_ASCII;
  if (deflateInit(cptr->zip->out, compressionlevel) != Z_OK)
    return -1;

  if (!unzipbuf)
  {
  	unzipbuf = MyMallocEx(UNZIP_BUFFER_SIZE); /* big chunk! */
  	if (!unzipbuf)
  	{
  		ircd_log(LOG_ERROR, "zip_init(): out of memory (trying to alloc %d bytes)!", UNZIP_BUFFER_SIZE);
  		sendto_realops("zip_init(): out of memory (trying to alloc %d bytes)!", UNZIP_BUFFER_SIZE);
  		return -1;
  	}
  }


  return 0;
}
开发者ID:Adam-,项目名称:unrealircd,代码行数:48,代码来源:zip.c

示例15: compress_cb

static int compress_cb(lua_State* L)
{
	size_t srcsize;
	const char* srcbuffer = luaL_checklstring(L, 1, &srcsize);

	int outputchunks = 0;
	uint8_t outputbuffer[64*1024];

	z_stream zs = {0};
	int i = deflateInit(&zs, 1);
	if (i != Z_OK)
		return 0;

	zs.avail_in = srcsize;
	zs.next_in = (uint8_t*) srcbuffer;

	luaL_checkstack(L, STACKSIZE, "out of memory");
	do
	{
		zs.avail_out = sizeof(outputbuffer);
		zs.next_out = outputbuffer;

		i = deflate(&zs, Z_FINISH);

		int have = sizeof(outputbuffer) - zs.avail_out;
		lua_pushlstring(L, (char*) outputbuffer, have);
		outputchunks++;

		if (outputchunks == (STACKSIZE-1))
		{
			/* Stack full! Concatenate what we've got, to empty the stack, and
			 * keep going. This will only happen on very large input files. */
			lua_concat(L, outputchunks);
			outputchunks = 1;
		}
	}
	while (i != Z_STREAM_END);

	(void)deflateEnd(&zs);

	lua_concat(L, outputchunks);
	return 1;
}
开发者ID:NRauh,项目名称:wordgrinder,代码行数:43,代码来源:zip.c


注:本文中的deflateInit函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。