版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zxc024000/article/details/84032909
Gzip uncompress错误代码Z_BUF_ERROR
- 现在大多数网站都采用gzip解压缩技术来提升web应用的性能(百度、新浪等等等)。
- 某日gzip uncompress阶段,出现崩溃错误。err代码数字-5,查看对应的头文件zlib.h,确定错误原因为Z_BUF_ERROR。
#define Z_OK 0
#define Z_STREAM_END 1
#define Z_NEED_DICT 2
#define Z_ERRNO (-1)
#define Z_STREAM_ERROR (-2)
#define Z_DATA_ERROR (-3)
#define Z_MEM_ERROR (-4)
#define Z_BUF_ERROR (-5) // 这里
#define Z_VERSION_ERROR (-6)
- google了一段时间,并在程序中加log。终于找到了问题,source缓冲区(即待解压的资源)的长度为0。
- 总结一下导致Z_BUF_ERROR的原因:
- source缓冲区长度为0(没有要解压的资源,却调用解压过程)。
- dest缓冲区(解压后的资源)长度不够用来解压。