首页 > 代码库 > web服务交互中HTTP数据内容GZIP,ZLIB格式压缩与解压缩封装(共享)
web服务交互中HTTP数据内容GZIP,ZLIB格式压缩与解压缩封装(共享)
点击下载独立的dll
//dll内部封装API格式
//gzip BOOL fnZlibDecompressPacket (__IN_PARAM unsigned char* gZlibDataBuffer, __IN_PARAM size_t gZLibDataLength, __OUT_PARAM char* pChDataBuffer, __OUT_PARAM DWORD *pdwLength); BOOL fnZlibCompressPacket (__IN_PARAM unsigned char* gZlibDataBuffer, __IN_PARAM size_t gZLibDataLength, __OUT_PARAM char * pchGzipOutData, __OUT_PARAM DWORD *pdwLength); //zlib BOOL fnGzipDecompressPacket (__IN_PARAM unsigned char* gzipDataBuffer, __IN_PARAM size_t gzipDataBuffer_Length, __OUT_PARAM char* pChDataBuffer, __OUT_PARAM DWORD *pdwLength); BOOL fnGzipCompressPacket (__IN_PARAM const char * gzipDataBuffer, __IN_PARAM int gzipDataBuffer_Length, __OUT_PARAM char * dstDataBuffer, __OUT_PARAM int *pdwLength);
//GZIP调用核心代码演示
typedef BOOL (*UncompressionGzipPacketToBuffer)(unsigned char* gZipDataBuffer, size_t gZipDataLength, const char * pDataBuffer,DWORD *dwLength); typedef BOOL (*CompressionBufferPacketToGzip)( unsigned char* chDataBuffer, size_t chDataLength, const char* pGzipBuffer,DWORD *dwLength); HINSTANCE hInst=NULL; UncompressionGzipPacketToBuffer UngzipPacket; CompressionBufferPacketToGzip ComGzipBuffer; hInst=LoadLibrary(_T("GzipZlibdll.dll")); if (hInst==NULL) { return -1; } UngzipPacket=(UncompressionGzipPacketToBuffer)GetProcAddress(hInst,"fnGzipDecompressPacket"); ComGzipBuffer=(CompressionBufferPacketToGzip)GetProcAddress(hInst,"fnGzipCompressPacket"); if (UngzipPacket==NULL) { return -1; } if (ComGzipBuffer==NULL) { return -1; } BOOL bRet=UngzipPacket((unsigned char*)pChGzipBuff,dwReaded,pChDataBuff,&dwTransferSize); //注意此处dwGzipSize的必须有值,不能传递0考虑到压缩之后一定比原来数据小,传递dwTransferSize大小即可 BOOL bReturn=ComGzipBuffer((unsigned char*)pChDataBuff,dwTransferSize,pChGzipBuff,&dwGzipSize); FreeLibrary(hInst);
//zlib同上示例。
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。