Because a zip file permits a number of compression algorithms so a ZIP file contains one or more files. FZip is a cute little Actionscript 3 class library, it parses ZIP archives progressively, allowing access to contained files while the archive is loading(@see Actionscript 3 class zip library–FZip).

Now we will introduce an other actionscript zip library: ASZip.  You can generate ZIP files from ActionScript 3 with ASZip. ASZip uses the native gzip (Deflate) compression from the flash.utils.Bytearray.compress() method. More compression algorithms will be added in the future. ASZip has simple interface to add different types of files and directories.

ASZip-ActionScript-3-library

The following is a simple sample to generate a text file and PNG file to a zip file:

  1. // create the Zip file, first param : compression method
  2. var myZip:ASZip = new ASZip (CompressionMethod.GZIP);
  3. // create a flash.display.BitmapData
  4. var myStevie:Stevie = new Stevie (0, 0);
  5. // encode it as a PNG
  6. var bytes:ByteArray = PNGEnc.encode (myStevie);
  7. // create a text stream
  8. var txt:ByteArray = new ByteArray();
  9. // write some text into it
  10. txt.writeUTFBytes("Hello there !!");
  11. // add a pics folder
  12. myZip.addDirectory ("pics/");
  13. // then a text folder
  14. myZip.addDirectory ("text/");
  15. // pass the PNG stream and specify a file name and location
  16. myZip.addFile (bytes, "pics/stevie.png");
  17. // pass the text stream and specify a file name and location
  18. myZip.addFile (txt, "text/story.txt");
  19. // add a comment
  20. myZip.addComment ("A comment !");
  21. // generate final Zip file
  22. var myZipFile:ByteArray = myZip.saveZIP ( Method.LOCAL );

You can download the source from: http://code.google.com/p/aszip/downloads/list

 

For help, advice, tips and tricks, challenges, feel free to visit ourDoNotYet forum or Submit your good resource to share.

Reminder: Unless stated otherwise, all resources published on this site are NOT for commercial use. To use any resource from this site for commercial purposes, please contact the author.

Related Posts