- #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
- }
压缩和解压缩GZIP文件
最新推荐文章于 2020-05-03 14:46:06 发布