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

Posted yxwkaifa

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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, char * pDataBuffer,DWORD *dwLength);

typedef  BOOL   (*CompressionBufferPacketToGzip)
( unsigned char* chDataBuffer,  size_t chDataLength, 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格式压缩与解压缩封装(共享)的主要内容,如果未能解决你的问题,请参考以下文章

Delphi 使用 ZLib 压缩和解压 GZip

http服务器响应(套接字)的标头和内容之间的差异

Nginx系列:数据压缩

Ruby zlib 库解压 gzip 文件非常慢

zabbix准备:nginx安装

./configure: error: the HTTP gzip module requires the zlib library.