Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/ezlibexample_8cpp_source.html
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>TB9.2 Example Applications: examples/SysLibs/EzlibExample/ezlibexample.cpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.2 -->
<h1>examples/SysLibs/EzlibExample/ezlibexample.cpp</h1><a href="ezlibexample_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).</span>
<a name="l00002"></a>00002 <span class="comment">// All rights reserved.</span>
<a name="l00003"></a>00003 <span class="comment">// This component and the accompanying materials are made available</span>
<a name="l00004"></a>00004 <span class="comment">// under the terms of "Eclipse Public License v1.0"</span>
<a name="l00005"></a>00005 <span class="comment">// which accompanies this distribution, and is available</span>
<a name="l00006"></a>00006 <span class="comment">// at the URL "http://www.eclipse.org/legal/epl-v10.html".</span>
<a name="l00007"></a>00007 <span class="comment">//</span>
<a name="l00008"></a>00008 <span class="comment">// Initial Contributors:</span>
<a name="l00009"></a>00009 <span class="comment">// Nokia Corporation - initial contribution.</span>
<a name="l00010"></a>00010 <span class="comment">//</span>
<a name="l00011"></a>00011 <span class="comment">// Contributors:</span>
<a name="l00012"></a>00012 <span class="comment">//</span>
<a name="l00013"></a>00013 <span class="comment">// Description:</span>
<a name="l00014"></a>00014 <span class="comment">// This example program demonstrates the use of the Ezlib API. </span>
<a name="l00015"></a>00015 <span class="comment">// The code demonstrates how to </span>
<a name="l00016"></a>00016 <span class="comment">// -# Open a ZIP file and get the properties of each file</span>
<a name="l00017"></a>00017 <span class="comment">// -# Extract a selected member of the ZIP file and save it to a new file. </span>
<a name="l00018"></a>00018 <span class="comment">// -# Save all the members of a ZIP file to a file.</span>
<a name="l00019"></a>00019 <span class="comment">// -# Open a GZIP file and extract the contents to a file. </span>
<a name="l00020"></a>00020 <span class="comment">// -# Compress a file into a GZIP file.</span>
<a name="l00021"></a>00021 <span class="comment">//</span>
<a name="l00022"></a>00022
<a name="l00023"></a>00023
<a name="l00024"></a>00024
<a name="l00028"></a>00028 <span class="preprocessor">#include "<a class="code" href="ezlibexample_8h.html">ezlibexample.h</a>"</span>
<a name="l00029"></a>00029 <span class="preprocessor">#include <e32cons.h></span>
<a name="l00030"></a>00030 <span class="preprocessor">#include <ezgzip.h></span>
<a name="l00031"></a>00031
<a name="l00032"></a>00032 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KTitle, <span class="stringliteral">"Ezlib example"</span>);
<a name="l00033"></a>00033 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KTextPressAKey, <span class="stringliteral">"\n\nPress any key to step through the example\n"</span>);
<a name="l00034"></a>00034 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KExit,<span class="stringliteral">"\nPress any key to exit the application"</span>);
<a name="l00035"></a>00035 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KPressAKey,<span class="stringliteral">"\nPress any key to continue \n"</span>);
<a name="l00036"></a>00036 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KProperties,<span class="stringliteral">"Press any key to have a look at the properties of the zipped files \n"</span>);
<a name="l00037"></a>00037 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KDecompress,<span class="stringliteral">"Gzip file successfully decompressed\n"</span>);
<a name="l00038"></a>00038 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KCompress,<span class="stringliteral">"\nFile successfully compressed to gzip format and saved\n"</span>);
<a name="l00039"></a>00039 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KNoFilesFound,<span class="stringliteral">"No appropriate files located in this folder.\r\n"</span>);
<a name="l00040"></a>00040 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KLineSpace, <span class="stringliteral">"\r\n"</span>);
<a name="l00041"></a>00041 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KFileInfo,<span class="stringliteral">"\nCompressing file %S"</span>);
<a name="l00042"></a>00042 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KFileOpen,<span class="stringliteral">"\nOpening file: %S\r\n"</span>);
<a name="l00043"></a>00043 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KFileExtract,<span class="stringliteral">"\nExtracting the file %S\n"</span>);
<a name="l00044"></a>00044 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KFileZipExtract,<span class="stringliteral">"\nExtracting files from the zip file %S\n"</span>);
<a name="l00045"></a>00045
<a name="l00046"></a>00046 <span class="preprocessor">#if defined(__WINS__)</span>
<a name="l00047"></a>00047 <span class="preprocessor"></span><a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KCInputZipFile, <span class="stringliteral">"\\private\\E80000B7\\zip\\input\\EzlibZipFolder.zip"</span>);
<a name="l00048"></a>00048 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KCInputGzipPath, <span class="stringliteral">"\\private\\E80000B7\\gzip\\error.wav"</span>);
<a name="l00049"></a>00049 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KCInputGzipFile, <span class="stringliteral">"\\private\\E80000B7\\gzip\\icon.bmp.gz"</span>);
<a name="l00050"></a>00050 <span class="preprocessor">#endif</span>
<a name="l00051"></a>00051 <span class="preprocessor"></span>
<a name="l00052"></a>00052 <span class="preprocessor">#if defined(__EPOC32__)</span>
<a name="l00053"></a>00053 <span class="preprocessor"></span><a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KZInputZipFile, <span class="stringliteral">"z:\\private\\E80000B7\\zip\\input\\EzlibZipFolder.zip"</span>);
<a name="l00054"></a>00054 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KZInputGzipPath, <span class="stringliteral">"z:\\private\\E80000B7\\gzip\\error.wav"</span>);
<a name="l00055"></a>00055 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KZInputGzipFile, <span class="stringliteral">"z:\\private\\E80000B7\\gzip\\icon.bmp.gz"</span>);
<a name="l00056"></a>00056 <span class="preprocessor">#endif</span>
<a name="l00057"></a>00057 <span class="preprocessor"></span>
<a name="l00058"></a>00058 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KZipName,<span class="stringliteral">"\nName: %S "</span>);
<a name="l00059"></a>00059 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KZipCRC32,<span class="stringliteral">"\nCRC32: %X "</span>);
<a name="l00060"></a>00060 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KZipCSize,<span class="stringliteral">"\nCompressed Size: %d"</span>);
<a name="l00061"></a>00061 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KZipUCSize,<span class="stringliteral">"\nUncompressed Size: %d"</span>);
<a name="l00062"></a>00062 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KOpenedSuccessfully, <span class="stringliteral">"%S opened successfully.\n"</span>);
<a name="l00063"></a>00063
<a name="l00064"></a>00064 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KExtractZipPathMulti, <span class="stringliteral">"\\private\\E80000B7\\zip\\extracts\\"</span>);
<a name="l00065"></a>00065 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KExtractZipPathSingle, <span class="stringliteral">"\\private\\E80000B7\\zip\\extracts\\singlefile\\"</span>);
<a name="l00066"></a>00066 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KCompressGzipPath, <span class="stringliteral">"\\private\\E80000B7\\gzip\\extracts\\"</span>);
<a name="l00067"></a>00067 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KCompressZipFile, <span class="stringliteral">"icon.bmp"</span>);
<a name="l00068"></a>00068 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KExtractGzipFile, <span class="stringliteral">"error.wav"</span>);
<a name="l00069"></a>00069
<a name="l00075"></a><a class="code" href="class_c_ezlib_example.html#a7c541c9d16531ccc9ca4876cc9bfa33f">00075</a> <a class="code" href="class_c_ezlib_example.html">CEzlibExample</a> * <a class="code" href="class_c_ezlib_example.html#a7c541c9d16531ccc9ca4876cc9bfa33f">CEzlibExample::NewLC</a>()
<a name="l00076"></a>00076 {
<a name="l00077"></a>00077 <a class="code" href="class_c_ezlib_example.html">CEzlibExample</a> * rep = <span class="keyword">new</span>(ELeave) <a class="code" href="class_c_ezlib_example.html">CEzlibExample</a>();
<a name="l00078"></a>00078 CleanupStack::PushL(rep);
<a name="l00079"></a>00079 rep->ConstructL();
<a name="l00080"></a>00080 <span class="keywordflow">return</span> rep;
<a name="l00081"></a>00081 }
<a name="l00082"></a>00082
<a name="l00086"></a>00086 CEzlibExample::CEzlibExample()
<a name="l00087"></a>00087 {
<a name="l00088"></a>00088 }
<a name="l00089"></a>00089
<a name="l00090"></a>00090 <span class="keywordtype">void</span> CEzlibExample::ConstructL()
<a name="l00091"></a>00091 {
<a name="l00092"></a>00092 iConsole = Console::NewL(KTitle,TSize(KConsFullScreen,KConsFullScreen));
<a name="l00093"></a>00093 iConsole->Printf(KTextPressAKey);
<a name="l00094"></a>00094 iConsole->Getch();
<a name="l00095"></a>00095 }
<a name="l00096"></a>00096
<a name="l00100"></a><a class="code" href="class_c_ezlib_example.html#a48c59ffbda5ce37120fa9d017830d57c">00100</a> <a class="code" href="class_c_ezlib_example.html#a48c59ffbda5ce37120fa9d017830d57c">CEzlibExample::~CEzlibExample</a>()
<a name="l00101"></a>00101 {
<a name="l00102"></a>00102 iConsole->Printf(KExit);
<a name="l00103"></a>00103 iConsole->Getch();
<a name="l00104"></a>00104
<a name="l00105"></a>00105 <span class="keyword">delete</span> iConsole;
<a name="l00106"></a>00106 }
<a name="l00107"></a>00107
<a name="l00108"></a>00108
<a name="l00123"></a><a class="code" href="class_c_ezlib_example.html#af8c5bb49dba35b4870f4849ec1a70151">00123</a> <span class="keywordtype">void</span> <a class="code" href="class_c_ezlib_example.html#af8c5bb49dba35b4870f4849ec1a70151">CEzlibExample::GetPropertiesL</a>(TFileName& aFileName, RFs& aFsSession)
<a name="l00124"></a>00124 {
<a name="l00125"></a>00125 CZipFile* zipFile = 0;
<a name="l00126"></a>00126 CZipFileMember* member = 0;
<a name="l00127"></a>00127 CZipFileMemberIterator* fileMembers;
<a name="l00128"></a>00128
<a name="l00129"></a>00129 iConsole->Printf(KFileOpen, &aFileName);
<a name="l00130"></a>00130
<a name="l00131"></a>00131 zipFile = CZipFile::NewL(aFsSession, aFileName);
<a name="l00132"></a>00132 CleanupStack::PushL(zipFile);
<a name="l00133"></a>00133
<a name="l00134"></a>00134 iConsole->Printf(KOpenedSuccessfully, &aFileName);
<a name="l00135"></a>00135
<a name="l00136"></a>00136 <span class="comment">// Search for a file in the zip archive.</span>
<a name="l00137"></a>00137 <span class="comment">// The name of the file to be searched for </span>
<a name="l00138"></a>00138 <span class="comment">// in the zipfile is case-insensitive.</span>
<a name="l00139"></a>00139 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KSearchFile, <span class="stringliteral">"EzlibZipFolder\\icon.bmp"</span>);
<a name="l00140"></a>00140 member = zipFile->CaseInsensitiveMemberL(KSearchFile);
<a name="l00141"></a>00141 CleanupStack::PushL(member);
<a name="l00142"></a>00142 <span class="keywordflow">if</span>(member != NULL)
<a name="l00143"></a>00143 {
<a name="l00144"></a>00144 <span class="comment">// Extract the file that was searched for and found.</span>
<a name="l00145"></a>00145 <a class="code" href="class_c_ezlib_example.html#a5e98fd4d876b8bada261be2de5cd755d">ExtractFilesL</a>(member, zipFile, aFsSession, KExtractZipPathSingle);
<a name="l00146"></a>00146 iConsole->Printf(KFileExtract, &KSearchFile);
<a name="l00147"></a>00147 }
<a name="l00148"></a>00148 <span class="keywordflow">else</span>
<a name="l00149"></a>00149 {
<a name="l00150"></a>00150 iConsole->Printf(KNoFilesFound);
<a name="l00151"></a>00151 }
<a name="l00152"></a>00152 CleanupStack::PopAndDestroy(member);
<a name="l00153"></a>00153 <span class="comment">// Gets the iterator used for iterating through the files </span>
<a name="l00154"></a>00154 <span class="comment">// contained in the ZIP file. </span>
<a name="l00155"></a>00155 fileMembers = zipFile->GetMembersL();
<a name="l00156"></a>00156 CleanupStack::PushL(fileMembers);
<a name="l00157"></a>00157 <span class="comment">// Moves the entry iterator onto the next </span>
<a name="l00158"></a>00158 <span class="comment">// zip file member contained in the ZIP file</span>
<a name="l00159"></a>00159 member = fileMembers->NextL();
<a name="l00160"></a>00160
<a name="l00161"></a>00161 iConsole->Printf(KFileZipExtract, &aFileName);
<a name="l00162"></a>00162 iConsole->Printf(KProperties);
<a name="l00163"></a>00163 iConsole->Getch();
<a name="l00164"></a>00164
<a name="l00165"></a>00165 <span class="comment">// Get the properties of all the files</span>
<a name="l00166"></a>00166 <span class="keywordflow">while</span>(member != NULL)
<a name="l00167"></a>00167 {
<a name="l00168"></a>00168 CleanupStack::PushL(member);
<a name="l00169"></a>00169
<a name="l00170"></a>00170 <span class="comment">// Retrieve CRC(Cyclic Redundancy Check) value in a compressed file </span>
<a name="l00171"></a>00171 <span class="comment">// contained in a CZipFile archive file.</span>
<a name="l00172"></a>00172 TUint32 redundencyCode = member->CRC32();
<a name="l00173"></a>00173
<a name="l00174"></a>00174 <span class="comment">// Retrieve the size of uncompressed file </span>
<a name="l00175"></a>00175 <span class="comment">// contained in a CZipFile archive file.</span>
<a name="l00176"></a>00176 TUint32 UnCompSize = member->UncompressedSize();
<a name="l00177"></a>00177
<a name="l00178"></a>00178 <span class="comment">// Retrieve the size of compressed file </span>
<a name="l00179"></a>00179 <span class="comment">// contained in a CZipFile archive file.</span>
<a name="l00180"></a>00180 TUint32 CompSize = member->CompressedSize();
<a name="l00181"></a>00181
<a name="l00182"></a>00182 <span class="comment">// Print the properties</span>
<a name="l00183"></a>00183 <span class="comment">// Name of the zipped file</span>
<a name="l00184"></a>00184 TFileName fileName = *member->Name();
<a name="l00185"></a>00185 iConsole->Printf(KZipName, &fileName);
<a name="l00186"></a>00186
<a name="l00187"></a>00187 <span class="comment">// CRC value which will be printed in hexadecimal</span>
<a name="l00188"></a>00188 iConsole->Printf(KZipCRC32, redundencyCode);
<a name="l00189"></a>00189
<a name="l00190"></a>00190 <span class="comment">// Size of the compressed file</span>
<a name="l00191"></a>00191 iConsole->Printf(KZipCSize, CompSize);
<a name="l00192"></a>00192
<a name="l00193"></a>00193 <span class="comment">// Original size of te file</span>
<a name="l00194"></a>00194 iConsole->Printf(KZipUCSize,UnCompSize);
<a name="l00195"></a>00195
<a name="l00196"></a>00196 <span class="comment">// Extract each member in the zip file</span>
<a name="l00197"></a>00197 <a class="code" href="class_c_ezlib_example.html#a5e98fd4d876b8bada261be2de5cd755d">ExtractFilesL</a>(member, zipFile, aFsSession, KExtractZipPathMulti);
<a name="l00198"></a>00198
<a name="l00199"></a>00199 CleanupStack::PopAndDestroy(member);
<a name="l00200"></a>00200 member = fileMembers->NextL();
<a name="l00201"></a>00201 }
<a name="l00202"></a>00202
<a name="l00203"></a>00203 CleanupStack::PopAndDestroy(fileMembers);
<a name="l00204"></a>00204 CleanupStack::PopAndDestroy(zipFile);
<a name="l00205"></a>00205 }
<a name="l00206"></a>00206
<a name="l00218"></a><a class="code" href="class_c_ezlib_example.html#a5e98fd4d876b8bada261be2de5cd755d">00218</a> <span class="keywordtype">void</span> <a class="code" href="class_c_ezlib_example.html#a5e98fd4d876b8bada261be2de5cd755d">CEzlibExample::ExtractFilesL</a>(<span class="keyword">const</span> CZipFileMember* aMember, CZipFile* aZipFile, RFs& aFsSession, <span class="keyword">const</span> TDesC& aOutputPath)
<a name="l00219"></a>00219 {
<a name="l00220"></a>00220 TInt loop = 0;
<a name="l00221"></a>00221 <span class="comment">// Allocate memory for the retrieved name of a </span>
<a name="l00222"></a>00222 <span class="comment">// compressed file contained in a CZipFile archive file.</span>
<a name="l00223"></a>00223 HBufC* name = aMember->Name()->AllocLC();
<a name="l00224"></a>00224 <span class="keywordflow">while</span>(loop < name->Length())
<a name="l00225"></a>00225 {
<a name="l00226"></a>00226 <span class="keywordflow">if</span>((*name)[loop] == <span class="charliteral">'/'</span>)
<a name="l00227"></a>00227 {
<a name="l00228"></a>00228 name->Des()[loop] = <span class="charliteral">'\\'</span>;
<a name="l00229"></a>00229 }
<a name="l00230"></a>00230 loop++;
<a name="l00231"></a>00231 }
<a name="l00232"></a>00232
<a name="l00233"></a>00233 <span class="comment">// Create the directory to which the files need to be extracted.</span>
<a name="l00234"></a>00234 TFileName fn;
<a name="l00235"></a>00235 fn.Append(aOutputPath);
<a name="l00236"></a>00236 <span class="comment">// Append the name of the file to the directory </span>
<a name="l00237"></a>00237 <span class="comment">// where the file would get extracted.</span>
<a name="l00238"></a>00238 fn.Append(*name);
<a name="l00239"></a>00239 aFsSession.MkDirAll(fn);
<a name="l00240"></a>00240
<a name="l00241"></a>00241 RFile extractedMember;
<a name="l00242"></a>00242 extractedMember.Replace(aFsSession,fn, EFileShareAny|EFileWrite);
<a name="l00243"></a>00243 CleanupClosePushL(extractedMember);
<a name="l00244"></a>00244
<a name="l00245"></a>00245 RZipFileMemberReaderStream* fileStream;
<a name="l00246"></a>00246 <span class="comment">// Create and return the input stream for a file in the archive.</span>
<a name="l00247"></a>00247 TInt error = aZipFile->GetInputStreamL(aMember, fileStream);
<a name="l00248"></a>00248 <span class="keywordflow">if</span>(error != KErrNone)
<a name="l00249"></a>00249 {
<a name="l00250"></a>00250 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KCompressionNotSupported, <span class="stringliteral">"Error! Compression Method Not Supported"</span>);
<a name="l00251"></a>00251 iConsole->Printf(KCompressionNotSupported);
<a name="l00252"></a>00252 iConsole->Printf(KLineSpace);
<a name="l00253"></a>00253 CleanupStack::PopAndDestroy(2,name); <span class="comment">//expanded member, name</span>
<a name="l00254"></a>00254 aFsSession.Delete(fn);
<a name="l00255"></a>00255 <span class="keywordflow">return</span>;
<a name="l00256"></a>00256 }
<a name="l00257"></a>00257 CleanupStack::PushL(fileStream);
<a name="l00258"></a>00258
<a name="l00259"></a>00259 <span class="comment">// Retrieve the size of uncompressed file contained </span>
<a name="l00260"></a>00260 <span class="comment">// in a CZipFile archive file.</span>
<a name="l00261"></a>00261 TUint16 size = aMember->UncompressedSize();
<a name="l00262"></a>00262
<a name="l00263"></a>00263 RBuf8 bytes;
<a name="l00264"></a>00264 bytes.CreateL(size);
<a name="l00265"></a>00265 bytes.CleanupClosePushL();
<a name="l00266"></a>00266
<a name="l00267"></a>00267 <span class="comment">// Read the specified number of bytes of binary data </span>
<a name="l00268"></a>00268 <span class="comment">// from the file at the current position.</span>
<a name="l00269"></a>00269 User::LeaveIfError(fileStream->Read(bytes,size));
<a name="l00270"></a>00270 <span class="comment">// Write to the file</span>
<a name="l00271"></a>00271 User::LeaveIfError(extractedMember.Write(bytes));
<a name="l00272"></a>00272
<a name="l00273"></a>00273 CleanupStack::PopAndDestroy(4,name); <span class="comment">// bytes, fileStream, expanded member and name</span>
<a name="l00274"></a>00274
<a name="l00275"></a>00275 }
<a name="l00276"></a>00276
<a name="l00285"></a><a class="code" href="class_c_ezlib_example.html#a81f560db578514ae40d41a6946ad7e6b">00285</a> <span class="keywordtype">void</span> <a class="code" href="class_c_ezlib_example.html#a81f560db578514ae40d41a6946ad7e6b">CEzlibExample::ExtractGzipFileL</a>(RFs& aFsSession)
<a name="l00286"></a>00286 {
<a name="l00287"></a>00287 iConsole->Printf(KPressAKey);
<a name="l00288"></a>00288 iConsole->Getch();
<a name="l00289"></a>00289
<a name="l00290"></a>00290 <span class="preprocessor"> #if defined(__WINS__)</span>
<a name="l00291"></a>00291 <span class="preprocessor"></span> TFileName gzipInputFileName(KCInputGzipFile);
<a name="l00292"></a>00292 <span class="preprocessor"> #endif</span>
<a name="l00293"></a>00293 <span class="preprocessor"></span>
<a name="l00294"></a>00294 <span class="preprocessor"> #if defined(__EPOC32__)</span>
<a name="l00295"></a>00295 <span class="preprocessor"></span> TFileName gzipInputFileName(KZInputGzipFile);
<a name="l00296"></a>00296 <span class="preprocessor"> #endif</span>
<a name="l00297"></a>00297 <span class="preprocessor"></span>
<a name="l00298"></a>00298 <span class="comment">//TFileName gzipInputFileName(KInputGzipFile);</span>
<a name="l00299"></a>00299
<a name="l00300"></a>00300 RFile input;
<a name="l00301"></a>00301 RFile output;
<a name="l00302"></a>00302
<a name="l00303"></a>00303 User::LeaveIfError(input.Open(aFsSession, gzipInputFileName, EFileStream | EFileRead | EFileShareAny));
<a name="l00304"></a>00304 CleanupClosePushL(input);
<a name="l00305"></a>00305
<a name="l00306"></a>00306 TFileName outputFile(KCompressGzipPath);
<a name="l00307"></a>00307 <span class="comment">// Append the path to the directory where you want to </span>
<a name="l00308"></a>00308 <span class="comment">// store the uncompressed file.</span>
<a name="l00309"></a>00309 aFsSession.MkDirAll(outputFile);
<a name="l00310"></a>00310 outputFile.Append(KCompressZipFile);
<a name="l00311"></a>00311
<a name="l00312"></a>00312 <span class="comment">// Create and open icon.bmp on </span>
<a name="l00313"></a>00313 <span class="comment">// c:\private\E80000B7\gzip\extracts\ folder.</span>
<a name="l00314"></a>00314 output.Replace(aFsSession, outputFile, EFileStream | EFileWrite | EFileShareExclusive);
<a name="l00315"></a>00315 CleanupClosePushL(output);
<a name="l00316"></a>00316
<a name="l00317"></a>00317 <span class="comment">// icon.bmp.gz file is the input file</span>
<a name="l00318"></a>00318 TPtrC inputFile = gzipInputFileName;
<a name="l00319"></a>00319
<a name="l00320"></a>00320 RBuf uncompressedFile;
<a name="l00321"></a>00321 uncompressedFile.CreateL(outputFile.Length());
<a name="l00322"></a>00322 uncompressedFile.CleanupClosePushL();
<a name="l00323"></a>00323
<a name="l00324"></a>00324 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KUfl,<span class="stringliteral">"%S"</span>);
<a name="l00325"></a>00325 <span class="comment">// Format and copy the filename into the descriptor</span>
<a name="l00326"></a>00326 uncompressedFile.Format(KUfl,&inputFile);
<a name="l00327"></a>00327
<a name="l00328"></a>00328 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KInfo,<span class="stringliteral">"\nDecompressing file %S\n"</span>);
<a name="l00329"></a>00329 iConsole->Printf(KInfo,&inputFile);
<a name="l00330"></a>00330
<a name="l00331"></a>00331 CEZGZipToFile *def = <a class="code" href="class_c_ezlib_example.html#a7c541c9d16531ccc9ca4876cc9bfa33f">CEZGZipToFile::NewLC</a>(aFsSession,uncompressedFile,output);
<a name="l00332"></a>00332
<a name="l00333"></a>00333 <span class="comment">// Decompress the gzip file</span>
<a name="l00334"></a>00334 <span class="keywordflow">while</span>(def->InflateL())
<a name="l00335"></a>00335 {
<a name="l00336"></a>00336 <span class="comment">// InflateL decompresses the file in stages. </span>
<a name="l00337"></a>00337 <span class="comment">// It returns false when decompression is complete</span>
<a name="l00338"></a>00338 }
<a name="l00339"></a>00339 iConsole->Printf(KDecompress);
<a name="l00340"></a>00340
<a name="l00341"></a>00341 CleanupStack::PopAndDestroy(4); <span class="comment">// input, output, uncompressedFile, def</span>
<a name="l00342"></a>00342
<a name="l00343"></a>00343 }
<a name="l00344"></a>00344
<a name="l00353"></a><a class="code" href="class_c_ezlib_example.html#a462f99cf9b1dd1ebdc0fbc279cc7d229">00353</a> <span class="keywordtype">void</span> <a class="code" href="class_c_ezlib_example.html#a462f99cf9b1dd1ebdc0fbc279cc7d229">CEzlibExample::CompressToGzipFileL</a>(RFs& aFsSession)
<a name="l00354"></a>00354 {
<a name="l00355"></a>00355 iConsole->Printf(KPressAKey);
<a name="l00356"></a>00356 iConsole->Getch();
<a name="l00357"></a>00357
<a name="l00358"></a>00358 <span class="preprocessor"> #if defined(__WINS__)</span>
<a name="l00359"></a>00359 <span class="preprocessor"></span> TFileName inputFileToBeGzipped(KCInputGzipPath);
<a name="l00360"></a>00360 <span class="preprocessor"> #endif</span>
<a name="l00361"></a>00361 <span class="preprocessor"></span>
<a name="l00362"></a>00362 <span class="preprocessor"> #if defined(__EPOC32__)</span>
<a name="l00363"></a>00363 <span class="preprocessor"></span> TFileName inputFileToBeGzipped(KZInputGzipPath);
<a name="l00364"></a>00364 <span class="preprocessor"> #endif</span>
<a name="l00365"></a>00365 <span class="preprocessor"></span> <span class="comment">//TFileName inputFileToBeGzipped(KInputGzipPath);</span>
<a name="l00366"></a>00366
<a name="l00367"></a>00367 RFile input;
<a name="l00368"></a>00368
<a name="l00369"></a>00369 User::LeaveIfError(input.Open(aFsSession, inputFileToBeGzipped, EFileStream | EFileRead | EFileShareAny));
<a name="l00370"></a>00370 CleanupClosePushL(input);
<a name="l00371"></a>00371
<a name="l00372"></a>00372 <span class="comment">// Set the output path to the directory where you </span>
<a name="l00373"></a>00373 <span class="comment">// want to store the compressed file.</span>
<a name="l00374"></a>00374 TFileName outputFile(KCompressGzipPath);
<a name="l00375"></a>00375 aFsSession.MkDirAll(outputFile);
<a name="l00376"></a>00376 outputFile.Append(KExtractGzipFile);
<a name="l00377"></a>00377
<a name="l00378"></a>00378 iConsole->Printf(KFileInfo, &inputFileToBeGzipped);
<a name="l00379"></a>00379
<a name="l00380"></a>00380 <span class="comment">// Prevent the length of the descriptor to which data is written,</span>
<a name="l00381"></a>00381 <span class="comment">// from exceeding its maximum length by appending additional length.</span>
<a name="l00382"></a>00382 <span class="keyword">const</span> TInt extensionLength = 3;
<a name="l00383"></a>00383
<a name="l00384"></a>00384 RBuf compressedFile;
<a name="l00385"></a>00385 compressedFile.CreateL(outputFile.Length() + extensionLength);
<a name="l00386"></a>00386 compressedFile.CleanupClosePushL();
<a name="l00387"></a>00387
<a name="l00388"></a>00388 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KAppendExtension,<span class="stringliteral">"%S.gz"</span>);
<a name="l00389"></a>00389 <span class="comment">// Format and copy the filename into the descriptor</span>
<a name="l00390"></a>00390 compressedFile.Format(KAppendExtension,&outputFile);
<a name="l00391"></a>00391
<a name="l00392"></a>00392 CEZFileToGZip *def = <a class="code" href="class_c_ezlib_example.html#a7c541c9d16531ccc9ca4876cc9bfa33f">CEZFileToGZip::NewLC</a>(aFsSession, compressedFile, input);
<a name="l00393"></a>00393 <span class="comment">// Compress the file to gzip format</span>
<a name="l00394"></a>00394 <span class="keywordflow">while</span>(def->DeflateL())
<a name="l00395"></a>00395 {
<a name="l00396"></a>00396 <span class="comment">// DeflateL compresses the file in stages. </span>
<a name="l00397"></a>00397 <span class="comment">// It returns false when compression is complete</span>
<a name="l00398"></a>00398 }
<a name="l00399"></a>00399
<a name="l00400"></a>00400 iConsole->Printf(KCompress);
<a name="l00401"></a>00401
<a name="l00402"></a>00402 CleanupStack::PopAndDestroy(3); <span class="comment">// def, compressedFile, input</span>
<a name="l00403"></a>00403
<a name="l00404"></a>00404 }
<a name="l00405"></a>00405
<a name="l00406"></a>00406
<a name="l00407"></a><a class="code" href="ezlibexample_8cpp.html#a689e0bf9aa924a1d7dc108665d44736c">00407</a> LOCAL_C <span class="keywordtype">void</span> MainL()
<a name="l00408"></a>00408 {
<a name="l00409"></a>00409 <span class="comment">// Create an Active Scheduler to handle asychronous calls</span>
<a name="l00410"></a>00410 CActiveScheduler* scheduler = <span class="keyword">new</span>(ELeave) CActiveScheduler;
<a name="l00411"></a>00411 CleanupStack::PushL(scheduler);
<a name="l00412"></a>00412 CActiveScheduler::Install( scheduler );
<a name="l00413"></a>00413
<a name="l00414"></a>00414 <a class="code" href="class_c_ezlib_example.html">CEzlibExample</a> * app = <a class="code" href="class_c_ezlib_example.html#a7c541c9d16531ccc9ca4876cc9bfa33f">CEzlibExample::NewLC</a>();
<a name="l00415"></a>00415
<a name="l00416"></a>00416 RFs fsSession;
<a name="l00417"></a>00417 <span class="comment">// Connect to file session</span>
<a name="l00418"></a>00418 User::LeaveIfError(fsSession.Connect());
<a name="l00419"></a>00419
<a name="l00420"></a>00420 <span class="comment">// Create the private directory on the writable drive</span>
<a name="l00421"></a>00421 <span class="comment">// i.e. "\private\E80000B7\"</span>
<a name="l00422"></a>00422 <span class="comment">// Note that the number E80000B7 is the process security id </span>
<a name="l00423"></a>00423 <span class="comment">// taken from the 2nd UID specified in the mmp file.</span>
<a name="l00424"></a>00424
<a name="l00425"></a>00425 fsSession.CreatePrivatePath(RFs::GetSystemDrive());
<a name="l00426"></a>00426 <span class="comment">// Set the session path to this private directory on the writable drive</span>
<a name="l00427"></a>00427 fsSession.SetSessionToPrivate(RFs::GetSystemDrive());
<a name="l00428"></a>00428
<a name="l00429"></a>00429 <span class="comment">// Get the properties of files in the zip file</span>
<a name="l00430"></a>00430 <span class="preprocessor"> #if defined(__WINS__)</span>
<a name="l00431"></a>00431 <span class="preprocessor"></span> TBuf<256> inputFileName(KCInputZipFile);
<a name="l00432"></a>00432 <span class="preprocessor"> #endif</span>
<a name="l00433"></a>00433 <span class="preprocessor"></span>
<a name="l00434"></a>00434 <span class="preprocessor"> #if defined(__EPOC32__)</span>
<a name="l00435"></a>00435 <span class="preprocessor"></span> TBuf<256> inputFileName(KZInputZipFile);
<a name="l00436"></a>00436 <span class="preprocessor"> #endif</span>
<a name="l00437"></a>00437 <span class="preprocessor"></span>
<a name="l00438"></a>00438 app-><a class="code" href="class_c_ezlib_example.html#af8c5bb49dba35b4870f4849ec1a70151">GetPropertiesL</a>(inputFileName, fsSession);
<a name="l00439"></a>00439
<a name="l00440"></a>00440 <span class="comment">// Compress a file to gzip format</span>
<a name="l00441"></a>00441 app-><a class="code" href="class_c_ezlib_example.html#a462f99cf9b1dd1ebdc0fbc279cc7d229">CompressToGzipFileL</a>(fsSession);
<a name="l00442"></a>00442
<a name="l00443"></a>00443 <span class="comment">// Extract a gzip file</span>
<a name="l00444"></a>00444 app-><a class="code" href="class_c_ezlib_example.html#a81f560db578514ae40d41a6946ad7e6b">ExtractGzipFileL</a>(fsSession);
<a name="l00445"></a>00445
<a name="l00446"></a>00446 CleanupStack::PopAndDestroy(2); <span class="comment">//app, scheduler</span>
<a name="l00447"></a>00447 <span class="comment">// Close the file session</span>
<a name="l00448"></a>00448 fsSession.Close();
<a name="l00449"></a>00449
<a name="l00450"></a>00450 }
<a name="l00451"></a>00451
<a name="l00452"></a><a class="code" href="ezlibexample_8cpp.html#a0f358e9c4355138f629b8c4f37310295">00452</a> GLDEF_C TInt E32Main()
<a name="l00453"></a>00453 {
<a name="l00454"></a>00454 __UHEAP_MARK;
<a name="l00455"></a>00455 CTrapCleanup* cleanup = CTrapCleanup::New();
<a name="l00456"></a>00456 <span class="keywordflow">if</span>(cleanup == NULL)
<a name="l00457"></a>00457 {
<a name="l00458"></a>00458 <span class="keywordflow">return</span> KErrNoMemory;
<a name="l00459"></a>00459 }
<a name="l00460"></a>00460 TRAPD(err, MainL());
<a name="l00461"></a>00461 <span class="keywordflow">if</span>(err != KErrNone)
<a name="l00462"></a>00462 {
<a name="l00463"></a>00463 User::Panic(_L(<span class="stringliteral">"Failed to complete"</span>),err);
<a name="l00464"></a>00464 }
<a name="l00465"></a>00465
<a name="l00466"></a>00466 <span class="keyword">delete</span> cleanup;
<a name="l00467"></a>00467 __UHEAP_MARKEND;
<a name="l00468"></a>00468 <span class="keywordflow">return</span> KErrNone;
<a name="l00469"></a>00469 }
<a name="l00470"></a>00470
<a name="l00471"></a>00471
</pre></div></div>
<hr size="1"/><address style="text-align: right;"><small>Generated by
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.2 </small></address>
</body>
</html>