4 Replies Latest reply on Sep 14, 2012 2:46 AM by B4stien

    Exporting package and compressing it as a ZIP in ActionScript

    B4stien Level 1

      Hi everyone,

       

      Our users need to be able to export InDesign packages to our remote web app directly from our InDesign extension. Compressing it to ZIP is probbaly the best option.

      I saw that this question had already been asked and answered for JavaScript (http://forums.adobe.com/message/4243513#4243513). My question is, is there a good zip library for actionscript out there; the few I found haven't been maintained for years. Or is the best option to also use JsZip here? I wish I could use command line tools, but our users work on a large variety of OS and we can't guarantee that they will have the proper tools installed.

       

      Thanks in advance for your help.

      - Bastien

        • 1. Re: Exporting package and compressing it as a ZIP in ActionScript
          lomorgan Adobe Employee

          I can't officially endorse anything, but I've used fzip before (http://codeazur.com.br/lab/fzip/), which now seems to be part of as3commons: http://www.as3commons.org/as3-commons-zip/index.html. From what I remember it worked pretty well. There's some sample code here for archive creation: http://wahlers.com.br/claus/blog/fzip-alpha-release-create-and-modify-zip-archives/, though this was before it moved to as3commons, so I think the class names will have changed slightly.

           

          Hope that helps,

           

          Louis

          • 2. Re: Exporting package and compressing it as a ZIP in ActionScript
            Loic.Aigon Adobe Community Professional

            Hi,

             

            I did zip files once in a applescript by using the shell zip command. I would give the NativeProcess a chance to use the system tool for zipping files. I guess there is a native command in Windows as well. I am soon doing this and this is the lead I will investigate first.

             

            Best,

             

            Loic

            1 person found this helpful
            • 3. Re: Exporting package and compressing it as a ZIP in ActionScript
              Harbs. Level 6

              I've tested a couple of different zip utilities, and FZip worked best.

              1 person found this helpful
              • 4. Re: Exporting package and compressing it as a ZIP in ActionScript
                B4stien Level 1

                Thanks everyone,

                I followed Louis and Harbs' advice and used the fzip (now as3common) library, and it works like a charm. Here's some experimental code I used (obviously it's missing some folder cleaning):

                 

                public class MultiplePagesUploader      { 

                     private var zip:Zip;

                     private var filesToCompress:int = 1;

                     private var filesCompressed:int = 0;

                 

                     ...

                 

                     public function extractPackage(exportFolderPath:String):void{

                          var indDesignApp:Application = InDesign.app;

                          var doc:Document = indDesignApp.activeDocument;

                          var exportFolder:File = File.createTempDirectory();

                          doc.packageForPrint(exportFolder, true, true, true, false, true, false, false);

                          zip = new Zip();

                          addFileToZip(exportFolder, zip);

                     }

                 

                     public function fileAddedToZip():void{

                           filesCompressed++;

                          if (filesToCompress == filesCompressed){

                               var tempDir:File = File.createTempDirectory();

                               var zipFile:File = new File(tempDir.nativePath + "/indd_package_test.zip");

                               var stream:FileStream = new FileStream();

                               stream.open(zipFile, FileMode.WRITE);

                               zip.serialize(stream);

                               stream.close();

                           }

                     }

                 

                     public function addFileToZip(file:File, zip:Zip, path:String=""):void{

                           if(file.isDirectory){

                                var directory:Array = file.getDirectoryListing();

                               filesToCompress = filesToCompress + directory.length;

                               for each (var f:File in directory){

                                     addFileToZip(f, zip, path + "/" + file.name);

                                }

                               fileAddedToZip();

                           }else{

                                file.addEventListener(flash.events.Event.COMPLETE, function():void{

                                     zip.addFile(path + '/' + file.name, file.data);

                                     fileAddedToZip();

                                });

                                file.load();

                           }

                     }

                }

                 

                Someone might find it useful.

                Cheers