Unzip and save files using as3?

后端 未结 2 1491
梦毁少年i
梦毁少年i 2020-12-06 19:11

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 s

2条回答
  •  無奈伤痛
    2020-12-06 19:38

    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...

提交回复
热议问题