Thursday, April 1, 2010

Flex Directory Compression

Here is an example for compression and decompression of files and directories using the DEFLATE compression algorithm. 

The structure I have created for the file structure in the compressed file is arbitrary.  for each file it describes the name and data witch is a byte array of the file content. Directories do not have a data attribute, but children that recursively describe files with in.  


Download the source code here

Download the example AIR application here

 
When running the example, drag and drop a file or directory into the upper box, this will catch the link and create a compressed version of the file in the application storage directory (i.e. /AppData/Roaming/Deflator/Local Store)

To extract the file back, click on the compressed file in the list and click the extract button. This will recreate the file or directory on your desktop.




Please note: that if the original file is still on the desktop when you extract, you will have an error. so if you deflated something from the desktop, make sure you rename it before you extract

Good luck.