epoc32/include/ezgzip.h
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
child 4 837f303aceeb
     1.1 --- a/epoc32/include/ezgzip.h	Tue Nov 24 13:55:44 2009 +0000
     1.2 +++ b/epoc32/include/ezgzip.h	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -1,1 +1,253 @@
     1.4 -ezgzip.h
     1.5 +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +// All rights reserved.
     1.7 +// This component and the accompanying materials are made available
     1.8 +// under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
     1.9 +// which accompanies this distribution, and is available
    1.10 +// at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
    1.11 +//
    1.12 +// Initial Contributors:
    1.13 +// Nokia Corporation - initial contribution.
    1.14 +//
    1.15 +// Contributors:
    1.16 +//
    1.17 +// Description:
    1.18 +//
    1.19 +
    1.20 +#ifndef __GZIP_H__
    1.21 +#define __GZIP_H__
    1.22 +
    1.23 +#include <ezdecompressor.h>
    1.24 +#include <ezcompressor.h>
    1.25 +#include <ezfilebuffer.h>
    1.26 +
    1.27 +/**
    1.28 +The TEZGZipHeader class encapsulates a zip file header, which is written to the start of the zip
    1.29 +file to store various settings of the archive
    1.30 +
    1.31 +@publishedAll
    1.32 +@released
    1.33 +*/
    1.34 +class TEZGZipHeader
    1.35 +	{
    1.36 +
    1.37 +public:
    1.38 +	IMPORT_C TEZGZipHeader();
    1.39 +	IMPORT_C ~TEZGZipHeader();
    1.40 +	
    1.41 +public:
    1.42 +	TUint8 iId1;
    1.43 +	TUint8 iId2;
    1.44 +	TUint8 iCompressionMethod;
    1.45 +	TUint8 iFlags;
    1.46 +	TInt32 iTime;
    1.47 +	TUint8 iExtraFlags;
    1.48 +	TUint8 iOs;
    1.49 +	TInt16 iXlen;
    1.50 +	HBufC8* iExtra;
    1.51 +	HBufC8* iFname;
    1.52 +	HBufC8* iComment;
    1.53 +	TInt16 iCrc;
    1.54 +	};
    1.55 +
    1.56 +/**
    1.57 +The TEZGZipTrailer class encapsulates a zip file trailer, which uses a CRC (cyclic redundancy check) to 
    1.58 +confirm the validity of the unpacked archive
    1.59 +
    1.60 +@publishedAll
    1.61 +@released
    1.62 +*/
    1.63 +class TEZGZipTrailer
    1.64 +	{
    1.65 +public:
    1.66 +	IMPORT_C TEZGZipTrailer();
    1.67 +	IMPORT_C TEZGZipTrailer(TInt32 aCrc, TInt32 aSize);
    1.68 +public:
    1.69 +	TInt32 iCrc32;
    1.70 +	TInt32 iSize;
    1.71 +	};
    1.72 +
    1.73 +/**
    1.74 +The EZGZipFile class handles writing / reading of headers and trailers to / from zip files
    1.75 +
    1.76 +@publishedAll
    1.77 +@released
    1.78 +*/
    1.79 +class EZGZipFile
    1.80 +	{
    1.81 +public:
    1.82 +	
    1.83 +	/** Zip file error codes */	
    1.84 +	enum { 	ENotGZipFile = KEZlibErrNotGZipFile, 					
    1.85 +			EInvalidCompressionMethod = KEZlibErrInvalidCompression,
    1.86 +			EBadGZipHeader= KEZlibErrBadGZipHeader, 				
    1.87 +			EBadGZipTrailer = KEZlibErrBadGZipTrailer, 				
    1.88 +			EBadGZipCrc = KEZlibErrBadGZipCrc };					
    1.89 +	/** Flags to determine which part of the header / trailer is being written */			
    1.90 +	enum { EFText = 0, EFHcrc = 1, EFExtra = 2, EFName = 3, EFComment = 4};
    1.91 +
    1.92 +public:
    1.93 +	IMPORT_C static void ReadHeaderL(RFile &aFile, TEZGZipHeader &aHeader);
    1.94 +	IMPORT_C static void WriteHeaderL(RFile &aFile, TEZGZipHeader &aHeader);
    1.95 +	IMPORT_C static void ReadTrailerL(RFile &aFile, TEZGZipTrailer &aTrailer);
    1.96 +	IMPORT_C static void WriteTrailerL(RFile &aFile, TEZGZipTrailer &aTrailer);
    1.97 +	IMPORT_C static void LocateAndReadTrailerL(RFs &aRfs, const TDesC &aFname, TEZGZipTrailer &aTrailer);
    1.98 +	IMPORT_C static TBool IsGzipFile(RFs &aRfs, const TDesC &aFname);
    1.99 +	IMPORT_C static TBool IsGzipFileL(RFs &aRfs, const TDesC &aFname);
   1.100 +
   1.101 +private:
   1.102 +	static void ReadStringIntoDescriptorL(RFile &aFile, HBufC8 **aDes);
   1.103 +
   1.104 +public:
   1.105 +	/** First of the header ID pair */
   1.106 +	static const TUint8 ID1;
   1.107 +	/** Second of the header ID pair */	
   1.108 +	static const TUint8 ID2;
   1.109 +	};
   1.110 +
   1.111 +/**
   1.112 +The CEZFileToGzipBM manages the input and output buffers for compression
   1.113 +
   1.114 +@publishedAll
   1.115 +@released
   1.116 +*/
   1.117 +NONSHARABLE_CLASS(CEZFileToGzipBM) : public CEZFileBufferManager
   1.118 +	{
   1.119 +public:
   1.120 +
   1.121 +	static CEZFileToGzipBM* NewLC(RFile &aInput, RFile &aOutput, TInt aBufferSize);
   1.122 +	static CEZFileToGzipBM* NewL(RFile &aInput, RFile &aOutput, TInt aBufferSize);
   1.123 +
   1.124 +	/**
   1.125 +	Initialise the stream with input and output buffers and starts reading
   1.126 +
   1.127 +	@param aZStream the stream to initialise
   1.128 +	*/
   1.129 +	virtual void InitializeL(CEZZStream &aZStream);
   1.130 +	
   1.131 +	/**
   1.132 +	Set the stream's input buffer and starts reading
   1.133 +	
   1.134 +	@param aZStream the steam whose input buffer to set
   1.135 +	*/	
   1.136 +	virtual void NeedInputL(CEZZStream &aZStream);
   1.137 +	
   1.138 +	/**
   1.139 +	Return the CRC - used for checking validity of the archive
   1.140 +
   1.141 +	@return the CRC value
   1.142 +	*/	
   1.143 +	TInt32 Crc() const { return iCrc; } ;
   1.144 +
   1.145 +private:
   1.146 +	CEZFileToGzipBM(RFile &aInput, RFile &aOutput);
   1.147 +private:
   1.148 +	TInt32 iCrc;
   1.149 +	};
   1.150 +
   1.151 +/**
   1.152 +The CEZGzipToFileBM class manages the input and output buffers for de-compression
   1.153 +
   1.154 +@publishedAll
   1.155 +@released
   1.156 +*/
   1.157 +NONSHARABLE_CLASS(CEZGzipToFileBM) : public CEZFileBufferManager
   1.158 +	{
   1.159 +public:
   1.160 +
   1.161 +	static CEZGzipToFileBM* NewLC(RFile &aInput, RFile &aOutput, TInt aBufferSize);
   1.162 +	static CEZGzipToFileBM* NewL(RFile &aInput, RFile &aOutput, TInt aBufferSize);
   1.163 +
   1.164 +	/**
   1.165 +	Finish writing to the stream
   1.166 +
   1.167 +	@param aZStream the stream to complete writing to
   1.168 +	*/	
   1.169 +	virtual void FinalizeL(CEZZStream &aZStream);
   1.170 +	
   1.171 +	/**
   1.172 +	Set the stream's output buffer and start writing
   1.173 +
   1.174 +	@param aZStream the steam whose output buffer to set
   1.175 +	*/	
   1.176 +	virtual void NeedOutputL(CEZZStream &aZStream);
   1.177 +	
   1.178 +	/**
   1.179 +	Return the CRC - used for checking validity of the archive
   1.180 +
   1.181 +	@return the CRC value
   1.182 +	*/	
   1.183 +	TInt32 Crc() const { return iCrc; } ;
   1.184 +
   1.185 +private:
   1.186 +	CEZGzipToFileBM(RFile &aInput, RFile &aOutput);
   1.187 +private:
   1.188 +	TInt32 iCrc;
   1.189 +	};
   1.190 +
   1.191 +
   1.192 +/**
   1.193 +A CEZGZipToFile object allows de-compression of a compressed file.
   1.194 +The name of the compressed file is passed into the constructor along with a target file 
   1.195 +to contain the uncompressed data.  The file is uncompressed by calling the InflateL() function.
   1.196 +
   1.197 +@publishedAll
   1.198 +@released
   1.199 +*/
   1.200 +class CEZGZipToFile : public CBase
   1.201 +	{
   1.202 +public:
   1.203 +	~CEZGZipToFile();
   1.204 +
   1.205 +	IMPORT_C static CEZGZipToFile* NewLC(RFs &aRfs, const TDesC &aGzFileName, RFile &aOutput, TInt aBufferSize = 0x8000);
   1.206 +	IMPORT_C static CEZGZipToFile* NewL(RFs &aRfs, const TDesC &aGzFileName, RFile &aOutput, TInt aBufferSize = 0x8000);
   1.207 +
   1.208 +	IMPORT_C void ResetL(RFs &aRfs, const TDesC &aGzFileName, RFile &aOutput, TInt aBufferSize = 0x8000);
   1.209 +
   1.210 +	IMPORT_C TBool InflateL();
   1.211 +
   1.212 +private:
   1.213 +	CEZGZipToFile();
   1.214 +	void ConstructL(RFs &aRfs, const TDesC &aGzFileName, RFile &aOutput, TInt aBufferSize);
   1.215 +	void InitialiseBufManL(RFs &aRfs, const TDesC &aGzFileName, RFile &aOutput, TInt aBufferSize);
   1.216 +private:
   1.217 +	CEZDecompressor *iDecompressor;
   1.218 +	CEZGzipToFileBM *iBufferManager;
   1.219 +	TEZGZipTrailer iTrailer;
   1.220 +	RFile iGZipFile;
   1.221 +	TEZGZipHeader iHeader;
   1.222 +	};
   1.223 +
   1.224 +/**
   1.225 +A CEZFileToGZip object allows compression of an uncompressed file to a zip file.
   1.226 +The uncompressed source file is passed into the constructor along with the name of the target
   1.227 +zip file.  The file is compressed by calling the DeflateL() function.
   1.228 +
   1.229 +@publishedAll
   1.230 +@released
   1.231 +*/
   1.232 +class CEZFileToGZip : public CBase
   1.233 +	{
   1.234 +public:
   1.235 +	~CEZFileToGZip();
   1.236 +
   1.237 +	IMPORT_C static CEZFileToGZip* NewLC(RFs &aRfs, const TDesC &aGzFileName, RFile &aInput, TInt aBufferSize = 0x8000);
   1.238 +	IMPORT_C static CEZFileToGZip* NewL(RFs &aRfs, const TDesC &aGzFileName, RFile &aInput, TInt aBufferSize = 0x8000);
   1.239 +
   1.240 +	IMPORT_C void ResetL(RFs &aRfs, const TDesC &aGzFileName, RFile &aInput, TInt aBufferSize = 0x8000);
   1.241 +
   1.242 +	IMPORT_C TBool DeflateL();
   1.243 +
   1.244 +private:
   1.245 +	CEZFileToGZip();
   1.246 +	void ConstructL(RFs &aRfs, const TDesC &aGzFileName, RFile &aInput, TInt aBufferSize);
   1.247 +	void InitialiseBufManL(RFs &aRfs, const TDesC &aGzFileName, RFile &aInput, TInt aBufferSize);
   1.248 +private:
   1.249 +	CEZCompressor *iCompressor;
   1.250 +	CEZFileToGzipBM *iBufferManager;
   1.251 +	TInt iUncompressedDataSize;
   1.252 +	RFile iGZipFile;
   1.253 +	TEZGZipHeader iHeader;
   1.254 +	};
   1.255 +
   1.256 +
   1.257 +#endif