首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

如何用zlib解压gzip数据

2012-04-12 
怎么用zlib解压gzip数据怎么用zib库去解压gzipint ZEXPORT uncompress (dest, destLen, source, sourceLen

怎么用zlib解压gzip数据
怎么用zib库去解压gzip
int ZEXPORT uncompress (dest, destLen, source, sourceLen)
  Bytef *dest;
  uLongf *destLen;
  const Bytef *source;
  uLong sourceLen;
{
  z_stream stream;
  int err;

  stream.next_in = (Bytef*)source;
  stream.avail_in = (uInt)sourceLen;
  /* Check for source > 64K on 16-bit machine: */
  if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;

  stream.next_out = dest;
  stream.avail_out = (uInt)*destLen;
  if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;

  stream.zalloc = (alloc_func)0;
  stream.zfree = (free_func)0;

  err = inflateInit2(&stream,15);
  if (err != Z_OK) return err;

  err = inflate(&stream, Z_NO_FLUSH);
  if (err != Z_STREAM_END) {
  inflateEnd(&stream);
  if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))
  return Z_DATA_ERROR;
  return err;
  }
  *destLen = stream.total_out;

  err = inflateEnd(&stream);
  return err;
}
这个解压zlib的,解压gzib怎么写呢

[解决办法]
自己写?学习。。
[解决办法]
你没仔细看文档吧
http://www.zlib.net/manual.html

int uncompress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen); 
Decompresses the source buffer into the destination buffer. sourceLen is the byte length of the source buffer. Upon entry, destLen is the total size of the destination buffer, which must be large enough to hold the entire uncompressed data. (The size of the uncompressed data must have been saved previously by the compressor and transmitted to the decompressor by some mechanism outside the scope of this compression library.) Upon exit, destLen is the actual size of the uncompressed buffer. 
This function can be used to decompress a whole file at once if the input file is mmap'ed. 

uncompress returns Z_OK if success, Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR if there was not enough room in the output buffer, or Z_DATA_ERROR if the input data was corrupted. 



int gzread (gzFile file, voidp buf, unsigned len); 
Reads the given number of uncompressed bytes from the compressed file. If the input file was not in gzip format, gzread copies the given number of bytes into the buffer. 
gzread returns the number of uncompressed bytes actually read (0 for end of file, -1 for error). 

............

热点排行