×
Namespaces

Variants
Actions

获得GZIP文件尾部和头部的信息

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

文章
hoolee 在 26 Jun 2008 创建
最后由 hamishwillee 在 15 Dec 2011 编辑

CS000948


  • 开发伙伴平台:

S60 3rd Edition, FP1


  • 详细描述

下列代码片段演示了如何获得GZIP文件的头部和尾部信息。GZIP尾部信息应包含以下数据:

CRC32

Input size(从原始未压缩的文件计算得到)


而实际GZIP头信息定义包含了如下字段:

Fixed value for ID1 = 31 
Fixed value for ID2 = 139
Compression method (8 is the standard)
Flags (0 = no flags are set)
Modification time (time stamp in Unix format)
Extra flags (maximum compression - fastest algorithm)
Operating System

代码通过通过自签名执行.


MMP文件

需要下列链接库

LIBRARY efsrv.lib
LIBRARY ezlib.lib


源文件

#include <ezgzip.h>
#include <f32file.h>
 
 
void GetGZipFileTrailerAndHeaderInfoL(RFs& aRfs, const TDesC& aFileName)
{
RFile file;
TEZGZipHeader header;
TEZGZipTrailer trailer;
 
if (!EZGZipFile::IsGzipFileL(aRfs,aFileName))
{
_LIT(KIsNotGZipFile,"File:%S is not in GZip format\n");
console->Printf(KIsNotGZipFile,&aFileName);
console->Getch();
User::Leave(KErrGeneral);
}
 
EZGZipFile::LocateAndReadTrailerL(aRfs, aFileName, trailer);
_LIT(KTrailer,"CRC32 = %d size = %d\n");
console->Printf(KTrailer,trailer.iCrc32,trailer.iSize);
 
User::LeaveIfError(file.Open(aRfs,aFileName,EFileStream | EFileRead | EFileShareAny));
EZGZipFile::ReadHeaderL(file, header);
 
_LIT(KFileId1,"ID1 = %d\n");
console->Printf(KFileId1,header.iId1);
_LIT(KFileId2,"ID2 = %d\n");
console->Printf(KFileId2,header.iId2);
_LIT(KCompressionMethod,"compression method = %d\n");
console->Printf(KCompressionMethod,header.iCompressionMethod);
_LIT(KFlags,"flags = %d\n");
console->Printf(KFlags,header.iFlags);
_LIT(KTimeStamp,"time stamp = %d\n");
console->Printf(KTimeStamp,header.iTime);
_LIT(KExtraFlags,"extra flags %d\n");
console->Printf(KExtraFlags,header.iExtraFlags);
_LIT(KOS,"OS %d\n");
console->Printf(KOS,header.iOs);
 
if (header.iFlags & EZGZipFile::EFText)
{
_LIT(KText,"text flag set\n");
console->Printf(KText);
}
 
if (header.iFlags & EZGZipFile::EFHcrc)
{
_LIT(KCrc16,"CRC16 = %d\n");
console->Printf(KCrc16,header.iCrc);
}
 
if (header.iFlags & EZGZipFile::EFExtra)
{
_LIT(KExtraLength,"extra length %d\n");
console->Printf(KExtraLength,header.iXlen);
HBufC *buf = HBufC::NewLC(header.iExtra->Length());
buf->Des().Copy(*header.iExtra);
console->Printf(*buf);
CleanupStack::PopAndDestroy(); //buf
}
 
if (header.iFlags & EZGZipFile::EFName)
{
_LIT(KFName,"fname: %S\n");
HBufC *buf = HBufC::NewLC(header.iFname->Length());
buf->Des().Copy(*header.iFname);
console->Printf(KFName,buf);
CleanupStack::PopAndDestroy(); //buf
}
 
if (header.iFlags & EZGZipFile::EFComment)
{
_LIT(KComment,"comment: %S\n");
HBufC *buf = HBufC::NewLC(header.iComment->Length());
buf->Des().Copy(*header.iComment);
console->Printf(KComment,buf);
CleanupStack::PopAndDestroy(); //buf
}
}
This page was last modified on 15 December 2011, at 08:42.
58 page views in the last 30 days.
×