zip many files with Air as3 flash

会有一股神秘感。 提交于 2020-01-17 04:12:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!