symbian压缩和解压缩GZIP文件

news/2024/7/4 7:25:51

开发伙伴平台:
S60 3rd Edition, FP1

详细描述
下列代码片段演示了如何压缩和解压缩GZIP文件,这里使用了CEZFileToGZip类和CEZGZipToFi类。代码可以通过自签名执行。

MMP文件
需要下列链接库

Code:
LIBRARY efsrv.lib
LIBRARY ezlib.lib

源文件

Code:
#include <ezgzip.h>
#include <f32file.h>

void CompressGZipFileL(RFs &aFs, TInt aBufferSize, const TDesC& aFileName)
{
RFile input;

HBufC *compressedFile = HBufC::NewLC(aFileName.Length()+3);
_LIT(KCompressedGZipFileName,"%S.gz");
compressedFile->Des().Format(KCompressedGZipFileName,&aFileName);

User::LeaveIfError(input.Open(aFs,aFileName,EFileStream | EFileRead | EFileShareAny));
CleanupClosePushL(input);

CEZFileToGZip *fileToGZip = CEZFileToGZip::NewLC(aFs,*compressedFile,input,aBufferSize);

_LIT(KCompressingToGZipFile,"Compressing file %S to gzip file %S/n");
console->Printf(KCompressingToGZipFile,&aFileName,compressedFile);

while (fileToGZip->DeflateL())
{
// loop here until the gzip file is created
}

CleanupStack::PopAndDestroy(3); //fileToGZip, input, compressedFile
}

void DecompressGZipFileL(RFs &aFs, TInt aBufferSize, const TDesC& aFileName)
{
TInt err(KErrNone);
RFile output;

HBufC *decompressedFile = HBufC::NewLC(aFileName.Length()+1);
_LIT(KDecompressedGZipFileName,"%S_");
decompressedFile->Des().Format(KDecompressedGZipFileName,&aFileName);

err = output.Create(aFs, *decompressedFile,EFileStream | EFileWrite |
EFileShareExclusive);
if (err == KErrAlreadyExists)
User::LeaveIfError(output.Open(aFs, *decompressedFile,EFileStream |
EFileWrite | EFileShareExclusive));
else
User::LeaveIfError(err);
CleanupClosePushL(output);

CEZGZipToFile *gZipToFile = CEZGZipToFile::NewLC(aFs,aFileName,output,aBufferSize);

_LIT(KDecompressingFromGZipFile,"Decompressing file %S from gzip file %S/n");
console->Printf(KDecompressingFromGZipFile, decompressedFile, &aFileName);

while (gZipToFile->InflateL())
{
// loop here until the gzip file is decompressed
}

CleanupStack::PopAndDestroy(3); //gZipToFile, output, decompressedFile
}


使用CompressGZipFileL()和DecompressGZipFileL()方法
下面这个示例演示了通过读取命令行参数来压缩或解压缩.gz文件

选项:
* -c = compress
* -d = decompress
* -b n = buffer size
* filename = gzip file

Code:
void doGZipCompressionAndDecompressionL()
{
RFs fs;
User::LeaveIfError(fs.Connect());
CleanupClosePushL(fs);

TBool doCompress = ETrue;
TInt bufferSize = 32768;
TInt cmdLineLen = User::CommandLineLength();

if (cmdLineLen <= 0)
{
_LIT(KUsage,"Usage: program.exe [-cd] [-u buffer] filename/n");
console->Printf(KUsage);
User::Leave(KErrGeneral);
}

HBufC *argv = HBufC::NewLC(cmdLineLen);
TPtr argPtr=argv->Des();
User::CommandLine(argPtr);

TLex arguments(*argv);

TPtrC options(arguments.NextToken());
TBool bufferSizeSpecified = EFalse;

_LIT(KInvalidOption,"Invalid option %S/n");
_LIT(KUnknownOption,"Unknown option %S/n");
_LIT(KNoOptionSpecified,"No option specified/n");

while (options[0]=='-' || bufferSizeSpecified)
{
TInt index = 1;

if (bufferSizeSpecified)
{
if (options.Length() == 0)
{
console->Printf(KNoOptionSpecified);
console->Getch();
User::Leave(KErrGeneral);
}
else
{
TLex lex(options);
TInt ret(KErrNone);

ret = lex.Val(bufferSize);
bufferSizeSpecified = EFalse;

if (ret != KErrNone)
{
console->Printf(KInvalidOption,&options);
console->Getch();
User::Leave(KErrGeneral);
}
}
}
else
{
while (index < options.Length())
{
if (options[index] == 'd')
doCompress = EFalse;
else if (options[index] == 'c')
doCompress = ETrue;
else if (options[index] == 'b' )
bufferSizeSpecified = ETrue;
else
{
console->Printf(KUnknownOption,&options);
console->Getch();
User::Leave(KErrGeneral);
}
index++;
}

if (index == 1)
{
console->Printf(KNoOptionSpecified);
console->Getch();
User::Leave(KErrGeneral);
}
}
options.Set(arguments.NextToken());
}

TPtrC fileNamePtr(options);
HBufC *fileNameBuf = HBufC::NewLC(fileNamePtr.Length());
*fileNameBuf = fileNamePtr;

if(doCompress)
CompressGZipFileL(fs,bufferSize,*fileNameBuf);
else
DecompressGZipFileL(fs,bufferSize,*fileNameBuf);

CleanupStack::PopAndDestroy(3); //fileNameBuf,argv,fs
}

 


http://www.niftyadmin.cn/n/2308418.html

相关文章

symbian 使用RLibrary加载DLL

开发伙伴平台&#xff1a; S60 3rd Edition, MR 详细描述 下列代码片段演示了如何动态加载一个多态的DLL。对静态DLL来说&#xff0c;程序在启动时自动加载到RAM中。也可以在任何不需要的时候自动卸载。一个多态的 DLL可以通过调用RLibrary::Load()加载&#xff0c;以及通过…

ubuntu安装gnutls_在ubuntu中安装pyspider(注意事项)

最近生病&#xff0c;经历了半个月&#xff0c;总算是活过来了。既然没死&#xff0c;那学习就永无止境吧。今天讲讲在ubuntu中安装pyspider的注意事项吧。PySpider 是非常方便并且功能强大的爬虫框架&#xff0c;支持多线程爬取、JS动态解析&#xff0c;提供了可操作界面、出错…

合肥天鹅湖万达广场机器人_2021年元旦淮南万达广场非常热闹,商家打折促销,生意非常好...

今天是2021年的元旦&#xff0c;新年的第1天&#xff01;全省万达广场非常多&#xff0c;淮南万达开业已经接近两年&#xff0c;也是全省万达广场之一。今天我到淮南万达广场逛一逛&#xff0c;看一看。来到淮南万达广场&#xff0c;商家正忙的不亦乐乎&#xff0c;非常热闹&am…

后氧传感器正常数据_最简单实用的传感器检测方法(氧传感器、凸轮轴位置传感器等)...

1. 凸轮轴位置传感器(安装在凸轮轴上的凸轮轴位置传感器)01接插件的检测检查凸轮轴位置传感器的插接件接触是否良好&#xff0c;检测传感器插接件三个端脚之间是否有短路或严重漏电现象存在。02供电检测检测凸轮轴位置传感器端脚A所对应的插头与搭铁之间的5V供电电压是否正常&a…

aⅴgo安装包下载_【Windows系统】基于vscode搭建go语言开发环境

点蓝色字关注“CurryCoder的程序人生”微信公众号&#xff1a;CurryCoder的程序人生 怕什么真理无穷&#xff0c;进一寸有一寸的欢喜1.golang安装包下载与安装关于vscode的下载&#xff0c;请参见历史文章Ubuntu16.04下搭建vscode的C开发环境&#xff0c;本文就不再赘述啦~下面…

symbian 进度条 processbar

进度条&#xff08;Progressbar&#xff09;控件用于显示某个持续时间比较长的操作进度&#xff0c;例如邮件接受进度和文件下载进度大牛股。本节的ProgressBar示例程序显示了一个简单的进度条&#xff0c;进度随着事件增长&#xff0c;ProgressBar示例程序的运行界面如下如所示…

amd为什么还用针脚_英特尔CPU早就取消针脚了,AMD为什么还不取消?

英特尔和AMD竞争了这么多年&#xff0c;AMD唯一改变最小的恐怕就是接口了&#xff0c;到现在仍然坚持使用“老旧”的针脚式接口&#xff0c;而英特尔早在十多年以前就早早抛弃了针脚&#xff0c;使用了LGA触点式接口&#xff0c;当时人们还觉得AMD处理器不久后也将跟随英特尔全…

干活的不如写ppt的吗_吃相太难看:咱基层干活的不如写PPT的!

藏蓝观察社当下警事 警察心声 2018年8月27日晚&#xff0c;江苏省发生了著名的“昆山反杀案”&#xff0c;此案引发了全国热议&#xff0c;“正当防卫”的话题再次被摆到了桌面上。六哥一直在最基层工作&#xff0c;当然知道出了这样的“命案”一线警察将会又是多少的灯火通明的…