Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
489 views
in Technique[技术] by (71.8m points)

actionscript 3 - Unzip and save files using as3?

I have a list of zip and rar files in a local folder.
All I need to do is to extract the contents of the zip as well as rar files and to save them in a folder with the same name of the respective archive file.
Since I am new to as3, I have no clue for this.
Is there any Library for this???




Thanks in advance...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To decompress zip files, you can use AS3Commons Zip (formerly know as FZip). It works without the Adler32 checksum requirement mentionned in a previous answer.

Here's an example of how to extract all files in a zip archive. The function below would be called when a URLLoader object has downloaded the zip file and dispatched an Event.COMPLETE event:

import org.as3commons.zip.Zip;
import org.as3commons.zip.ZipFile;

private function _onZipDownloaded(e:Event):void {

    var ba:ByteArray = ByteArray(e.target.data);
    var zip:Zip = new Zip();
    zip.loadBytes(ba);

    for(var i:uint = 0; i < zip.getFileCount(); i++) {

        var zipFile:ZipFile = zip.getFileAt(i);
        var extracted:File = directory.resolvePath(zipFile.filename);

        var fs:FileStream = new FileStream();
        fs.open(extracted, FileMode.WRITE);
        fs.writeBytes(zipFile.content);
        fs.close();

    }

}

Obviously, error checking should be added to the code above but you get the idea...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...