sl@0
|
1 |
// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include "OldEZGzip.h"
|
sl@0
|
17 |
|
sl@0
|
18 |
using namespace TOLDEZLIB;
|
sl@0
|
19 |
|
sl@0
|
20 |
const TUint8 EZGZipFile::ID1 = 31;
|
sl@0
|
21 |
const TUint8 EZGZipFile::ID2 = 139;
|
sl@0
|
22 |
|
sl@0
|
23 |
/**
|
sl@0
|
24 |
Constructor
|
sl@0
|
25 |
*/
|
sl@0
|
26 |
EXPORT_C TEZGZipHeader::TEZGZipHeader() : iId1(EZGZipFile::ID1), iId2(EZGZipFile::ID2), iCompressionMethod(8), iFlags(0), iTime(0),
|
sl@0
|
27 |
iExtraFlags(0), iOs(255), iXlen(0), iExtra(NULL), iFname(NULL), iComment(NULL), iCrc(0)
|
sl@0
|
28 |
{
|
sl@0
|
29 |
|
sl@0
|
30 |
}
|
sl@0
|
31 |
|
sl@0
|
32 |
/**
|
sl@0
|
33 |
Destructor
|
sl@0
|
34 |
*/
|
sl@0
|
35 |
EXPORT_C TEZGZipHeader::~TEZGZipHeader()
|
sl@0
|
36 |
{
|
sl@0
|
37 |
delete iExtra;
|
sl@0
|
38 |
delete iFname;
|
sl@0
|
39 |
delete iComment;
|
sl@0
|
40 |
}
|
sl@0
|
41 |
|
sl@0
|
42 |
/**
|
sl@0
|
43 |
Constructor
|
sl@0
|
44 |
*/
|
sl@0
|
45 |
EXPORT_C TEZGZipTrailer::TEZGZipTrailer() : iCrc32(0), iSize(0)
|
sl@0
|
46 |
{
|
sl@0
|
47 |
|
sl@0
|
48 |
}
|
sl@0
|
49 |
|
sl@0
|
50 |
/**
|
sl@0
|
51 |
Constructor
|
sl@0
|
52 |
|
sl@0
|
53 |
@param aCrc the CRC to use for archive checking
|
sl@0
|
54 |
@param aSize the size of the trailer
|
sl@0
|
55 |
*/
|
sl@0
|
56 |
EXPORT_C TEZGZipTrailer::TEZGZipTrailer(TInt32 aCrc, TInt32 aSize) : iCrc32(aCrc), iSize(aSize)
|
sl@0
|
57 |
{
|
sl@0
|
58 |
|
sl@0
|
59 |
}
|
sl@0
|
60 |
|
sl@0
|
61 |
//--------------------------------------------------------------------------------------------------------
|
sl@0
|
62 |
|
sl@0
|
63 |
/**
|
sl@0
|
64 |
Read the zip header from the specified zip file into the TEZGZipHeader object
|
sl@0
|
65 |
|
sl@0
|
66 |
@param aFile the zip file to read from
|
sl@0
|
67 |
@param aHeader the target header object
|
sl@0
|
68 |
@leave KEZlibErrBadGZipHeader invalid zip header
|
sl@0
|
69 |
@leave ... Any of the system wide error codes
|
sl@0
|
70 |
*/
|
sl@0
|
71 |
EXPORT_C void EZGZipFile::ReadHeaderL(RFile &aFile, TEZGZipHeader &aHeader)
|
sl@0
|
72 |
{
|
sl@0
|
73 |
TInt obligatoryData = sizeof(aHeader.iId1) + sizeof(aHeader.iId2) + sizeof(aHeader.iCompressionMethod) +
|
sl@0
|
74 |
sizeof(aHeader.iFlags) + sizeof(aHeader.iTime) + sizeof(aHeader.iExtraFlags) + sizeof(aHeader.iOs);
|
sl@0
|
75 |
|
sl@0
|
76 |
TPtr8 des(&aHeader.iId1,0,obligatoryData);
|
sl@0
|
77 |
TInt err = aFile.Read(des);
|
sl@0
|
78 |
if (err != KErrNone || (des.Size() != obligatoryData))
|
sl@0
|
79 |
User::Leave(KEZlibErrBadGZipHeader);
|
sl@0
|
80 |
|
sl@0
|
81 |
if (aHeader.iId1 != ID1 || aHeader.iId2 != ID2)
|
sl@0
|
82 |
User::Leave(KEZlibErrBadGZipHeader);
|
sl@0
|
83 |
|
sl@0
|
84 |
if (aHeader.iFlags & (1 << EFExtra)) // then the extra bit is set
|
sl@0
|
85 |
{
|
sl@0
|
86 |
des.Set(REINTERPRET_CAST(TUint8 *,&aHeader.iXlen),0,sizeof(aHeader.iXlen));
|
sl@0
|
87 |
err = aFile.Read(des);
|
sl@0
|
88 |
if (err != KErrNone || des.Size() != sizeof(aHeader.iXlen) || aHeader.iXlen < 0)
|
sl@0
|
89 |
User::Leave(KEZlibErrBadGZipHeader);
|
sl@0
|
90 |
|
sl@0
|
91 |
aHeader.iExtra = HBufC8::NewMaxL(aHeader.iXlen);
|
sl@0
|
92 |
TPtr8 des = aHeader.iExtra->Des();
|
sl@0
|
93 |
err = aFile.Read(des);
|
sl@0
|
94 |
if (err != KErrNone || des.Size() != aHeader.iXlen)
|
sl@0
|
95 |
User::Leave(KEZlibErrBadGZipHeader);
|
sl@0
|
96 |
}
|
sl@0
|
97 |
|
sl@0
|
98 |
if (aHeader.iFlags & (1 << EFName)) // then read in filename
|
sl@0
|
99 |
ReadStringIntoDescriptorL(aFile,&aHeader.iFname);
|
sl@0
|
100 |
|
sl@0
|
101 |
if (aHeader.iFlags & (1 << EFComment)) // then read in comment
|
sl@0
|
102 |
ReadStringIntoDescriptorL(aFile,&aHeader.iComment);
|
sl@0
|
103 |
|
sl@0
|
104 |
if (aHeader.iFlags & (1 << EFHcrc))
|
sl@0
|
105 |
{
|
sl@0
|
106 |
des.Set(REINTERPRET_CAST(TUint8*,&aHeader.iCrc),0,sizeof(aHeader.iCrc));
|
sl@0
|
107 |
err = aFile.Read(des);
|
sl@0
|
108 |
if (err != KErrNone || des.Size() != sizeof(aHeader.iCrc))
|
sl@0
|
109 |
User::Leave(KEZlibErrBadGZipHeader);
|
sl@0
|
110 |
}
|
sl@0
|
111 |
}
|
sl@0
|
112 |
|
sl@0
|
113 |
/**
|
sl@0
|
114 |
Write the zip header to the specified file
|
sl@0
|
115 |
|
sl@0
|
116 |
@param aFile the file to write to
|
sl@0
|
117 |
@param aHeader the header object to write to the file
|
sl@0
|
118 |
@leave ... Any of the system wide error codes
|
sl@0
|
119 |
*/
|
sl@0
|
120 |
EXPORT_C void EZGZipFile::WriteHeaderL(RFile &aFile, TEZGZipHeader &aHeader)
|
sl@0
|
121 |
{
|
sl@0
|
122 |
TInt obligatoryData = sizeof(aHeader.iId1) + sizeof(aHeader.iId2) + sizeof(aHeader.iCompressionMethod) +
|
sl@0
|
123 |
sizeof(aHeader.iFlags) + sizeof(aHeader.iTime) + sizeof(aHeader.iExtraFlags) + sizeof(aHeader.iOs);
|
sl@0
|
124 |
|
sl@0
|
125 |
TPtrC8 des(&aHeader.iId1,obligatoryData);
|
sl@0
|
126 |
User::LeaveIfError(aFile.Write(des));
|
sl@0
|
127 |
TBuf8<1> null(1);
|
sl@0
|
128 |
null[0] = '\0';
|
sl@0
|
129 |
|
sl@0
|
130 |
if (aHeader.iFlags & (1 << EFExtra)) // then the extra bit is set
|
sl@0
|
131 |
{
|
sl@0
|
132 |
des.Set(REINTERPRET_CAST(TUint8 *,&aHeader.iXlen),sizeof(aHeader.iXlen));
|
sl@0
|
133 |
User::LeaveIfError(aFile.Write(des));
|
sl@0
|
134 |
|
sl@0
|
135 |
User::LeaveIfError(aFile.Write(*aHeader.iExtra));
|
sl@0
|
136 |
}
|
sl@0
|
137 |
|
sl@0
|
138 |
if (aHeader.iFlags & (1 << EFName)) // then read in filename
|
sl@0
|
139 |
{
|
sl@0
|
140 |
User::LeaveIfError(aFile.Write(*aHeader.iFname));
|
sl@0
|
141 |
User::LeaveIfError(aFile.Write(null));
|
sl@0
|
142 |
}
|
sl@0
|
143 |
|
sl@0
|
144 |
if (aHeader.iFlags & (1 << EFComment)) // then read in comment
|
sl@0
|
145 |
{
|
sl@0
|
146 |
User::LeaveIfError(aFile.Write(*aHeader.iComment));
|
sl@0
|
147 |
User::LeaveIfError(aFile.Write(null));
|
sl@0
|
148 |
}
|
sl@0
|
149 |
|
sl@0
|
150 |
if (aHeader.iFlags & (1 << EFHcrc))
|
sl@0
|
151 |
{
|
sl@0
|
152 |
des.Set(REINTERPRET_CAST(TUint8*,&aHeader.iCrc),sizeof(aHeader.iCrc));
|
sl@0
|
153 |
User::LeaveIfError(aFile.Write(des));
|
sl@0
|
154 |
}
|
sl@0
|
155 |
}
|
sl@0
|
156 |
|
sl@0
|
157 |
void EZGZipFile::ReadStringIntoDescriptorL(RFile &aFile, HBufC8 **aDes)
|
sl@0
|
158 |
{
|
sl@0
|
159 |
TInt i, err;
|
sl@0
|
160 |
CArrayFixFlat<TUint8> *bytes = new (ELeave) CArrayFixFlat<TUint8>(16);
|
sl@0
|
161 |
CleanupStack::PushL(bytes);
|
sl@0
|
162 |
TBuf8<1> ch;
|
sl@0
|
163 |
while (((err = aFile.Read(ch)) == KErrNone) && ch[0] != '\0')
|
sl@0
|
164 |
bytes->AppendL(*ch.Ptr());
|
sl@0
|
165 |
|
sl@0
|
166 |
if (err != KErrNone)
|
sl@0
|
167 |
User::Leave(KEZlibErrBadGZipHeader);
|
sl@0
|
168 |
|
sl@0
|
169 |
*aDes = HBufC8::NewMaxL(bytes->Count());
|
sl@0
|
170 |
|
sl@0
|
171 |
for (i = 0; i < bytes->Count(); i++)
|
sl@0
|
172 |
(*aDes)->Des()[i] = (*bytes)[i];
|
sl@0
|
173 |
|
sl@0
|
174 |
CleanupStack::PopAndDestroy(); // delete bytes
|
sl@0
|
175 |
}
|
sl@0
|
176 |
|
sl@0
|
177 |
/**
|
sl@0
|
178 |
Read the zip trailer from the specified zip file into the TEZGZipTrailer object
|
sl@0
|
179 |
|
sl@0
|
180 |
@param aFile the zip file to read from
|
sl@0
|
181 |
@param aTrailer the target trailer object
|
sl@0
|
182 |
@leave KEZlibErrBadGZipTrailer invalid zip trailer
|
sl@0
|
183 |
@leave ... Any of the system wide error codes
|
sl@0
|
184 |
*/
|
sl@0
|
185 |
EXPORT_C void EZGZipFile::ReadTrailerL(RFile &aFile, TEZGZipTrailer &aTrailer)
|
sl@0
|
186 |
{
|
sl@0
|
187 |
TPtr8 des(REINTERPRET_CAST(TUint8*,&aTrailer.iCrc32),0,sizeof(TEZGZipTrailer));
|
sl@0
|
188 |
|
sl@0
|
189 |
TInt err = aFile.Read(des);
|
sl@0
|
190 |
if (err != KErrNone || des.Size() != sizeof(TEZGZipTrailer))
|
sl@0
|
191 |
User::Leave(KEZlibErrBadGZipTrailer);
|
sl@0
|
192 |
}
|
sl@0
|
193 |
|
sl@0
|
194 |
/**
|
sl@0
|
195 |
Write the zip trailer to the specified file
|
sl@0
|
196 |
|
sl@0
|
197 |
@param aFile the file to write to
|
sl@0
|
198 |
@param aTrailer the trailer object to write to the file
|
sl@0
|
199 |
@leave ... Any of the system wide error codes
|
sl@0
|
200 |
*/
|
sl@0
|
201 |
EXPORT_C void EZGZipFile::WriteTrailerL(RFile &aFile, TEZGZipTrailer &aTrailer)
|
sl@0
|
202 |
{
|
sl@0
|
203 |
TPtrC8 des(REINTERPRET_CAST(TUint8*,&aTrailer.iCrc32),sizeof(TEZGZipTrailer));
|
sl@0
|
204 |
User::LeaveIfError(aFile.Write(des));
|
sl@0
|
205 |
}
|
sl@0
|
206 |
|
sl@0
|
207 |
/**
|
sl@0
|
208 |
Find the zip trailer within the specified file, and read it into the TEZGZipTrailer object
|
sl@0
|
209 |
|
sl@0
|
210 |
@param aRfs file server session
|
sl@0
|
211 |
@param aFname the file to read from
|
sl@0
|
212 |
@param aTrailer the target trailer object
|
sl@0
|
213 |
@leave KEZlibErrBadGZipHeader Invalid zip header
|
sl@0
|
214 |
@leave ... Any of the system wide error codes
|
sl@0
|
215 |
*/
|
sl@0
|
216 |
EXPORT_C void EZGZipFile::LocateAndReadTrailerL(RFs &aRfs, const TDesC &aFname, TEZGZipTrailer &aTrailer)
|
sl@0
|
217 |
{
|
sl@0
|
218 |
TInt fileSize;
|
sl@0
|
219 |
|
sl@0
|
220 |
RFile file;
|
sl@0
|
221 |
|
sl@0
|
222 |
User::LeaveIfError(file.Open(aRfs,aFname,EFileStream | EFileRead | EFileShareAny));
|
sl@0
|
223 |
CleanupClosePushL(file);
|
sl@0
|
224 |
|
sl@0
|
225 |
TUint8 magic[2];
|
sl@0
|
226 |
TPtr8 des(magic,0,sizeof(TUint8) * 2);
|
sl@0
|
227 |
User::LeaveIfError(file.Read(des));
|
sl@0
|
228 |
if (magic[0] != ID1 || magic[1] != ID2)
|
sl@0
|
229 |
User::Leave(KEZlibErrBadGZipHeader);
|
sl@0
|
230 |
|
sl@0
|
231 |
User::LeaveIfError(file.Size(fileSize));
|
sl@0
|
232 |
TInt sizePos = fileSize - (sizeof (TInt32) * 2);
|
sl@0
|
233 |
User::LeaveIfError(file.Seek(ESeekStart,sizePos));
|
sl@0
|
234 |
|
sl@0
|
235 |
des.Set(REINTERPRET_CAST(TUint8 *,&aTrailer),0,sizeof(TInt32)*2);
|
sl@0
|
236 |
|
sl@0
|
237 |
User::LeaveIfError(file.Read(des));
|
sl@0
|
238 |
|
sl@0
|
239 |
CleanupStack::PopAndDestroy();
|
sl@0
|
240 |
}
|
sl@0
|
241 |
|
sl@0
|
242 |
/**
|
sl@0
|
243 |
@deprecated Interface is deprecated because it is unsafe as it may leave. It is available for backward compatibility reasons only.
|
sl@0
|
244 |
@see EZGZipFile::IsGzipFileL
|
sl@0
|
245 |
*/
|
sl@0
|
246 |
EXPORT_C TBool EZGZipFile::IsGzipFile(RFs &aRfs, const TDesC &aFname)
|
sl@0
|
247 |
{
|
sl@0
|
248 |
TBool retBool = true;
|
sl@0
|
249 |
TRAPD(errCode, retBool = IsGzipFileL(aRfs, aFname));
|
sl@0
|
250 |
if(errCode != KErrNone)
|
sl@0
|
251 |
{
|
sl@0
|
252 |
retBool = false;
|
sl@0
|
253 |
}
|
sl@0
|
254 |
return retBool;
|
sl@0
|
255 |
}
|
sl@0
|
256 |
|
sl@0
|
257 |
/**
|
sl@0
|
258 |
Determine if the given file is a valid zip file
|
sl@0
|
259 |
|
sl@0
|
260 |
@param aRfs file server session
|
sl@0
|
261 |
@param aFname name of the file to check
|
sl@0
|
262 |
@leave ... Any of the system wide error codes
|
sl@0
|
263 |
@return ETrue if the file is valid zip file, EFalse otherwise
|
sl@0
|
264 |
*/
|
sl@0
|
265 |
EXPORT_C TBool EZGZipFile::IsGzipFileL(RFs &aRfs, const TDesC &aFname)
|
sl@0
|
266 |
{
|
sl@0
|
267 |
TUint8 ids[2];
|
sl@0
|
268 |
RFile file;
|
sl@0
|
269 |
|
sl@0
|
270 |
User::LeaveIfError(file.Open(aRfs,aFname,EFileStream | EFileRead | EFileShareAny));
|
sl@0
|
271 |
CleanupClosePushL(file);
|
sl@0
|
272 |
|
sl@0
|
273 |
TPtr8 des(ids,0,sizeof(TUint8) * 2);
|
sl@0
|
274 |
|
sl@0
|
275 |
User::LeaveIfError(file.Read(des));
|
sl@0
|
276 |
CleanupStack::PopAndDestroy();
|
sl@0
|
277 |
return (ids[0] == ID1 && ids[1] == ID2);
|
sl@0
|
278 |
}
|
sl@0
|
279 |
|
sl@0
|
280 |
//--------------------------------------------------------------------------------------------------------
|
sl@0
|
281 |
|
sl@0
|
282 |
|
sl@0
|
283 |
CEZFileToGzipBM::CEZFileToGzipBM(RFile &aInput, RFile &aOutput) : CEZFileBufferManager(aInput,aOutput)
|
sl@0
|
284 |
{
|
sl@0
|
285 |
iCrc = crc32(iCrc,NULL,0);
|
sl@0
|
286 |
}
|
sl@0
|
287 |
|
sl@0
|
288 |
|
sl@0
|
289 |
CEZFileToGzipBM* CEZFileToGzipBM::NewLC(RFile &aInput, RFile &aOutput, TInt aBufferSize)
|
sl@0
|
290 |
{
|
sl@0
|
291 |
CEZFileToGzipBM *bm = new (ELeave) CEZFileToGzipBM(aInput,aOutput);
|
sl@0
|
292 |
CleanupStack::PushL(bm);
|
sl@0
|
293 |
bm->ConstructL(aBufferSize);
|
sl@0
|
294 |
return bm;
|
sl@0
|
295 |
}
|
sl@0
|
296 |
|
sl@0
|
297 |
CEZFileToGzipBM* CEZFileToGzipBM::NewL(RFile &aInput, RFile &aOutput, TInt aBufferSize)
|
sl@0
|
298 |
{
|
sl@0
|
299 |
CEZFileToGzipBM *bm = new (ELeave) CEZFileToGzipBM(aInput,aOutput);
|
sl@0
|
300 |
CleanupStack::PushL(bm);
|
sl@0
|
301 |
bm->ConstructL(aBufferSize);
|
sl@0
|
302 |
CleanupStack::Pop();
|
sl@0
|
303 |
return bm;
|
sl@0
|
304 |
}
|
sl@0
|
305 |
|
sl@0
|
306 |
void CEZFileToGzipBM::NeedInputL(CEZZStream &aZStream)
|
sl@0
|
307 |
{
|
sl@0
|
308 |
CEZFileBufferManager::NeedInputL(aZStream);
|
sl@0
|
309 |
iCrc = crc32(iCrc,iInputDescriptor.Ptr(),iInputDescriptor.Size());
|
sl@0
|
310 |
}
|
sl@0
|
311 |
|
sl@0
|
312 |
void CEZFileToGzipBM::InitializeL(CEZZStream &aZStream)
|
sl@0
|
313 |
{
|
sl@0
|
314 |
CEZFileBufferManager::InitializeL(aZStream);
|
sl@0
|
315 |
iCrc = crc32(iCrc,iInputDescriptor.Ptr(),iInputDescriptor.Size());
|
sl@0
|
316 |
}
|
sl@0
|
317 |
|
sl@0
|
318 |
//--------------------------------------------------------------------------------------------------------
|
sl@0
|
319 |
|
sl@0
|
320 |
|
sl@0
|
321 |
CEZGzipToFileBM::CEZGzipToFileBM(RFile &aInput, RFile &aOutput) : CEZFileBufferManager(aInput,aOutput)
|
sl@0
|
322 |
{
|
sl@0
|
323 |
iCrc = crc32(iCrc,NULL,0);
|
sl@0
|
324 |
}
|
sl@0
|
325 |
|
sl@0
|
326 |
CEZGzipToFileBM* CEZGzipToFileBM::NewLC(RFile &aInput, RFile &aOutput, TInt aBufferSize)
|
sl@0
|
327 |
{
|
sl@0
|
328 |
CEZGzipToFileBM *bm = new (ELeave) CEZGzipToFileBM(aInput,aOutput);
|
sl@0
|
329 |
CleanupStack::PushL(bm);
|
sl@0
|
330 |
bm->ConstructL(aBufferSize);
|
sl@0
|
331 |
return bm;
|
sl@0
|
332 |
}
|
sl@0
|
333 |
|
sl@0
|
334 |
CEZGzipToFileBM* CEZGzipToFileBM::NewL(RFile &aInput, RFile &aOutput, TInt aBufferSize)
|
sl@0
|
335 |
{
|
sl@0
|
336 |
CEZGzipToFileBM *bm = new (ELeave) CEZGzipToFileBM(aInput,aOutput);
|
sl@0
|
337 |
CleanupStack::PushL(bm);
|
sl@0
|
338 |
bm->ConstructL(aBufferSize);
|
sl@0
|
339 |
CleanupStack::Pop();
|
sl@0
|
340 |
return bm;
|
sl@0
|
341 |
}
|
sl@0
|
342 |
|
sl@0
|
343 |
void CEZGzipToFileBM::NeedOutputL(CEZZStream &aZStream)
|
sl@0
|
344 |
{
|
sl@0
|
345 |
TPtrC8 od = aZStream.OutputDescriptor();
|
sl@0
|
346 |
iCrc = crc32(iCrc,od.Ptr(),od.Size());
|
sl@0
|
347 |
CEZFileBufferManager::NeedOutputL(aZStream);
|
sl@0
|
348 |
}
|
sl@0
|
349 |
|
sl@0
|
350 |
void CEZGzipToFileBM::FinalizeL(CEZZStream &aZStream)
|
sl@0
|
351 |
{
|
sl@0
|
352 |
TPtrC8 od = aZStream.OutputDescriptor();
|
sl@0
|
353 |
iCrc = crc32(iCrc,od.Ptr(),od.Size());
|
sl@0
|
354 |
CEZFileBufferManager::FinalizeL(aZStream);
|
sl@0
|
355 |
}
|
sl@0
|
356 |
|
sl@0
|
357 |
|
sl@0
|
358 |
//--------------------------------------------------------------------------------------------------------
|
sl@0
|
359 |
CEZGZipToFile::CEZGZipToFile() : iDecompressor(NULL), iBufferManager(NULL)
|
sl@0
|
360 |
{
|
sl@0
|
361 |
|
sl@0
|
362 |
}
|
sl@0
|
363 |
|
sl@0
|
364 |
CEZGZipToFile::~CEZGZipToFile()
|
sl@0
|
365 |
{
|
sl@0
|
366 |
delete iDecompressor;
|
sl@0
|
367 |
delete iBufferManager;
|
sl@0
|
368 |
iGZipFile.Close();
|
sl@0
|
369 |
}
|
sl@0
|
370 |
|
sl@0
|
371 |
/**
|
sl@0
|
372 |
Creates a new CEZGZipToFile object and leaves it on the CleanupStack
|
sl@0
|
373 |
|
sl@0
|
374 |
@param aRfs open file server session
|
sl@0
|
375 |
@param aGzFileName name of the file to be de-compressed
|
sl@0
|
376 |
@param aOutput the target file to hold the un-compressed data
|
sl@0
|
377 |
@param aBufferSize required size of buffers
|
sl@0
|
378 |
@return a pointer to the new CEZGZipToFile object, left on the CleanupStack
|
sl@0
|
379 |
*/
|
sl@0
|
380 |
EXPORT_C CEZGZipToFile* CEZGZipToFile::NewLC(RFs &aRfs, const TDesC &aGzFileName, RFile &aOutput, TInt aBufferSize)
|
sl@0
|
381 |
{
|
sl@0
|
382 |
CEZGZipToFile* dec = new (ELeave) CEZGZipToFile;
|
sl@0
|
383 |
CleanupStack::PushL(dec);
|
sl@0
|
384 |
dec->ConstructL(aRfs,aGzFileName,aOutput,aBufferSize);
|
sl@0
|
385 |
return dec;
|
sl@0
|
386 |
}
|
sl@0
|
387 |
|
sl@0
|
388 |
/**
|
sl@0
|
389 |
Creates a new CEZGZipToFile object
|
sl@0
|
390 |
|
sl@0
|
391 |
@param aRfs open file server session
|
sl@0
|
392 |
@param aGzFileName name of the file to be de-compressed
|
sl@0
|
393 |
@param aOutput the target file to hold the un-compressed data
|
sl@0
|
394 |
@param aBufferSize required size of buffers
|
sl@0
|
395 |
@return a pointer to the new CEZGZipToFile object
|
sl@0
|
396 |
*/
|
sl@0
|
397 |
EXPORT_C CEZGZipToFile* CEZGZipToFile::NewL(RFs &aRfs, const TDesC &aGzFileName, RFile &aOutput, TInt aBufferSize)
|
sl@0
|
398 |
{
|
sl@0
|
399 |
CEZGZipToFile* dec = new (ELeave) CEZGZipToFile;
|
sl@0
|
400 |
CleanupStack::PushL(dec);
|
sl@0
|
401 |
dec->ConstructL(aRfs,aGzFileName,aOutput,aBufferSize);
|
sl@0
|
402 |
CleanupStack::Pop();
|
sl@0
|
403 |
return dec;
|
sl@0
|
404 |
}
|
sl@0
|
405 |
|
sl@0
|
406 |
/**
|
sl@0
|
407 |
Quits the current de-compression operation and restarts with the specified arguments
|
sl@0
|
408 |
|
sl@0
|
409 |
@param aRfs open file server session
|
sl@0
|
410 |
@param aGzFileName name of the file to be de-compressed
|
sl@0
|
411 |
@param aOutput the target file to hold the un-compressed data
|
sl@0
|
412 |
@param aBufferSize required size of buffers
|
sl@0
|
413 |
@leave ... Any of the system wide error codes
|
sl@0
|
414 |
*/
|
sl@0
|
415 |
EXPORT_C void CEZGZipToFile::ResetL(RFs &aRfs, const TDesC &aGzFileName, RFile &aOutput, TInt aBufferSize)
|
sl@0
|
416 |
{
|
sl@0
|
417 |
delete iBufferManager;
|
sl@0
|
418 |
InitialiseBufManL(aRfs,aGzFileName,aOutput,aBufferSize);
|
sl@0
|
419 |
iDecompressor->ResetL(*iBufferManager);
|
sl@0
|
420 |
}
|
sl@0
|
421 |
|
sl@0
|
422 |
/**
|
sl@0
|
423 |
De-compresses the current zip file in stages. The function needs to called again until the de-compression
|
sl@0
|
424 |
is finalised, in which case it will return EFalse - for example...
|
sl@0
|
425 |
|
sl@0
|
426 |
@code
|
sl@0
|
427 |
while ( decompressor->InflateL() )
|
sl@0
|
428 |
{
|
sl@0
|
429 |
// No action required
|
sl@0
|
430 |
}
|
sl@0
|
431 |
@endcode
|
sl@0
|
432 |
|
sl@0
|
433 |
@leave KEZlibErrBadGZipCrc Invalid CRC check
|
sl@0
|
434 |
@leave ... Any of the system wide error codes
|
sl@0
|
435 |
@return ETrue if the de-compression is not complete, and function must be called again
|
sl@0
|
436 |
@return EFalse if the de-compression is finalised
|
sl@0
|
437 |
*/
|
sl@0
|
438 |
EXPORT_C TBool CEZGZipToFile::InflateL()
|
sl@0
|
439 |
{
|
sl@0
|
440 |
TBool keepGoing = iDecompressor->InflateL();
|
sl@0
|
441 |
|
sl@0
|
442 |
if (!keepGoing)
|
sl@0
|
443 |
{
|
sl@0
|
444 |
if (iBufferManager->Crc() != iTrailer.iCrc32)
|
sl@0
|
445 |
User::Leave(KEZlibErrBadGZipCrc);
|
sl@0
|
446 |
iGZipFile.Close();
|
sl@0
|
447 |
}
|
sl@0
|
448 |
|
sl@0
|
449 |
return keepGoing;
|
sl@0
|
450 |
}
|
sl@0
|
451 |
|
sl@0
|
452 |
void CEZGZipToFile::InitialiseBufManL(RFs &aRfs, const TDesC &aGzFileName, RFile &aOutput, TInt aBufferSize)
|
sl@0
|
453 |
{
|
sl@0
|
454 |
EZGZipFile::LocateAndReadTrailerL(aRfs,aGzFileName,iTrailer);
|
sl@0
|
455 |
User::LeaveIfError(iGZipFile.Open(aRfs,aGzFileName,EFileStream | EFileRead | EFileShareAny));
|
sl@0
|
456 |
EZGZipFile::ReadHeaderL(iGZipFile,iHeader);
|
sl@0
|
457 |
iBufferManager = CEZGzipToFileBM::NewL(iGZipFile,aOutput,aBufferSize);
|
sl@0
|
458 |
}
|
sl@0
|
459 |
|
sl@0
|
460 |
void CEZGZipToFile::ConstructL(RFs &aRfs, const TDesC &aGzFileName, RFile &aOutput, TInt aBufferSize)
|
sl@0
|
461 |
{
|
sl@0
|
462 |
InitialiseBufManL(aRfs,aGzFileName,aOutput,aBufferSize);
|
sl@0
|
463 |
|
sl@0
|
464 |
// this is a special zlib modification to stop it choking when it can't find the normal zlib stream header.
|
sl@0
|
465 |
|
sl@0
|
466 |
iDecompressor = CEZDecompressor::NewL(*iBufferManager,-CEZDecompressor::EMaxWBits);
|
sl@0
|
467 |
}
|
sl@0
|
468 |
|
sl@0
|
469 |
|
sl@0
|
470 |
//--------------------------------------------------------------------------------------------------------
|
sl@0
|
471 |
|
sl@0
|
472 |
|
sl@0
|
473 |
CEZFileToGZip::CEZFileToGZip() : iCompressor(NULL), iBufferManager(NULL)
|
sl@0
|
474 |
{
|
sl@0
|
475 |
|
sl@0
|
476 |
}
|
sl@0
|
477 |
|
sl@0
|
478 |
CEZFileToGZip::~CEZFileToGZip()
|
sl@0
|
479 |
{
|
sl@0
|
480 |
delete iCompressor;
|
sl@0
|
481 |
delete iBufferManager;
|
sl@0
|
482 |
iGZipFile.Close();
|
sl@0
|
483 |
}
|
sl@0
|
484 |
|
sl@0
|
485 |
/**
|
sl@0
|
486 |
Creates a new CEZFileToGZip object and leaves it on the CleanupStack
|
sl@0
|
487 |
|
sl@0
|
488 |
@param aRfs open file server session
|
sl@0
|
489 |
@param aGzFileName the name of the target zip file
|
sl@0
|
490 |
@param aInput the file to compress
|
sl@0
|
491 |
@param aBufferSize required size of buffers
|
sl@0
|
492 |
@return a pointer to the new CEZFileToGZip object, left on the CleanupStack
|
sl@0
|
493 |
*/
|
sl@0
|
494 |
EXPORT_C CEZFileToGZip* CEZFileToGZip::NewLC(RFs &aRfs, const TDesC &aGzFileName, RFile &aInput, TInt aBufferSize)
|
sl@0
|
495 |
{
|
sl@0
|
496 |
CEZFileToGZip* com = new (ELeave) CEZFileToGZip;
|
sl@0
|
497 |
CleanupStack::PushL(com);
|
sl@0
|
498 |
com->ConstructL(aRfs,aGzFileName,aInput,aBufferSize);
|
sl@0
|
499 |
return com;
|
sl@0
|
500 |
}
|
sl@0
|
501 |
|
sl@0
|
502 |
/**
|
sl@0
|
503 |
Creates a new CEZFileToGZip object and leaves it on the CleanupStack
|
sl@0
|
504 |
|
sl@0
|
505 |
@param aRfs open file server session
|
sl@0
|
506 |
@param aGzFileName the name of the target zip file
|
sl@0
|
507 |
@param aInput the file to compress
|
sl@0
|
508 |
@param aBufferSize required size of buffers
|
sl@0
|
509 |
@return a pointer to the new CEZFileToGZip object, left on the CleanupStack
|
sl@0
|
510 |
*/
|
sl@0
|
511 |
EXPORT_C CEZFileToGZip* CEZFileToGZip::NewL(RFs &aRfs, const TDesC &aGzFileName, RFile &aInput, TInt aBufferSize)
|
sl@0
|
512 |
{
|
sl@0
|
513 |
CEZFileToGZip* com = new (ELeave) CEZFileToGZip;
|
sl@0
|
514 |
CleanupStack::PushL(com);
|
sl@0
|
515 |
com->ConstructL(aRfs,aGzFileName,aInput,aBufferSize);
|
sl@0
|
516 |
CleanupStack::Pop();
|
sl@0
|
517 |
return com;
|
sl@0
|
518 |
}
|
sl@0
|
519 |
|
sl@0
|
520 |
/**
|
sl@0
|
521 |
Quits the current compression operation and restarts with the specified arguments
|
sl@0
|
522 |
|
sl@0
|
523 |
@param aRfs open file server session
|
sl@0
|
524 |
@param aGzFileName the name of the target zip file
|
sl@0
|
525 |
@param aInput the file to compress
|
sl@0
|
526 |
@param aBufferSize required size of buffers
|
sl@0
|
527 |
@leave ... Any of the system wide error codes
|
sl@0
|
528 |
*/
|
sl@0
|
529 |
EXPORT_C void CEZFileToGZip::ResetL(RFs &aRfs, const TDesC &aGzFileName, RFile &aInput, TInt aBufferSize)
|
sl@0
|
530 |
{
|
sl@0
|
531 |
delete iBufferManager;
|
sl@0
|
532 |
InitialiseBufManL(aRfs,aGzFileName,aInput,aBufferSize);
|
sl@0
|
533 |
iCompressor->ResetL(*iBufferManager);
|
sl@0
|
534 |
}
|
sl@0
|
535 |
|
sl@0
|
536 |
/**
|
sl@0
|
537 |
Compresses the current file in stages. The function needs to called again until the compression
|
sl@0
|
538 |
is finalised, in which case it will return EFalse - for example...
|
sl@0
|
539 |
|
sl@0
|
540 |
@code
|
sl@0
|
541 |
while ( compressor->DeflateL() )
|
sl@0
|
542 |
{
|
sl@0
|
543 |
// No action required
|
sl@0
|
544 |
}
|
sl@0
|
545 |
@endcode
|
sl@0
|
546 |
|
sl@0
|
547 |
@leave ... Any of the system wide error codes
|
sl@0
|
548 |
@return ETrue if the compression is not complete, and function must be called again
|
sl@0
|
549 |
@return EFalse if the compression is finalised
|
sl@0
|
550 |
*/
|
sl@0
|
551 |
EXPORT_C TBool CEZFileToGZip::DeflateL()
|
sl@0
|
552 |
{
|
sl@0
|
553 |
TBool keepgoing = iCompressor->DeflateL();
|
sl@0
|
554 |
if (!keepgoing)
|
sl@0
|
555 |
{
|
sl@0
|
556 |
TEZGZipTrailer trailer(iBufferManager->Crc(), iUncompressedDataSize);
|
sl@0
|
557 |
EZGZipFile::WriteTrailerL(iGZipFile, trailer);
|
sl@0
|
558 |
iGZipFile.Close();
|
sl@0
|
559 |
}
|
sl@0
|
560 |
|
sl@0
|
561 |
return keepgoing;
|
sl@0
|
562 |
}
|
sl@0
|
563 |
|
sl@0
|
564 |
void CEZFileToGZip::InitialiseBufManL(RFs &aRfs, const TDesC &aGzFileName, RFile &aInput, TInt aBufferSize)
|
sl@0
|
565 |
{
|
sl@0
|
566 |
User::LeaveIfError(aInput.Size(iUncompressedDataSize));
|
sl@0
|
567 |
TInt err;
|
sl@0
|
568 |
|
sl@0
|
569 |
err = iGZipFile.Create(aRfs, aGzFileName,EFileStream | EFileWrite | EFileShareExclusive);
|
sl@0
|
570 |
if (err == KErrAlreadyExists)
|
sl@0
|
571 |
User::LeaveIfError(iGZipFile.Open(aRfs,aGzFileName,EFileStream | EFileWrite | EFileShareExclusive));
|
sl@0
|
572 |
else
|
sl@0
|
573 |
User::LeaveIfError(err);
|
sl@0
|
574 |
|
sl@0
|
575 |
EZGZipFile::WriteHeaderL(iGZipFile,iHeader);
|
sl@0
|
576 |
iBufferManager = CEZFileToGzipBM::NewL(aInput,iGZipFile,aBufferSize);
|
sl@0
|
577 |
}
|
sl@0
|
578 |
|
sl@0
|
579 |
void CEZFileToGZip::ConstructL(RFs &aRfs, const TDesC &aGzFileName, RFile &aInput, TInt aBufferSize)
|
sl@0
|
580 |
{
|
sl@0
|
581 |
InitialiseBufManL(aRfs,aGzFileName,aInput,aBufferSize);
|
sl@0
|
582 |
|
sl@0
|
583 |
// this is a special zlib modification to stop zlib writing out its normal zlib stream header.
|
sl@0
|
584 |
|
sl@0
|
585 |
iCompressor = CEZCompressor::NewL(*iBufferManager,CEZCompressor::EDefaultCompression,-CEZCompressor::EMaxWBits);
|
sl@0
|
586 |
}
|