|
1 // Copyright (c) 2006-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 // GZIP output stream functions |
|
15 // |
|
16 |
|
17 #include "xmlenggzipfiledeserializer.h" |
|
18 #include <ezstream.h> |
|
19 #include <ezdecompressor.h> |
|
20 |
|
21 |
|
22 CXmlEngGZipFileDeserializer* CXmlEngGZipFileDeserializer::NewLC( Xml::CParser* aParser, RFs& aRfs, const TDesC& aGzFileName, TInt aBufSize ) |
|
23 { |
|
24 CXmlEngGZipFileDeserializer* bm = new (ELeave) CXmlEngGZipFileDeserializer( aParser ); |
|
25 CleanupStack::PushL( bm ); |
|
26 bm->ConstructL( aRfs, aGzFileName, aBufSize ); |
|
27 return bm; |
|
28 } |
|
29 |
|
30 CXmlEngGZipFileDeserializer* CXmlEngGZipFileDeserializer::NewL( Xml::CParser* aParser, RFs& aRfs, const TDesC& aGzFileName, TInt aBufSize ) |
|
31 { |
|
32 CXmlEngGZipFileDeserializer* bm = CXmlEngGZipFileDeserializer::NewLC( aParser, aRfs, aGzFileName, aBufSize ); |
|
33 CleanupStack::Pop( bm ); |
|
34 return bm; |
|
35 } |
|
36 |
|
37 CXmlEngGZipFileDeserializer::CXmlEngGZipFileDeserializer( Xml::CParser* aParser ) |
|
38 : iInputDescriptor(NULL,0), iOutputDescriptor(NULL,0) |
|
39 { |
|
40 iParser = aParser; |
|
41 } |
|
42 |
|
43 void CXmlEngGZipFileDeserializer::ConstructL( RFs& aRfs, const TDesC& aGzFileName, TInt aBufSize ) |
|
44 { |
|
45 EZGZipFile::LocateAndReadTrailerL(aRfs,aGzFileName,iTrailer); |
|
46 User::LeaveIfError(iInputFile.Open(aRfs,aGzFileName,EFileStream | EFileRead | EFileShareAny)); |
|
47 EZGZipFile::ReadHeaderL(iInputFile,iHeader); |
|
48 iCrc = crc32(iCrc,NULL,0); |
|
49 |
|
50 if ( aBufSize <= 0 ) |
|
51 { |
|
52 User::Leave(KErrArgument); |
|
53 } |
|
54 iInputBuffer = new (ELeave) TUint8[aBufSize]; |
|
55 iOutputBuffer = new (ELeave) TUint8[aBufSize]; |
|
56 |
|
57 iInputDescriptor.Set(iInputBuffer,0,aBufSize); |
|
58 iOutputDescriptor.Set(iOutputBuffer,0,aBufSize); |
|
59 |
|
60 |
|
61 iDecompressor = CEZDecompressor::NewL(*this,-CEZDecompressor::EMaxWBits); |
|
62 } |
|
63 |
|
64 CXmlEngGZipFileDeserializer::~CXmlEngGZipFileDeserializer() |
|
65 { |
|
66 //do NOT destroy iParser |
|
67 delete iDecompressor; |
|
68 delete[] iInputBuffer; |
|
69 delete[] iOutputBuffer; |
|
70 iInputFile.Close(); |
|
71 } |
|
72 |
|
73 TBool CXmlEngGZipFileDeserializer::InflateL() |
|
74 { |
|
75 TBool keepGoing = iDecompressor->InflateL(); |
|
76 |
|
77 if (!keepGoing) |
|
78 { |
|
79 if (iCrc != iTrailer.iCrc32) |
|
80 User::Leave(KEZlibErrBadGZipCrc); |
|
81 iInputFile.Close(); |
|
82 } |
|
83 return keepGoing; |
|
84 } |
|
85 |
|
86 void CXmlEngGZipFileDeserializer::InitializeL( CEZZStream& aZStream ) |
|
87 { |
|
88 iParser->ParseBeginL(); |
|
89 User::LeaveIfError(iInputFile.Read(iInputDescriptor)); |
|
90 aZStream.SetInput(iInputDescriptor); |
|
91 aZStream.SetOutput( iOutputDescriptor ); |
|
92 } |
|
93 |
|
94 void CXmlEngGZipFileDeserializer::NeedInputL( CEZZStream& aZStream ) |
|
95 { |
|
96 User::LeaveIfError(iInputFile.Read(iInputDescriptor)); |
|
97 aZStream.SetInput(iInputDescriptor); |
|
98 } |
|
99 |
|
100 void CXmlEngGZipFileDeserializer::NeedOutputL( CEZZStream& aZStream ) |
|
101 { |
|
102 TPtrC8 od = aZStream.OutputDescriptor(); |
|
103 iCrc = crc32(iCrc,od.Ptr(),od.Size()); |
|
104 iParser->ParseL( od ); |
|
105 aZStream.SetOutput( iOutputDescriptor ); |
|
106 } |
|
107 |
|
108 void CXmlEngGZipFileDeserializer::FinalizeL( CEZZStream& aZStream ) |
|
109 { |
|
110 TPtrC8 od = aZStream.OutputDescriptor(); |
|
111 iCrc = crc32(iCrc,od.Ptr(),od.Size()); |
|
112 iParser->ParseL( od ); |
|
113 iParser->ParseEndL(); |
|
114 } |