symbian读写zip
来源:互联网 发布:nba各年状元体测数据 编辑:程序博客网 时间:2024/05/17 03:38
The most popular archive file format used these days isZIP, originally created by Phil Katz from the modification of ARCformat. Symbian OS provides a class, called CZipFile, to read ZIP file.This class is supported by Symbian since version 7.x. This article willshow how to use CZipFile and give an example. You can compile and runthe example in Series 60 2.x or UIQ 2.x.
Although CZipFile is documented in Symbian SDKs, theexplanation is far from enough. Another challenge, there is no examplehow to use the class. That's why I write this article to share myexperience reading ZIP file in Symbian OS. I hope this would be usefulfor you.
Reading ZIP File
Let's start with a simple case, open a ZIP file anddisplay information of all the files inside the ZIP file. Firstly, weneed to create a new instance of CZipFile. There is a two-phaseconstructor that you can use to create it.
CleanupStack::PushL(zipFile);
The first parameter of the constructor is a session of File Server. The second parameter is the file name of the ZIP file.
Next, we have to get the iterator for the ZIP file toiterate all the files one by one. It can be done by callingCZipFile::GetMembersL(). The return value is an instance ofCZipFileMemberIterator class.
CleanupStack::PushL(members);
Note that the ownership of members will be passed to the caller, thus we have to delete it after we are done.
Now, how can we get the instance of each file? Bycalling CZipFileMemberIterator::NextL(). We have to call this methoduntil it returns 0, which means there is no more file. Look at thefollowing example:
while ((member = members->NextL()) != 0)
{
console->Printf(
KInfoMessage,
member->Name(),
member->CompressedSize(), member->UncompressedSize());
delete member;
}
The example above prints the name, compressed size anduncompressed size of all the files in the ZIP file. Note that we haveto delete member because the ownership is passed to caller.
Finally, don't forget to release all the resources that we have allocated.
CleanupStack::PopAndDestroy(); // zipFile
If we have a ZIP file that contains three file, i.e.Example.txt, Example.dat and Example.png, the output will look likethis (you can download this ZIP file at the end of this article).
Example.dat - 15 - 180
Example.png - 4393 - 4393
Extracting a File from ZIP File
This section shows how to extract a specific file froma ZIP file. As the previous example, the first step is to create theinstance of CZipFile.
CleanupStack::PushL(zipFile);
Here, we don't need an iterator because we areinterested only in a specific file. The method that we have to call toget the instance of it is CZipFile::CaseInsensitiveMemberL(). Thismethod requires a parameter, that is the file name that you want toaccess.
CleanupStack::PushL(member);
Once again, we have to delete member after we havefinished using it.The next step is to the input stream and use the Read() method toextract the file. The input stream of a file inside ZIP file isRZipFileMemberReaderStream. The method used to get the input stream isCZipFile::GetInputStreamL().
zipFile->GetInputStreamL(member, stream);
CleanupStack::PushL(stream);
The following code shows how to read the file. Beforereading the file, the code allocates a buffer to store with the size ofmember->UncompressesedSize().
TPtr8 bufferPtr(buffer->Des());
User::LeaveIfError(stream->Read(bufferPtr, member->UncompressedSize()));
If your file is quite huge, do not use "one-shot"Read() like the example above. It is not good because it will blockyour program. Instead, read using a small block of buffer and do itinside an active object. This example use "one-shot" Read() forsimplicity reason.
Now we have the extracted file in a buffer. You can useit right away, or alternatively you can write it to a file. Here is theexample how to write it to a file.
User::LeaveIfError(file.Replace(fileSession, fileName, EFileWrite));
CleanupClosePushL(file);
User::LeaveIfError(file.Write(*buffer));
Finally, do not forget to release all the allocated resources.
CleanupStack::PopAndDestroy(5); // file, buffer, stream, member, zipFile
Example
The following file contains the complete source code ofthe two examples above. This example is a console program. The outputof the compiled example is a standalone .exe file, ZipExample.exe. Copythis file to your device at c:/systems/programs or any otherdirectories. Before running the example, make sure that you have copied/group/Example.zip to c:/data/Example.zip on your device too.
The example does two things, i.e.:
Display information of all the files contained in c:/data/Example.zip. It is done in IteratorExampleL() function.
Extract Example.txt from c:/data/Example.zip and save it to c:/data/Example.txt. It is done in ExtractionExampleL() function.
原文地址:http://www.newlc.com/en/Reading-ZIP-File-in-Symbian-OS.html
- symbian读写zip
- Symbian Zip解压问题
- Symbian中读写配置文件
- Symbian 文件读写实例
- Java读写Zip文件
- Java读写Zip文件
- java读写zip
- Symbian中文件的读写
- 在Symbian OS中读取ZIP文件
- 在Symbian OS中读取ZIP文件
- Symbian解压缩Zip包的方法
- 读写zip格式的文件
- symbian os :TFileText 读写文本的实例
- symbian OS:流读写文件的实例
- Symbian文档类读写文件和读写Ini文件
- 在iPhone上读写zip文件
- 在iPhone上读写zip文件
- 在iPhone上读写zip文件
- 【20100121】今天firefox碰到了一个郁闷的问题
- ORACLE数据库导入导出
- QWebView使用SIMSUN字体时,遇到网页按钮字体显示不正常处理方法
- Google protocol buffer程序书写小结
- d3d读取.x文件
- symbian读写zip
- 什么是SSH?
- P2P网络中DHT算法分析
- Mapguide open source 利用 king.Oracle的问题。
- vim替换功能
- C语言的两个小函数: 格式化当前时间和返回字符串中两个子字符串间的内容
- Reading Codes in Linux, by taglist + ctags
- fckedit和struts2集成不能上传文件的解决方法
- C#获取项目程序路径的方法