|
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-84922B27-FDCF-56FD-91ED-5E0BFE3ED0E4" xml:lang="en"><title>Compressing |
|
13 and Decompressing File - Zip Format </title><shortdesc>The Zip Compression Library, EZLib provides stream and file compression |
|
14 and decompression functionality for the Symbian platforms. The files can be |
|
15 compressed to two formats namely zip and gzip. Compression and Decompression |
|
16 are performed iteratively, till the completion of required task. </shortdesc><prolog><metadata><keywords/></metadata></prolog><taskbody> |
|
17 <context id="GUID-BE620F4A-6D23-5832-8C2A-4B9C75F6BF12"/> |
|
18 <steps id="GUID-0DE92899-962B-5E18-9378-EB7B6C78E7BD"> |
|
19 <step id="GUID-414B561B-4BCA-5D6F-A744-3944D0EBDBE2"><cmd>Pass the input and |
|
20 output files as parameters to construct an instance of <xref href="GUID-A54D8675-1874-3B4F-816D-001A235C0F9C.dita"><apiname>CEZFileBufferManager</apiname></xref>. |
|
21 This returns a pointer to <xref href="GUID-A54D8675-1874-3B4F-816D-001A235C0F9C.dita"><apiname>CEZFileBufferManager</apiname></xref> (input buffer). </cmd> |
|
22 <info> <xref href="GUID-A54D8675-1874-3B4F-816D-001A235C0F9C.dita"><apiname>CEZFileBufferManager</apiname></xref> provides functions that accept |
|
23 and converts the data into buffers for <xref href="GUID-B90BA6D6-72A2-3EB8-B8EF-CD5408107A9E.dita"><apiname>MEZBufferManager</apiname></xref> class |
|
24 to manage it internally. </info> |
|
25 </step> |
|
26 <step id="GUID-BA8CC59E-FD6B-5ACA-A516-EBFFB5316D30"><cmd/> |
|
27 <info>Pass the input buffer and other compression parameters to the object |
|
28 of the <xref href="GUID-AEF8BCC8-6B24-3D59-AD3A-17B5203B3AA5.dita"><apiname>CEZCompressor</apiname></xref> class. </info> |
|
29 </step> |
|
30 <step id="GUID-BD4E38F1-78A7-5ED3-83D7-6C56EE7122DD"><cmd/> |
|
31 <info>Use <xref href="GUID-AEF8BCC8-6B24-3D59-AD3A-17B5203B3AA5.dita#GUID-AEF8BCC8-6B24-3D59-AD3A-17B5203B3AA5/GUID-03E4E3A2-3830-3209-9D7B-A2238B5AF219"><apiname>CEZCompressor::DeflateL()</apiname></xref> to compress the file. </info> |
|
32 </step> |
|
33 </steps> |
|
34 <example><p>The following code demonstrates a compression procedure. </p><codeblock xml:space="preserve">/* |
|
35 * Compresses the file into a zip file using the EZlib component. |
|
36 * It is assumed that the input and output file names are contained in a |
|
37 * provided ini file. |
|
38 */ |
|
39 |
|
40 |
|
41 void CEZlibEZipTests::DoEZlibDeflateL() |
|
42 { |
|
43 RFs iFs; |
|
44 iFS.connect(); |
|
45 |
|
46 |
|
47 |
|
48 //Open input file |
|
49 _LIT(KInputFileLocation, "c:\\private\\E80000B7\\zip\\input\\input.doc"); |
|
50 TFileName inputFile(KInputFileLocation); |
|
51 RFile input; |
|
52 err = input.Open(iFs, inputFile, EFileStream | EFileRead | EFileShareExclusive); |
|
53 if(err != KErrNone) |
|
54 { |
|
55 INFO_PRINTF1(KOpenFileError); |
|
56 User::Leave(err); |
|
57 } |
|
58 |
|
59 |
|
60 |
|
61 //open output file |
|
62 |
|
63 _LIT(KOutputFileLocation, "c:\\private\\E80000B7\\zip\\input\\output.zip"); |
|
64 TFileName outputFile(KOutputFileLocation); |
|
65 RFile output; |
|
66 err = output.Replace(iFs, outputFile, EFileStream | EFileWrite | EFileShareExclusive); |
|
67 if(err != KErrNone) |
|
68 { |
|
69 INFO_PRINTF1(KCreateFileError); |
|
70 User::Leave(err); |
|
71 } |
|
72 |
|
73 |
|
74 |
|
75 CEZFileBufferManager *bufferManager = CEZFileBufferManager::NewLC(input, output); |
|
76 CEZCompressor *compressor = CEZCompressor::NewLC(*bufferManager, aLevel, aWindowBits, aMemLevel, aStrategy); |
|
77 |
|
78 while(compressor->DeflateL()) |
|
79 { |
|
80 } |
|
81 output.Close(); |
|
82 input.Close(); |
|
83 iFS.Close(); |
|
84 |
|
85 |
|
86 |
|
87 } |
|
88 </codeblock></example> |
|
89 <postreq><p>The decompression of a <filepath>.zip</filepath> file can be achieved |
|
90 through the following the steps: </p> <ol id="GUID-468D2F53-B015-5DAB-96A7-08DBE8101773"> |
|
91 <li id="GUID-23A8B3BC-0C23-503A-969A-EAD80BBDA3ED"><p>Pass the |
|
92 input and output files as parameters to construct an instance of <xref href="GUID-A54D8675-1874-3B4F-816D-001A235C0F9C.dita"><apiname>CEZFileBufferManager</apiname></xref>. |
|
93 This returns a pointer to <xref href="GUID-A54D8675-1874-3B4F-816D-001A235C0F9C.dita"><apiname>CEZFileBufferManager</apiname></xref> ( buffer). </p> </li> |
|
94 <li id="GUID-60335F30-42FF-57A1-8457-ADFAE6C34E76"><p>Pass the buffer to the |
|
95 object of the <xref href="GUID-BC3CEC02-B747-38FB-8B35-E7390DB06E35.dita"><apiname>CEZDecompressor</apiname></xref> class. </p> </li> |
|
96 <li id="GUID-969C35D8-AAB8-5875-9DA9-B80D0F402EB1"><p> <xref href="GUID-BC3CEC02-B747-38FB-8B35-E7390DB06E35.dita#GUID-BC3CEC02-B747-38FB-8B35-E7390DB06E35/GUID-0AC99B66-412B-3CCF-84DA-D7BC0F0D32B2"><apiname>CEZDecompressor::InflateL()</apiname></xref> is |
|
97 called repeatedly until the decompression is complete. </p> </li> |
|
98 </ol> <p>The following code demonstrates the decompression procedure. </p> <codeblock id="GUID-4A0A0D64-939C-587F-B9C7-F34B8F934E25" xml:space="preserve">/* Decompresses the file contained in a Zip file using the EZlib component. |
|
99 * It is assumed that the input and output file names are contained in a |
|
100 * provided ini file. |
|
101 */ |
|
102 |
|
103 void CEZlibEZipTests::DoEZlibInflateL() |
|
104 { |
|
105 RFs iFs; |
|
106 iFS.connect(); |
|
107 |
|
108 //Open input file |
|
109 _LIT(KInputFileLocation, "c:\\private\\E80000B7\\zip\\input\\output.zip"); |
|
110 TFileName inputFile(KInputFileLocation); |
|
111 RFile input; |
|
112 err = input.Open(iRfs, inputFile, EFileStream | EFileRead | EFileShareExclusive); |
|
113 if(err != KErrNone) |
|
114 { |
|
115 INFO_PRINTF1(KOpenFileError); |
|
116 User::Leave(err); |
|
117 } |
|
118 |
|
119 |
|
120 |
|
121 //open output file |
|
122 |
|
123 _LIT(KOutputFile, "c:\\private\\E80000B7\\zip\\input\\input.doc"); |
|
124 TFileName outputFile(KOutputFile); |
|
125 RFile output; |
|
126 err = output.Replace(iFs, outputFile, EFileStream | EFileWrite | EFileShareExclusive); |
|
127 if(err != KErrNone) |
|
128 { |
|
129 INFO_PRINTF1(KCreateFileError); |
|
130 User::Leave(err); |
|
131 } |
|
132 |
|
133 |
|
134 |
|
135 CEZFileBufferManager *bufferManager = CEZFileBufferManager::NewLC(input, Output); |
|
136 CEZDecompressor *decompressor = CEZDecompressor::NewLC(*bufferManager, aWindowBits); |
|
137 |
|
138 |
|
139 while(decompressor->InflateL()) |
|
140 { |
|
141 } |
|
142 output.Close(); |
|
143 input.Close(); |
|
144 ifs.Close(); |
|
145 |
|
146 }</codeblock> </postreq> |
|
147 </taskbody></task> |