分享

Compress zlib

 smallarmy 2008-02-16
Ezlib.lib
Estlib.lib
#include <stdio.h>
#include <zlib.h>
#include <stdlib.h>
#include <string.h>
 {
 int err;
 z_stream c_stream; /* compression stream */
 Byte * compr;
 uLong comprLen = 20*sizeof(int);
 compr    = (Byte*)calloc((uInt)comprLen, 1);
 const char hello[] = "hello, hello!";
 uLong len = (uLong)strlen(hello)+1;
 c_stream.zalloc = (alloc_func)0;
 c_stream.zfree = (free_func)0;
 c_stream.opaque = (voidpf)0;
 err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
 c_stream.next_in  = (Bytef*)hello;
 c_stream.next_out = compr;
 while (c_stream.total_in != len && c_stream.total_out < comprLen)
  {
  c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */
  err = deflate(&c_stream, Z_NO_FLUSH);
  }    /* Finish the stream, still forcing small buffers: */
  deflateEnd(&c_stream);
  free(compr);
 } 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多