ASZip 0.1

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

Comments (41)

  1. sean wrote:

    Is good!
    I have been using fzip, but it Bunaiyasu.


    Tuesday, August 7, 2007 at 4:59 am #
  2. Pieter wrote:

    These projects of yours are truly useful. Great job!

    Tuesday, August 7, 2007 at 8:14 am #
  3. Jérôme wrote:

    Faut arrêter la cocaïne p’tit gars. Tu crois pas qu’avec ce que tu produis en ce moment on s’en est pas rendu compte ?

    Tuesday, August 7, 2007 at 10:01 am #
  4. Thibault Imbert wrote:

    Je tourne à l’andouillette Jérome, pas pareil ;)

    Tuesday, August 7, 2007 at 12:54 pm #
  5. Hey Thibault, this is great. Thanks for sharing!

    Tuesday, August 7, 2007 at 2:30 pm #
  6. Pixelmixer wrote:

    Wow… great stuff :)

    Tuesday, August 7, 2007 at 6:35 pm #
  7. Thibault Imbert wrote:

    Happy you like it guys ! :)

    Wednesday, August 8, 2007 at 10:43 pm #
  8. katopz wrote:

    thx! that’s work really fine to me
    can’t wait for inflate and password, ;)

    Friday, August 10, 2007 at 1:15 pm #
  9. !Seve wrote:

    Thibault, great job!. Thanks for sharing!!

    Saturday, August 11, 2007 at 3:16 pm #
  10. Marcus wrote:

    Awesome!!! Really great! Thanks for sharing.

    Thursday, September 13, 2007 at 11:39 am #
  11. Marcus wrote:

    Hello Thibault,

    can you please show an example to add an image to a zip file.

    I don’t understand your:

    var myStevie:Stevie = new Stevie(0,0);

    “Stevie” seems to be the picture, but how add you the image from a server into the zip file (via url)? And I don’t have a Stevie-Class.

    Can I also add non-image-files (e.g. *.pdf, *.dwg [CAD-File]) to the zip via bytearray? And how? I did not found anything in the documentation.


    Thursday, September 13, 2007 at 2:49 pm #
  12. Thibault Imbert wrote:

    Hi Marcus,

    The addFile method takes an incoming ByteArray, so you can add everything into the zip file. The important thing is to retrieve the file bytearray.

    For the Stevie class, it’s compressed with the PNG encoder which returns a bytearray that I pass to the addFile method.

    For example, if you want to embed an image from an URL into the zip file, load it with URLLoader then retrieve the bytearray from it and pass it to the addFile method :)

    let me know ;)

    Thursday, September 13, 2007 at 3:02 pm #
  13. Marcus wrote:

    Hi Thibault,

    URLLoader works fine! Thanks!

    And adding a *.dwg File also works. It seems that we can zip all file-types via bytearray. :-)

    But my small “problem”

    Friday, September 14, 2007 at 8:15 pm #
  14. Marcus wrote:

    … is to add multiple files via URLLoader. But I think I can make it.

    Sorry for the 2 posts. My ENTER-Key is sooo big. :-)

    Friday, September 14, 2007 at 8:18 pm #
  15. andiskater wrote:

    The zip-File created by the online Demo does not work (using Mac OS X integrated un-zip application and “The Unarchiver”).
    There seems to be something wrong about the archive. Another expander application on OS X 7zX seems to be able to expand the archive, but the resulting stevie.png image is corrupted.

    Friday, September 28, 2007 at 4:32 pm #
  16. Thibault Imbert wrote:

    Hi andiskater,

    Yes I heard about this problem using Mac OS X. I will fix that in the next version coming up :)

    Thanks :)


    Saturday, September 29, 2007 at 1:40 pm #
  17. I can never download half of the stuff you post.

    I always get 404′s all the time.

    Monday, October 15, 2007 at 11:31 pm #
  18. Thibault Imbert wrote:

    Hi Mario,

    sorry about that, server has been hacked I am hunting for broken links !

    let me know, I fixed the broken links on this post :)


    Tuesday, October 16, 2007 at 2:41 am #
  19. Uh oh… dreamhost?

    I feel your pain dude, I got hit with that index changing bot some time back… it really sucked.

    Wednesday, October 17, 2007 at 5:02 pm #
  20. End-of-central-directory signature not found. Either this file is not
    a zipfile, or it constitutes one disk of a multi-part archive. In the
    latter case the central directory and zipfile comment will be found on
    the last disk(s) of this archive.
    zipinfo: cannot find zipfile directory in one of

    Friday, November 23, 2007 at 11:31 am #
  21. Thibault Imbert wrote:

    Hi Misterniak,

    Which unzip program are you using ?
    Thanks you :)


    Friday, November 23, 2007 at 3:09 pm #
  22. papa wrote:

    did u ever get around to making a new build that does not cause errors on OSX? I am really excited by this, however I really need OSX support for the project I will be using it on. Thanks!

    Saturday, January 5, 2008 at 1:10 am #
  23. Thibault Imbert wrote:

    Hi papa,

    Yes, I will work on that as soon as possible. Drop me an email so that I can let you know, and talk about it ;)

    kind regards,


    Saturday, January 5, 2008 at 1:51 am #
  24. Rui Cruz wrote:

    Hi thibault, I need to add password to zip file, how do I do it?

    Monday, April 14, 2008 at 2:58 am #
  25. Sam wrote:

    Hi thibault , Should I do some settings in the Web Server?
    I try the example download from your ASzip googlecode project , with my localhost server, but unluckly I got a zip file with 0 bytes.
    Appreciate for your response.:(

    Friday, April 25, 2008 at 5:00 am #
  26. Maíra wrote:

    Hi, very nice library! The thing is… Is zip saving local only for AIR? Maybe I’m missing something…

    Friday, May 23, 2008 at 12:47 pm #
  27. Maíra wrote:

    i think my actul question is: how to convert the byteArray into the actual file without php, so internet wouldn’t be required and i could save my file local?

    Friday, May 23, 2008 at 1:12 pm #
  28. Thibault Imbert wrote:

    Hi Maíra,

    You have to solutions to create the zip file without any server involved.

    First one is to use this library with AIR, where you will be able to save the Zip ByteArray on your hard disk.

    The other one is to use Astro (Flash Player 10) which has such a feature (local file saving).

    Let me know :)

    Saturday, May 24, 2008 at 4:57 am #
  29. Maíra wrote:

    Hey Thibault,

    I’ve decided to try it with zinc, as this is suposed to integrate a project the uses it.

    I’m using the mdm.FileSystem.BinaryFile.writeData() and the setData() but is still not understanding my string (byteArray converted to string).

    It generates the zip file but I can’t open it… not in hexadecimal or decimal string coding… well,i’ll keep on trying things here.


    Monday, May 26, 2008 at 11:13 am #
  30. Marcus wrote:

    Hey Thibault,

    your zip is realy great. I am using this with no problems under windows. But today I realized that there is a problem under Mac OS X. In the comments you mentioned that you will fix this problem in the next release. Any news about that? Thanks!

    Tuesday, July 15, 2008 at 10:58 am #
  31. A bit off topic, but can this code be subverted to perform the “save as” dialog function for an mp3 file?

    Currently in html whether a mp3 tries to play in the browser (via something like quicktime) or generate the “save as” pop up is dependent on the users setup of their web browser. As I create and distribute music, see the site, I some times want to specifically distribute a track as a download, not have it open and play in a browser window?

    Hope this makes sense…

    Great work

    Friday, July 17, 2009 at 8:54 pm #
  32. g wrote:

    Does anybody have a patch for the Mac problem? I am assuming this never got fixed; a developer is working on a downloader for an application I am working on and it does not work with Mac default, but does with Stuffit Expander for Mac.

    Friday, July 31, 2009 at 2:09 pm #
  33. odon kwon wrote:

    It’s good.
    I will using this…

    Monday, September 21, 2009 at 6:33 am #
  34. Jordan W wrote:

    OSX bug fixed – at least mine was – culprit nbDirectory. have you caught the unixToDos month bug? feedArrayRow and addCentralRecord not needed, bloat memory. few others. I’m not going to make it pretty, but code is here – – expects static crc32, use in same folder or change code. Change import for crc32.

    Tuesday, February 9, 2010 at 5:47 pm #
  35. P48l0 wrote:

    Dosent work for me. I´m using the sample and XAMP. But when i download the generated zip it says it´s broken and not valid.

    PHP Version 5.3.1
    Windows XP SP3

    Monday, December 6, 2010 at 5:25 pm #
  36. P48l0 wrote:

    It works, i was using the PHP but i noticed that it had a type, it says $pdf where it should say $zip.

    It works.

    Monday, December 6, 2010 at 5:36 pm #
  37. sasky wrote:

    Hey is it possible to add mp3 files (as already loaded content, so they are Sound objects) to the add file function?

    so How can you turn a Sound object into a byteArray?

    Thursday, December 9, 2010 at 12:45 pm #
  38. Naresh wrote:

    Hi Thibault,

    I tried the ASZip with the argument as gzip compression (default) and with “none” and created the zip file successfully. BUT the generated file does not open with Mac’z Archive utility. Am I missing something here?

    Also ASZip seems bit faster than FZip in generating the final byte array :)

    Thanks, Naresh

    Friday, March 11, 2011 at 10:15 am #
  39. Good API and efficient results, but it would be nice if your library included gzip reading functions.

    Monday, March 26, 2012 at 12:25 pm #
  40. Andrew wrote:

    Where does one find the that Jordan uses?

    Tuesday, July 3, 2012 at 5:26 pm #
  41. Robbie wrote:

    Hi, I am using this lib with player 14.0 beta and the byte array is being posted fine but doesn’t seem to be getting saved to the server (so I imagine this maybe something to do with php5?). I can proxy the bytearray and it returns a status of 200 but there is nothing saved. Any thoughts on why this could be?

    Tuesday, May 27, 2014 at 8:54 am #

Trackbacks/Pingbacks (6)

  1. [...] Thibault Imbert made a class while working on his AlivePDF application that allows you to add files in AS3 to an ASZip object which generates a zip file on your local filesystem.  Some of the stuff going on in the community these days just blows my mind thinking back on how this was all impossible no more than two years ago.  Crazy stuff; gotta love this community and the people in it. [...]

  2. Silverlight Preloader with Downloader « [ draw.logic ] on Thursday, September 20, 2007 at 11:55 am

    [...] zip downloading is attractive and much of this is going on in Flash AS3 with FZip or ASZip AS3 packages. These are made possible with ByteArray and BinarySockets and other fun tools that give [...]

  3. [...] CoreLib’s Jpg & Png encoders), creating pdf’s (AlivePDF) , compress and zip files (ASZip) and work with audio data on the very lowest level (Andre Michelle) and very possibly much [...]

  4. » FlexͿѻ on Tuesday, December 25, 2007 at 5:11 am


  5. Dando la chapa » Blog Archive » onAIR Tour @ London on Thursday, April 10, 2008 at 12:02 am

    [...] Te compilas en un swf la librería AS3 de manejo de zips AS Zip. – Importas el swf como si fuera un archivo JS más: <script src=”lib.swf” [...]

  6. [...] ASZip: Compression de données au format Zip et Gzip [...]