Reputation: 1313
I am trying to compress a folder into a .zip file. I'm using the FZip library. This is what i have so far:
var zip:FZip = new FZip();
zip.addFile("Users/Vincent/Desktop/test/", null);
The folder test on my desktop is the folder i want to compress.
Now i would like to zip that folder and place the zip file on my desktop but they are talking about byteArrays etc. and i have no idea how to do this. Can someone please help me?enter link description here
Upvotes: 1
Views: 1925
Reputation: 4216
here is a working example, to make it short I used a lot of anonymous functions.
package {
import deng.fzip.FZip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.net.FileReference;
import flash.net.FileReferenceList;
import flash.utils.ByteArray;
public class ZipTest extends Sprite {
private var imageRefList : FileReferenceList = new FileReferenceList();
private var saveRef : FileReference = new FileReference();
private var zipName : String = "someName.zip";
public function ZipTest() {
var someButton : Sprite = new Sprite();
with(someButton.graphics) {
beginFill(0x00ff00);
drawRect(0, 0, 50, 50);
endFill();
}
addChild(someButton).addEventListener(MouseEvent.CLICK, function(event : MouseEvent) : void {
var saveZip : Function = function(zip : FZip) : void {
var out : ByteArray = new ByteArray();
zip.serialize(out);
saveRef.addEventListener(Event.COMPLETE, function(e : Event) : void {
trace("done");
});
saveRef.save(out, zipName);
};
imageRefList.addEventListener(Event.SELECT, function(e : Event) : void {
var zip : FZip = new FZip();
var count : int = imageRefList.fileList.length;
for each (var image: FileReference in imageRefList.fileList) {
image.addEventListener(Event.COMPLETE, function(e : Event) : void {
var img : FileReference = FileReference(e.target);
trace(count + " loaded... " + img.name);
zip.addFile(img.name, img.data);
count--;
if (count == 0) saveZip(zip);
});
trace("load: " + image.name);
image.load();
}
});
imageRefList.browse();
});
}
}
}
Upvotes: 1