Why do you need to mount zip files instead using simple zip tools?
Applications usually generate some combinations of files as output such as xml, pictures, sound and put them to a folder. Packing all of those files and folders into single file and set custom extension for that file is common idea. The new file that includes other files is called container. Because of the fact put 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 focuses on zip archives as a container of files not other types of containers.
For example, java programmers use the zip file format to create java archive files with jar extension or Microsoft uses it for Microsoft Office Word 2007 (with DOCX extension), Microsoft Excel (with XLSX tension) and Microsoft PowerPoint 2007 (with PPTX extension). You can change file’s extension to zip and open those with zip tools applications. One of the advantages of using containers is to hide file structure complexity from the user view and give a single compressed file. After putting files into a zip archive you will have an important challenge:
How can your applications work with files in the container?Packaging the output file of an application into a zip file or any other format is not a complex task, but the application have some problems when it needs 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’s 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 these make it awesome and you need to extract them to temp folder, it requires time, loosing performance and so on. By mounting a zip file in your application process, these entire problems will be solved. Your application can pack its output as a standard zip archive and just mount it when needed.
There are three solutions exist for using zip archive:
- Extracting zip archives to a temporary folder.
- Opening each file or stream in zip archive with API of zip libraries.
- Mounting zip archive in the application process.
Now let us see the advantage and disadvantage of each approach.
Note: Shetab Mount Zip Library supports all three approaches.
1. Extract all of them into temporary folder and open each required file.
First approach for using files inside of zip archive is extracting them to a temporary folder and then work with files in a standard way. Before application terminated this temporary folder should be deleted. Shetab Mount Zip Library has tow interface IZipStorage and IZipStream that you can in your program for this approach.
Advantage
- You have a write access to files, but you need to pack it again.
- This solution is not bad for small files, but couldn't used for big files
- Easy to use and No complexity
- Don’t require to change code to access the files and stream
- Compatible with all current code and components
Disadvantage
- It will be very slow for big files, user must wait till all files extracted into disk. In some case it will be unacceptable.
- It requires some disk space on user hard disk to extract files.
- It requires disk clean up before your program closed, if your program close unexpectedly the file will remain on user computer.
- Your user can see all files detail in temp folder
2. Open each file or stream in zip file with zip tools.
In this case application can open file and folder in a zip archive directly as stream and storage with some methods. Shetab Mount Zip Library provides the two standard COM Interfaces to a zip archive file, IZipStorage and IZipStream that derived from COM IStorage and IStream.
Advantage
- This solution is good if all of your application code and component can use stream.
- You can have write access to stream with some zip tools
- It fast cause doesn’t require unzipping entire container to a temp folder
- It more secure cause doesn't require to unzip entire container to a temp folder
- It doesn't require additional space in a temp folder
Disadvantage
- Programmer should do special programming for this approach and it will be more complex than using a normal file system
- Not compatible with all components such as web browsers
3. Mount Zip files in your application process.
In this case application can open file and folder as normal files and folders.
Advantage
- Easy to use and No complexity
- Don’t require to change code to access the files and stream
- Compatible with all current code and components
- Don't require space to unzip the entire container to a temp folder
- It fast cause doesn’t require unzipping entire container to a temp folder
- It more secure cause doesn’t require to unzip entire container to a temp folder
- It doesn’t require additional space to a temp folder
Disadvantage
- Usually could not write to a zip file while mounting system has started
Note: in approach 2 and 3 opening a zip archive for write access have some restrictions.
Case Study
To understand more read the following scenario:
Your application is Auto Run Builder or Multimedia Builder application; it gets images, flash, sound, movie and html and so on. All of these files altogether may take a large size and we want insert these in one or some of zip archive files. Now we should select one of the approaches mentioned above.
Which approach is suitable in this scenario?
After review advantage and disadvantage of three exists approach we see the mounting approach is best solution because:
- First approach is not suitable because archive files are large and it will be slow and need much disk space for extracting archive files.
- Second approach is not suitable too because in your program used of flash and html that not supported streaming.
For mounting approach with Shetab Mount Zip Library you can pack your application's generated files and folders into single or multiple zip archive file at runtime and you can create single executable file of it. When your output Auto Run executed it is just enough to call “IBoxManager.Mount()” method to make all files and folders inside of its executable as normal file system without extracting them to a disk or memory. Your application can read all files inside of a zip archive (or self-extracted exe) same as when they are unzipped. It is so fast and easy.