std::string fullPath = FileUtils::getInstance()->fullPathForFilename("CMakeLists.txt");
FILE *fp = fopen(fullPath.c_str(), "rb");
fseek(fp,0,SEEK_END);
unsigned long size = ftell(fp);
fseek(fp,0,SEEK_SET);
unsigned char* buffer = (unsigned char*)malloc(sizeof(unsigned char) * size);
unsigned long readsize = fread(buffer, sizeof(unsigned char), size, fp);
fclose(fp);
unsigned char* bufferDes = (unsigned char*)malloc(sizeof(unsigned char) * readsize*2);
unsigned long dstEntrySize = readsize*2;
int result = compress(bufferDes,&dstEntrySize,buffer,size);
free(buffer);
if(result==Z_OK)
{
FILE *fp2 = fopen("/Users/liuxy/zlibDemo/Resources/dddd.txt", "wb");
fwrite(bufferDes, dstEntrySize, sizeof(unsigned char), fp2);
fclose(fp2);
}
FILE *fp = fopen("/Users/liuxy/zlibDemo/Resources/dddd.dd", "rb");
fseek(fp,0,SEEK_END);
unsigned long size = ftell(fp);
fseek(fp,0,SEEK_SET);
unsigned char* buffer = (unsigned char*)malloc(sizeof(unsigned char) * size);
unsigned long readsize = fread(buffer, sizeof(unsigned char), size, fp);
fclose(fp);
unsigned char* bufferDes = (unsigned char*)malloc(sizeof(unsigned char) * readsize *100);
unsigned long dstEntrySize = readsize *100;
int result = uncompress(bufferDes,&dstEntrySize,buffer,size);
free(buffer);
if(result==Z_OK)
{
FILE *fp2 = fopen("/Users/liuxy/zlibDemo/Resources/dddd.txt", "wb");
fwrite(bufferDes, dstEntrySize, sizeof(unsigned char), fp2);
fclose(fp2);
}
文件压缩算法
最新推荐文章于 2022-04-12 10:37:15 发布