简体   繁体   中英

zip many files with Air as3 flash

OK . I am reasonably capable, but still learning. This is for a program I am writing in AIR. Basicaly I am needing to grab the files of mixed type and content from a given folder and zip them.

Here is the code I have put together and it sort of works. Problem I have is that the files in the zip all have zero byte's in them. Efectivly empty. What have I missed or done wrong?

import flash.filesystem.File;
import flash.events.Event;
import deng.fzip.*;

var directory:File = File.desktopDirectory.resolvePath("FOLDER/");

var zip:FZip = new FZip(); 
var files:Array = directory.getDirectoryListing();
for(var i:uint = 0; i < files.length; i++)
{
    zip.addFile(files[i].name, files[i].data);
    trace(files[i].name);
}

var ba:ByteArray = new ByteArray(); 
zip.serialize(ba); 
ba.position = 0; 
var finalZIP:File = File.desktopDirectory.resolvePath("TEST.zip"); 
var fs:FileStream = new FileStream(); 
fs.open(finalZIP, FileMode.WRITE); 
fs.writeBytes(ba); 
fs.close();

EDIT=: While running the code, I have noticed this in the errors panel.

  ....app\scripts_classes\deng\fzip\FZipFile.as, Line 362   Warning: 1106: Empty statement found where block of code expected. Did you type ';'     accidentally?

and it seems to be fine from what I can see, but then I did not write the Fzip script.

File.data is only populated after a call to File.load .

For synchronous loading of bytes, look at FileStream . These docs give a rundown.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM