使用fzip压缩文件夹 [英] zip a folder using fzip

查看:519
本文介绍了使用fzip压缩文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想COM preSS文件夹到一个.zip文件。我使用的FZip库。这是我到目前为止有:

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

我的桌面上的文件夹test是我想要的文件夹COM preSS。

The folder test on my desktop is the folder i want to compress.

现在我想压缩该文件夹,并把我的桌面上的zip文件,但他们谈论的ByteArray等,我不知道如何做到这一点。 有人可以帮我吗?在此输入链接的描述

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

推荐答案

在这里是一个工作的例子,使之短我用了大量的匿名函数。

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

}

这篇关于使用fzip压缩文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆