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.


  1. Hi Gilad and thanks for sharing this.

    Your app works great. However, I'm trying to decompress a folder that was compressed using your class on a linux server. I tried using gunzip amongst others but I keep getting an error.

    Any ideas how I would go about doing that?

  2. Hi Nick,
    to have the compression work as a GZIP, you will have to make some adjustments. per file that is added to the archive you need to have:
    * a 10-byte header, containing a magic number, a version number and a timestamp
    * optional extra headers, such as the original file name,
    * a body, containing a DEFLATE-compressed payload
    * an 8-byte footer, containing a CRC-32 checksum and the length of the original uncompressed data

    you can find all this at:

    for my particular needs, the file entries contain the file name and the payload. in case its a directory, instead of the binary payload i have a list of children.

    mind you, i found a bug today in the distribute function:
    line 95 should read: resStream.writeBytes(d,0,d.bytesAvailable);
    instead of the writeObject currently there.

    hope this helps..

  3. link for dropbox is broken

  4. i try to download the file but i cant get that. anyone can help me to get ?

  5. Anyone have any luck finding the source files?

  6. Arghh where is the source :-(

  7. HI Gilad Manor source is missing from dropBox. Can u fix it.
    suvrajit nayak

  8. found it:
    sorry guys


Please do not post spam on this blog, Spam sites will be reported to google.
thank you kindly.