问题
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.
回答1:
File.data is only populated after a call to File.load
.
For synchronous loading of bytes, look at FileStream
. These docs give a rundown.
来源:https://stackoverflow.com/questions/10956573/zip-many-files-with-air-as3-flash