压缩和解压缩GZIP文件

  1. #include <ezgzip.h>
  2. #include <f32file.h>
  3. void CompressGZipFileL(RFs &aFs, TInt aBufferSize, const TDesC& aFileName)
  4. {
  5.    RFile input;
  6.    HBufC *compressedFile = HBufC::NewLC(aFileName.Length()+3);
  7.   _LIT(KCompressedGZipFileName,"%S.gz");
  8.   compressedFile->Des().Format(KCompressedGZipFileName,&aFileName);
  9.       
  10.   User::LeaveIfError(input.Open(aFs,aFileName,EFileStream | EFileRead | EFileShareAny));
  11.   CleanupClosePushL(input);
  12.   CEZFileToGZip *fileToGZip = CEZFileToGZip::NewLC(aFs,*compressedFile,input,aBufferSize);
  13.       
  14.   _LIT(KCompressingToGZipFile,"Compressing file %S to gzip file %S/n");
  15.   console->Printf(KCompressingToGZipFile,&aFileName,compressedFile);
  16.       
  17.   while (fileToGZip->DeflateL())
  18.     {
  19.     // loop here until the gzip file is created
  20.     }
  21.     
  22.   CleanupStack::PopAndDestroy(3); //fileToGZip, input, compressedFile
  23. }
  24. void DecompressGZipFileL(RFs &aFs, TInt aBufferSize, const TDesC& aFileName)
  25. {
  26.   TInt err(KErrNone);
  27.   RFile output;
  28.       
  29.   HBufC *decompressedFile = HBufC::NewLC(aFileName.Length()+1);
  30.   _LIT(KDecompressedGZipFileName,"%S_");
  31.   decompressedFile->Des().Format(KDecompressedGZipFileName,&aFileName);
  32.       
  33.   err = output.Create(aFs, *decompressedFile,EFileStream | EFileWrite |
  34.  EFileShareExclusive);
  35.   if (err == KErrAlreadyExists)
  36.     User::LeaveIfError(output.Open(aFs, *decompressedFile,EFileStream |
  37.  EFileWrite | EFileShareExclusive));
  38.   else 
  39.     User::LeaveIfError(err);
  40.   CleanupClosePushL(output);
  41.       
  42.   CEZGZipToFile *gZipToFile = CEZGZipToFile::NewLC(aFs,aFileName,output,aBufferSize);
  43.       
  44.   _LIT(KDecompressingFromGZipFile,"Decompressing file %S from gzip file %S/n");
  45.   console->Printf(KDecompressingFromGZipFile, decompressedFile, &aFileName);
  46.       
  47.   while (gZipToFile->InflateL())
  48.     {
  49.     // loop here until the gzip file is decompressed
  50.     }
  51.     CleanupStack::PopAndDestroy(3); //gZipToFile, output, decompressedFile
  52. }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值