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.
Hi Gilad and thanks for sharing this.
ReplyDeleteYour 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?
Cheers,
Nick.
Hi Nick,
ReplyDeleteto 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: http://en.wikipedia.org/wiki/Gzip
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..
link for dropbox is broken
ReplyDeletelink for dropbox is broken
ReplyDeletei try to download the file but i cant get that. anyone can help me to get ?
ReplyDeleteAnyone have any luck finding the source files?
ReplyDeleteArghh where is the source :-(
ReplyDeletePunks :)
ReplyDeleteHI Gilad Manor source is missing from dropBox. Can u fix it.
ReplyDeletesuvrajit nayak
suvrajitn@riaxe.com
found it: https://github.com/giladmanor/JunkYard/tree/master/actionscript
ReplyDeletesorry guys