ASZip Logo
As you may know, I am currently working on AlivePDF and I had to generate zip files from AS3, to generate Mars files with AlivePDF.

After looking for the Zip file format specification, I found this great article on and ported it to AS3.

Here comes ASZip to generate Zip files from scratch with some files and folders into it.

This first version is using the native gzip (Deflate) compression from the flash.utils.Bytearray.compress() method, more compression algorithms will be added later like PPMD or Bzip2 and more.

To generate a zip file, with a text file and a PNG file, you would do :

// create the Zip file, first param : compression method
var myZip:ASZip = new ASZip (CompressionMethod.GZIP);
// create a flash.display.BitmapData
var myStevie:Stevie = new Stevie (0, 0);
// encode it as a PNG
var bytes:ByteArray = PNGEnc.encode (myStevie);
// create a text stream
var txt:ByteArray = new ByteArray();
// write some text into it
txt.writeUTFBytes("Hello there !!");
// add a pics folder
myZip.addDirectory ("pics/");
// then a text folder
myZip.addDirectory ("text/");
// pass the PNG stream and specify a file name and location
myZip.addFile (bytes, "pics/stevie.png");
// pass the text stream and specify a file name and location
myZip.addFile (txt, "text/story.txt");
// add a comment
myZip.addComment ("A comment !");
// save the current zip in a remote context
myZip.saveZIP ( Method.REMOTE, 'create.php', Download.ATTACHMENT, '' );
// save the current zip in a local context (AIR)
var myZipFile:ByteArray = myZip.saveZIP ( Method.LOCAL );

Online demo :

A Flash animation should have appeared here, but it seems that your browser has an older version of the Flash Player or it is not installed at all. Please, install the last release of the Flash Player now, then reload this page.

Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 License.

Sources and documentation available at