#include
#include "/zlib/include/zlib.h"
// Demonstration of zlib utility functions
unsigned long file_size(char *filename)
{
FILE *pFile = fopen(filename, "rb");
fseek (pFile, 0, SEEK_END);
unsigned long size = ftell(pFile);
fclose (pFile);
return size;
}
int decompress_one_file(char *infilename, char *outfilename)
{
gzFile infile = gzopen(infilename, "rb");
FILE *outfile = fopen(outfilename, "wb");
if (!infile || !outfile) return -1;
char buffer[128];
int num_read = 0;
while ((num_read = gzread(infile, buffer, sizeof(buffer))) > 0)
{
fwrite(buffer, 1, num_read, outfile);
}
gzclose(infile);
fclose(outfile);
}
int compress_one_file(char *infilename, char *outfilename)
{
FILE *infile = fopen(infilename, "rb");
gzFile outfile = gzopen(outfilename, "wb");
if (!infile || !outfile) return -1;
char inbuffer[128];
int num_read = 0;
unsigned long total_read = 0, total_wrote = 0;
while ((num_read = fread(inbuffer, 1, sizeof(inbuffer), infile)) > 0)
{
total_read += num_read;
gzwrite(outfile, inbuffer, num_read);
}
fclose(infile);
gzclose(outfile);
printf("Read %ld bytes, Wrote %ld bytes,
Compression factor %4.2f%%\n",
total_read, file_size(outfilename),
(1.0-file_size(outfilename)*1.0/total_read)*100.0);
}
int main(int argc, char **argv)
{
compress_one_file(argv[1],argv[2]);
decompress_one_file(argv[2],argv[3]);
}
2008年1月8日星期二
几个关于zlib的小程序
订阅:
博文评论 (Atom)
我的简介
博客归档
-
▼
2008
(44)
-
▼
一月
(20)
- Clistctrl自动下滚
- VC++ 改变Dialog窗口大小及定位,SetWindowPos()
- CString 剖析
- VC++ 删除整个文件夹
- VC++, CString to CTime, CTime to CString
- VC++ boost: regex应用
- _access 可判断文件夹是否存在及访问权限
- VC++ 从数据文件一次读一行
- VC++得到当前系统时间日期 GetSystemTime()
- CTabCtrl控件
- Corrupt apollo.mdb bings unpack.exe "Failed to ...
- SetFileAttributes,更改文件写保护属性
- 常用的字符串处理函数
- 几个关于zlib的小程序
- zlib dll包的使用
- zlib(integrity check)解压文件完整性检查 方案一:(未决)
- Problem:header datei CUnpackView.h nicht gefunden ...
- SHBrowseForFolder设置初始目录中CALLBACK函数的使用
- VC++获取文件修改时间
- 修改MFC标题栏上的图标
-
▼
一月
(20)
没有评论:
发表评论