Fun with code (since 2006)

ASZip 0.1


08.07.07 Posted in Actionscript 3, ByteArray by

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 Zend.com 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, 'myzip.zip' );
// 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 http://code.google.com/p/aszip/



47 Responses to “ASZip 0.1”

  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. sean says:

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

    thks

  3. Pieter says:

    These projects of yours are truly useful. Great job!

  4. Jérôme says:

    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 ?

  5. Thibault Imbert says:

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

  6. Hey Thibault, this is great. Thanks for sharing!

  7. Pixelmixer says:

    Wow… great stuff :)

  8. Thibault Imbert says:

    Happy you like it guys ! :)

  9. katopz says:

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

  10. !Seve says:

    Thibault, great job!. Thanks for sharing!!

  11. Marcus says:

    Awesome!!! Really great! Thanks for sharing.

  12. Marcus says:

    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.

    Thanks!!!

  13. Thibault Imbert says:

    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 ;)

  14. Marcus says:

    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”

  15. Marcus says:

    … 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. :-)

  16. [...] 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 [...]

     
  17. andiskater says:

    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.

  18. Thibault Imbert says:

    Hi andiskater,

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

    Thanks :)

    Thibault

  19. I can never download half of the stuff you post.

    I always get 404′s all the time.

  20. Thibault Imbert says:

    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 :)

    cheers

  21. Uh oh… dreamhost?

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

  22. Misterniark says:

    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

  23. Thibault Imbert says:

    Hi Misterniak,

    Which unzip program are you using ?
    Thanks you :)

    Thibault

  24. [...] 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 [...]

     
  25. » FlexͿѻ says:

    [...] bytearray.org

     
  26. papa says:

    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!

  27. Thibault Imbert says:

    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,

    Thibault

  28. [...] 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” [...]

     
  29. Rui Cruz says:

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

  30. Sam says:

    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.:(

  31. Maíra says:

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

  32. Maíra says:

    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?

  33. Thibault Imbert says:

    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 :)

  34. Maíra says:

    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.

    thanks!

  35. Marcus says:

    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!

  36. Universe Boy says:

    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 http://www.universemusic.co.uk, 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

  37. g says:

    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.

  38. odon kwon says:

    Hi..Thibault
    It’s good.
    I will using this…
    thanks..

  39. Jordan W says:

    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 – http://www.quixological.com/jordan/ASZipo.as – expects static crc32, use CRC32.as in same folder or change code. Change import for crc32.

  40. P48l0 says:

    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

  41. P48l0 says:

    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.

  42. sasky says:

    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?

  43. Naresh says:

    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

  44. Good API and efficient results, but it would be nice if your library included gzip reading functions.

  45. Andrew says:

    Where does one find the CRC32.as that Jordan uses?

  46. Robbie says:

    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?

Leave a Reply

Open Sort Options

Sort comments by:
  • * Applied after refresh

ByteArray.org
Fun with code since 2006.