16,472
社区成员
发帖
与我相关
我的任务
分享
CString str=_T(""); // 全部内容
CStdioFile file; // 文件对象
if(!file.Open("D:\\1.W3G",CFile::modeRead | CFile::typeBinary,NULL))
{
//CString strTemp;
//strTemp.Format(_T("Open file error:%d"),GetLastError());
//MessageBox(strTemp);
// return false;
}
int len = file.GetLength()+1;
unsigned char szStr[1024] = {0};
file.Read(szStr,file.GetLength());
file.Flush();
file.Close();
CString strc,strc2,strc3;
const unsigned char strSrc[] = "English test\n中文测试";
unsigned char buff[1024] = {0},strDst[1024] = {0};
memcpy(buff,szStr+50,400);
//解压缩
uncompress(strDst, &dstLen, buff, bufLen);
strc3.Format("\nAfter UnCompressed Length:%d\nUnCompressed String:%s\n", dstLen, strDst);
#include <cstring>
#include <cstdlib>
#include <iostream>
#include "zlib.h"
using namespace std;
int main()
{
int err;
Byte compr[200], uncompr[200]; // big enough
uLong comprLen, uncomprLen;
const char* hello = "12345678901234567890123456789012345678901234567890";
uLong len = strlen(hello) + 1;
comprLen = sizeof(compr) / sizeof(compr[0]);
err = compress(compr, &comprLen, (const Bytef*)hello, len);
if (err != Z_OK) {
cerr << "compess error: " << err << '/n';
exit(1);
}
cout << "orignal size: " << len
<< " , compressed size : " << comprLen << '/n';
strcpy((char*)uncompr, "garbage");
err = uncompress(uncompr, &uncomprLen, compr, comprLen);
if (err != Z_OK) {
cerr << "uncompess error: " << err << '/n';
exit(1);
}
cout << "orignal size: " << len
<< " , uncompressed size : " << uncomprLen << '/n';
if (strcmp((char*)uncompr, hello)) {
cerr << "BAD uncompress!!!/n";
exit(1);
} else {
cout << "uncompress() succeed: /n" << (char *)uncompr;
}
}
if(!file.Open("D:\\1.W3G",CFile::modeRead | CFile::typeBinary,NULL))
{
}
int len = file.GetLength()+1;
unsigned char szStr[1024] = {0};
file.Read(szStr,file.GetLength());
file.Flush();
file.Close();
unsigned char buff[1024] = {0},strDst[1024*16] = {0};
unsigned long srcLen = sizeof(szStr),bufLen = sizeof(buff),dstLen = sizeof(strDst);
memcpy(buff,szStr+76,420);
int x = uncompress(strDst, &dstLen, buff, bufLen);
if(!file.Open("D:\\2.W3G",CFile::modeWrite | CFile::typeBinary,NULL))
{
}
file.Write(strDst,dstLen);