首页 > Web开发 > 详细

web服务交互中HTTP数据内容GZIP,ZLIB格式压缩与解压缩封装(共享)

时间:2014-08-04 14:24:27      阅读:378      评论:0      收藏:0      [点我收藏+]

点击下载独立的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同上示例。

web服务交互中HTTP数据内容GZIP,ZLIB格式压缩与解压缩封装(共享),布布扣,bubuko.com

web服务交互中HTTP数据内容GZIP,ZLIB格式压缩与解压缩封装(共享)

原文:http://blog.csdn.net/microzone/article/details/38367797

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!