压缩许多文件空气AS3闪光 [英] zip many files with Air as3 flash

查看:149
本文介绍了压缩许多文件空气AS3闪光的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

确定。我有理由有能力,但仍然在学习。 这是一个程序,我写的空气。 Basicaly我需要从给定的文件夹抢的混合类型和内容的文件和压缩它们。

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.

下面是code我已经把和排序它的工作原理。 我的问题是,在压缩文件都有零字节的在其中。 Efectivly空。 有什么我错过了还是做错了?

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();

编辑=: 当运行code,我在错误面板注意到这一点。

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?

和它似乎是罚款从我所看到的,但我没写Fzip脚本。

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

推荐答案

<一个href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReference.html#data"相对=nofollow> File.data 中只填入调用 File.load 后。

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

有关字节同步加载,看看的FileStream 这些文档给出一个破败。

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

这篇关于压缩许多文件空气AS3闪光的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆