This is a mirror of official site: http://jasper-net.blogspot.com/

Mount zip file in application process

| Thursday, October 28, 2010
Opening a zip package in a program without extracting
Introduction

Applications usually generate some combination of files as output such as xml, pictures, sound and put them in a folder. Packing all of that files and folders into single file and set custom extension for that file is common idea. The new file that includes other files called container. Because of the zip file format is a portable and standard format, many applications use zip file format for containers (usually with a custom extension). This article focus to zip archive as container of files not other containers.

For example java programmers use zip file format for create java archive files with jar extension or Microsoft corporative use it for Microsoft Office Word 2007 (with DOCX extension), Microsoft Excel (with XLSX extension) and Microsoft PowerPoint 2007 (with PPTX extension). You can change file’s extension to zip and open those with zip tools applications.

This article wants to introduce how to use zip archives in our application? How many solutions exist? And what is the best solution?

Why you need to mount the zip file instead using simple zip tools?

Packaging data to container as zip archive has some advantage that programmer use it. In this section we want to discuss about opening zip archive and use its files in our application process.

Some of the advantages of using containers are hide file structure complexity from the user view and give a single compressed file. After some files put in a zip archive you have an important problem: How can applications work with files in the container?

Packaging the output file of an application in zip file or any other format is not complex task, but the application have some problems when it need to open package and access the files inside the package, it may need to extract all of them in temp folder. Even if your zip tools support opening files as “stream” directly from zip archive some component may not support streaming such as “Flash”. Some component like web browser support streaming but what happen to the included file in html such as CSS and pictures? You may find how to give web browser the opened stream but you will need to recalculate all references to files and create other stream for them, all of this make it awesome and you need to extract them to temp folder, it require time, loosing performance and so on. By mounting zip file in your application process this entire problem solved. Your package makes the generated document file as standard zip archive and just mounts them when needed.

There are three solutions exist for using zip archive:

1. Extracting zip archives in a temporary folder.

2. Opening each file or stream in zip archive with API of zip libraries.

3. Mounting zip archive in the application process.

Now let us see the advantage and disadvantage of each approach.

1. Extract all of them into temporary folder and open each required file.

First approach for using the application from files inside of zip archive is extract it in a temporary folder and act with files in a standard way. after terminating application this temporary folder can be deleted

Read more: Codeproject

Posted via email from .NET Info

0 comments: