compressionlibs/ziplib/test/oldezlib/inc/OldEZGzip.h
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #ifndef __EZLIB_GZIP_H__
       
    17 #define __EZLIB_GZIP_H__
       
    18 
       
    19 #include "OldEZDecompressor.h"
       
    20 #include "OldEZCompressor.h"
       
    21 #include "OldEZFilebuffer.h"
       
    22 
       
    23 
       
    24 namespace TOLDEZLIB
       
    25 {
       
    26 	
       
    27 /**
       
    28 The TEZGZipHeader class encapsulates a zip file header, which is written to the start of the zip
       
    29 file to store various settings of the archive
       
    30 
       
    31 @publishedAll
       
    32 @released
       
    33 */
       
    34 class TEZGZipHeader
       
    35 	{
       
    36 
       
    37 public:
       
    38 	IMPORT_C TEZGZipHeader();
       
    39 	IMPORT_C ~TEZGZipHeader();
       
    40 	
       
    41 public:
       
    42 	TUint8 iId1;
       
    43 	TUint8 iId2;
       
    44 	TUint8 iCompressionMethod;
       
    45 	TUint8 iFlags;
       
    46 	TInt32 iTime;
       
    47 	TUint8 iExtraFlags;
       
    48 	TUint8 iOs;
       
    49 	TInt16 iXlen;
       
    50 	HBufC8* iExtra;
       
    51 	HBufC8* iFname;
       
    52 	HBufC8* iComment;
       
    53 	TInt16 iCrc;
       
    54 	};
       
    55 
       
    56 /**
       
    57 The TEZGZipTrailer class encapsulates a zip file trailer, which uses a CRC (cyclic redundancy check) to 
       
    58 confirm the validity of the unpacked archive
       
    59 
       
    60 @publishedAll
       
    61 @released
       
    62 */
       
    63 class TEZGZipTrailer
       
    64 	{
       
    65 public:
       
    66 	IMPORT_C TEZGZipTrailer();
       
    67 	IMPORT_C TEZGZipTrailer(TInt32 aCrc, TInt32 aSize);
       
    68 public:
       
    69 	TInt32 iCrc32;
       
    70 	TInt32 iSize;
       
    71 	};
       
    72 
       
    73 /**
       
    74 The EZGZipFile class handles writing / reading of headers and trailers to / from zip files
       
    75 
       
    76 @publishedAll
       
    77 @released
       
    78 */
       
    79 class EZGZipFile
       
    80 	{
       
    81 public:
       
    82 	
       
    83 	/** Zip file error codes */	
       
    84 	enum { 	ENotGZipFile = KEZlibErrNotGZipFile, 					
       
    85 			EInvalidCompressionMethod = KEZlibErrInvalidCompression,
       
    86 			EBadGZipHeader= KEZlibErrBadGZipHeader, 				
       
    87 			EBadGZipTrailer = KEZlibErrBadGZipTrailer, 				
       
    88 			EBadGZipCrc = KEZlibErrBadGZipCrc };					
       
    89 	/** Flags to determine which part of the header / trailer is being written */			
       
    90 	enum { EFText = 0, EFHcrc = 1, EFExtra = 2, EFName = 3, EFComment = 4};
       
    91 
       
    92 public:
       
    93 	IMPORT_C static void ReadHeaderL(RFile &aFile, TEZGZipHeader &aHeader);
       
    94 	IMPORT_C static void WriteHeaderL(RFile &aFile, TEZGZipHeader &aHeader);
       
    95 	IMPORT_C static void ReadTrailerL(RFile &aFile, TEZGZipTrailer &aTrailer);
       
    96 	IMPORT_C static void WriteTrailerL(RFile &aFile, TEZGZipTrailer &aTrailer);
       
    97 	IMPORT_C static void LocateAndReadTrailerL(RFs &aRfs, const TDesC &aFname, TEZGZipTrailer &aTrailer);
       
    98 	IMPORT_C static TBool IsGzipFile(RFs &aRfs, const TDesC &aFname);
       
    99 	IMPORT_C static TBool IsGzipFileL(RFs &aRfs, const TDesC &aFname);
       
   100 
       
   101 private:
       
   102 	static void ReadStringIntoDescriptorL(RFile &aFile, HBufC8 **aDes);
       
   103 
       
   104 public:
       
   105 	/** First of the header ID pair */
       
   106 	static const TUint8 ID1;
       
   107 	/** Second of the header ID pair */	
       
   108 	static const TUint8 ID2;
       
   109 	};
       
   110 
       
   111 /**
       
   112 The CEZFileToGzipBM manages the input and output buffers for compression
       
   113 
       
   114 @publishedAll
       
   115 @released
       
   116 */
       
   117 NONSHARABLE_CLASS(CEZFileToGzipBM) : public CEZFileBufferManager
       
   118 	{
       
   119 public:
       
   120 
       
   121 	static CEZFileToGzipBM* NewLC(RFile &aInput, RFile &aOutput, TInt aBufferSize);
       
   122 	static CEZFileToGzipBM* NewL(RFile &aInput, RFile &aOutput, TInt aBufferSize);
       
   123 
       
   124 	/**
       
   125 	Initialise the stream with input and output buffers and starts reading
       
   126 
       
   127 	@param aZStream the stream to initialise
       
   128 	*/
       
   129 	virtual void InitializeL(CEZZStream &aZStream);
       
   130 	
       
   131 	/**
       
   132 	Set the stream's input buffer and starts reading
       
   133 	
       
   134 	@param aZStream the steam whose input buffer to set
       
   135 	*/	
       
   136 	virtual void NeedInputL(CEZZStream &aZStream);
       
   137 	
       
   138 	/**
       
   139 	Return the CRC - used for checking validity of the archive
       
   140 
       
   141 	@return the CRC value
       
   142 	*/	
       
   143 	TInt32 Crc() const { return iCrc; } ;
       
   144 
       
   145 private:
       
   146 	CEZFileToGzipBM(RFile &aInput, RFile &aOutput);
       
   147 private:
       
   148 	TInt32 iCrc;
       
   149 	};
       
   150 
       
   151 /**
       
   152 The CEZGzipToFileBM class manages the input and output buffers for de-compression
       
   153 
       
   154 @publishedAll
       
   155 @released
       
   156 */
       
   157 NONSHARABLE_CLASS(CEZGzipToFileBM) : public CEZFileBufferManager
       
   158 	{
       
   159 public:
       
   160 
       
   161 	static CEZGzipToFileBM* NewLC(RFile &aInput, RFile &aOutput, TInt aBufferSize);
       
   162 	static CEZGzipToFileBM* NewL(RFile &aInput, RFile &aOutput, TInt aBufferSize);
       
   163 
       
   164 	/**
       
   165 	Finish writing to the stream
       
   166 
       
   167 	@param aZStream the stream to complete writing to
       
   168 	*/	
       
   169 	virtual void FinalizeL(CEZZStream &aZStream);
       
   170 	
       
   171 	/**
       
   172 	Set the stream's output buffer and start writing
       
   173 
       
   174 	@param aZStream the steam whose output buffer to set
       
   175 	*/	
       
   176 	virtual void NeedOutputL(CEZZStream &aZStream);
       
   177 	
       
   178 	/**
       
   179 	Return the CRC - used for checking validity of the archive
       
   180 
       
   181 	@return the CRC value
       
   182 	*/	
       
   183 	TInt32 Crc() const { return iCrc; } ;
       
   184 
       
   185 private:
       
   186 	CEZGzipToFileBM(RFile &aInput, RFile &aOutput);
       
   187 private:
       
   188 	TInt32 iCrc;
       
   189 	};
       
   190 
       
   191 
       
   192 /**
       
   193 A CEZGZipToFile object allows de-compression of a compressed file.
       
   194 The name of the compressed file is passed into the constructor along with a target file 
       
   195 to contain the uncompressed data.  The file is uncompressed by calling the InflateL() function.
       
   196 
       
   197 @publishedAll
       
   198 @released
       
   199 */
       
   200 class CEZGZipToFile : public CBase
       
   201 	{
       
   202 public:
       
   203 	~CEZGZipToFile();
       
   204 
       
   205 	IMPORT_C static CEZGZipToFile* NewLC(RFs &aRfs, const TDesC &aGzFileName, RFile &aOutput, TInt aBufferSize = 0x8000);
       
   206 	IMPORT_C static CEZGZipToFile* NewL(RFs &aRfs, const TDesC &aGzFileName, RFile &aOutput, TInt aBufferSize = 0x8000);
       
   207 
       
   208 	IMPORT_C void ResetL(RFs &aRfs, const TDesC &aGzFileName, RFile &aOutput, TInt aBufferSize = 0x8000);
       
   209 
       
   210 	IMPORT_C TBool InflateL();
       
   211 
       
   212 private:
       
   213 	CEZGZipToFile();
       
   214 	void ConstructL(RFs &aRfs, const TDesC &aGzFileName, RFile &aOutput, TInt aBufferSize);
       
   215 	void InitialiseBufManL(RFs &aRfs, const TDesC &aGzFileName, RFile &aOutput, TInt aBufferSize);
       
   216 private:
       
   217 	CEZDecompressor *iDecompressor;
       
   218 	CEZGzipToFileBM *iBufferManager;
       
   219 	TEZGZipTrailer iTrailer;
       
   220 	RFile iGZipFile;
       
   221 	TEZGZipHeader iHeader;
       
   222 	};
       
   223 
       
   224 /**
       
   225 A CEZFileToGZip object allows compression of an uncompressed file to a zip file.
       
   226 The uncompressed source file is passed into the constructor along with the name of the target
       
   227 zip file.  The file is compressed by calling the DeflateL() function.
       
   228 
       
   229 @publishedAll
       
   230 @released
       
   231 */
       
   232 class CEZFileToGZip : public CBase
       
   233 	{
       
   234 public:
       
   235 	~CEZFileToGZip();
       
   236 
       
   237 	IMPORT_C static CEZFileToGZip* NewLC(RFs &aRfs, const TDesC &aGzFileName, RFile &aInput, TInt aBufferSize = 0x8000);
       
   238 	IMPORT_C static CEZFileToGZip* NewL(RFs &aRfs, const TDesC &aGzFileName, RFile &aInput, TInt aBufferSize = 0x8000);
       
   239 
       
   240 	IMPORT_C void ResetL(RFs &aRfs, const TDesC &aGzFileName, RFile &aInput, TInt aBufferSize = 0x8000);
       
   241 
       
   242 	IMPORT_C TBool DeflateL();
       
   243 
       
   244 private:
       
   245 	CEZFileToGZip();
       
   246 	void ConstructL(RFs &aRfs, const TDesC &aGzFileName, RFile &aInput, TInt aBufferSize);
       
   247 	void InitialiseBufManL(RFs &aRfs, const TDesC &aGzFileName, RFile &aInput, TInt aBufferSize);
       
   248 private:
       
   249 	CEZCompressor *iCompressor;
       
   250 	CEZFileToGzipBM *iBufferManager;
       
   251 	TInt iUncompressedDataSize;
       
   252 	RFile iGZipFile;
       
   253 	TEZGZipHeader iHeader;
       
   254 	};
       
   255 
       
   256 }// namespace TOLDEZLIB
       
   257 #endif