|
1 <?xml version="1.0" encoding="utf-8"?> |
|
2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. --> |
|
3 <!-- This component and the accompanying materials are made available under the terms of the License |
|
4 "Eclipse Public License v1.0" which accompanies this distribution, |
|
5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". --> |
|
6 <!-- Initial Contributors: |
|
7 Nokia Corporation - initial contribution. |
|
8 Contributors: |
|
9 --> |
|
10 <!DOCTYPE task |
|
11 PUBLIC "-//OASIS//DTD DITA Task//EN" "task.dtd"> |
|
12 <task id="GUID-FDDAF8E9-4CAB-5489-B578-A5362E2140C1" xml:lang="en"><title>Decompressing |
|
13 File Archives</title><abstract><shortdesc>The Zip Compression Library, EZLib provides file archive |
|
14 decompression functionality for the Symbian platforms. </shortdesc> <p>EZLib |
|
15 allows clients to decompress data from file archives. The decompression task |
|
16 is performed by calling the decompression functions iteratively, until the |
|
17 required task completion. </p> </abstract><prolog><metadata><keywords/></metadata></prolog><taskbody> |
|
18 <context><p>The input archive file is opened and the properties of all the |
|
19 files in the archive are retrieved. </p> </context> |
|
20 <steps id="GUID-0D781F2C-8D11-5792-98D5-76091DA8EBBB"> |
|
21 <step id="GUID-E92A26A2-F56D-5FA0-A583-43B227AE670C"><cmd/> |
|
22 <info>Pass the input file archive and create an instance of the <xref href="GUID-79C613E8-35F8-319B-BE8B-1411CBE5AF00.dita"><apiname>CZipFile</apiname></xref> class.</info> |
|
23 <info> The <xref href="GUID-79C613E8-35F8-319B-BE8B-1411CBE5AF00.dita"><apiname>CZipFile</apiname></xref> is a read only interface. It does not |
|
24 support file compression to a single or multiple zip file archives. </info> |
|
25 </step> |
|
26 <step id="GUID-8E916762-869C-5E9C-B38C-43B55805EB73"><cmd/> |
|
27 <info>Invoke <xref href="GUID-79C613E8-35F8-319B-BE8B-1411CBE5AF00.dita#GUID-79C613E8-35F8-319B-BE8B-1411CBE5AF00/GUID-7F528528-1814-39A6-BE14-CA1F7AABFD06"><apiname>CZipFile::GetMembersL()</apiname></xref> that returns a pointer |
|
28 of <xref href="GUID-D458AE6A-EC64-3882-BCEA-A44A43DAA99A.dita"><apiname>CZipFileMemberIterator</apiname></xref> </info> |
|
29 <info>The <xref href="GUID-D458AE6A-EC64-3882-BCEA-A44A43DAA99A.dita"><apiname>CZipFileMemberIterator</apiname></xref> iterator |
|
30 class provides functions that point to the first file in the archive and to |
|
31 navigate through all the entries in the archive. </info> |
|
32 <info>The <xref href="GUID-D458AE6A-EC64-3882-BCEA-A44A43DAA99A.dita"><apiname>CZipFileMemberIterator</apiname></xref> iterator class can access |
|
33 each member of the zip archive using <xref href="GUID-D458AE6A-EC64-3882-BCEA-A44A43DAA99A.dita#GUID-D458AE6A-EC64-3882-BCEA-A44A43DAA99A/GUID-610F12F0-C1B7-39BB-A446-7616BBF84B2C"><apiname>CZipFileMemberIterator::NextL()</apiname></xref> </info> |
|
34 </step> |
|
35 <step id="GUID-BB056063-4391-5EC7-A223-ED752E2F1B32"><cmd/> |
|
36 <info>The properties of the member file are retrieved using the functions |
|
37 of <xref href="GUID-02A8BC62-D653-39A3-BE0C-92A5F3F43E85.dita"><apiname>CZipFileMember</apiname></xref>. </info> |
|
38 <info>The <xref href="GUID-02A8BC62-D653-39A3-BE0C-92A5F3F43E85.dita"><apiname>CZipFileMember</apiname></xref> class retrieves the properties |
|
39 of the member file once the member file is accessible. </info> |
|
40 </step> |
|
41 <step id="GUID-4EAC4BD5-551B-58A3-A6B4-D4433027F5C8"><cmd/> |
|
42 <info>The files extracted from the archive are stored in the output folder. </info> |
|
43 <info>If the output folder is unavailable a new folder is created prior to |
|
44 archive decompression. </info> |
|
45 </step> |
|
46 </steps> |
|
47 <example><p>The following example code illustrates the decompression of file |
|
48 archive. </p><codeblock xml:space="preserve">/* |
|
49 * Decompresses all the files in "inputarchive.zip" using the EZlib. |
|
50 * If an input filename is not specified it is assumed that the |
|
51 * input file name is contained in a provided .ini file. |
|
52 */ |
|
53 void CEZlibEZipTests::DoEZlibZipArchiveDecompressL() |
|
54 { |
|
55 RFs iFs; |
|
56 iFS.connect(); |
|
57 CleanupClosePushL(iFS); |
|
58 TInt err = KErrNone; |
|
59 HBufC8 *outputBuffer = HBufC8::NewLC(outputBufferSize); |
|
60 |
|
61 _LIT(KInputFileLocation, "c:\\private\\E80000B7\\zip\\input\\inputarchive.zip"); |
|
62 TFileName inputFile(KInputFileLocation); |
|
63 |
|
64 RFile input; |
|
65 err = input.Open(iFs, inputFile, EFileStream | EFileRead | EFileShareExclusive); |
|
66 if(err != KErrNone) |
|
67 { |
|
68 INFO_PRINTF1(KOpenFileError); |
|
69 User::Leave(err); |
|
70 } |
|
71 CleanupClosePushL(input); |
|
72 |
|
73 CZipFile *zipFile = CZipFile::NewL(iFs,input); |
|
74 CleanupStack::PushL(zipFile); |
|
75 CZipFileMemberIterator *fileMemberIter = zipFile->GetMembersL(); |
|
76 |
|
77 // iZipArchiveEzlibFolder = GenerateZipArchiveFolderNameL(aInputFileName); |
|
78 // iZipArchiveEzlibFolder.Append(KZipArchiveEzlib); |
|
79 |
|
80 for(TOLDEZIP::CZipFileMember *fileMember = fileMemberIter->NextL(); fileMember != NULL; fileMember = fileMemberIter->NextL()) |
|
81 { |
|
82 TFileName tmpfilename(*(fileMember->Name())); |
|
83 |
|
84 // Check if we have a folder or file |
|
85 TPtrC lastChar = tmpfilename.Right(1); |
|
86 if(lastChar.Compare(_L("\\")) != 0 && lastChar.Compare(_L("/")) != 0) |
|
87 { |
|
88 RFile output; |
|
89 err = output.Replace(iFs, tmpfilename, EFileStream | EFileWrite | EFileShareExclusive); |
|
90 if(err != KErrNone) |
|
91 { |
|
92 INFO_PRINTF1(KCreateFileError); |
|
93 User::Leave(err); |
|
94 } |
|
95 CleanupClosePushL(output); |
|
96 |
|
97 TOLDEZIP::RZipFileMemberReaderStream *readerStream; |
|
98 zipFile->GetInputStreamL(fileMember, readerStream); |
|
99 CleanupStack::PushL(readerStream); |
|
100 |
|
101 TPtr8 pOutputBuffer = outputBuffer->Des(); |
|
102 do |
|
103 { |
|
104 err = readerStream->Read(pOutputBuffer, outputBufferSize); |
|
105 output.Write(pOutputBuffer); |
|
106 } while(err == KErrNone); |
|
107 if(err != KErrEof) |
|
108 { |
|
109 User::Leave(err); |
|
110 } |
|
111 CleanupStack::PopAndDestroy(2); |
|
112 } |
|
113 else |
|
114 { |
|
115 TFileName fullPath("c:\\private\\E80000B7\\zip\\input\\"); |
|
116 fullPath.Append(tmpfilename); |
|
117 iRfs.MkDir(fullPath); |
|
118 } |
|
119 } |
|
120 CleanupStack::PopAndDestroy(3); |
|
121 } |
|
122 </codeblock></example> |
|
123 </taskbody></task> |