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