Following up on my previous post, here's how to archive a bunch of files and make a zip file.
After getting all the files you want to put in the archive, create a new ZipEntry object for each file and add it to a ZipOutput object using the putNextEntry() of the ZipOutput class. Then pass the ByteArray data of the file to the write() method of the ZipOutput class and close the entry by using the closeEntry() method. Finally, call the finish() method once you have done the same for all the files.
Here's the code snippet :
import flash.events.FileListEvent;
import flash.filesystem.*;
import nochump.util.zip.*;
private var zipInput:File = new File();
private var zipOutput:File = new File();
private var zipFile:ZipOutput;
private var files:Array = new Array();
private function loadFiles():void
{
zipInput.browseForOpenMultiple("Open ZIP file");
zipInput.addEventListener(FileListEvent.SELECT_MULTIPLE, onSelect);
}
private function onSelect(e:FileListEvent):void
{
for(var i:uint = 0;i < e.files.length;i++)
{
var stream:FileStream = new FileStream();
var f:File = e.files[i] as File;
stream.open(f,FileMode.READ);
var fileData:ByteArray = new ByteArray();
stream.readBytes(fileData);
var file:Object = new Object();
file.name = f.name;
file.data = fileData;
files.push(file);
}
}
private function createZIP():void
{
zipFile = new ZipOutput();
for(var i:uint = 0; i < files.length; i++)
{
var zipEntry:ZipEntry = new ZipEntry(files[i].name);
zipFile.putNextEntry(zipEntry);
zipFile.write(files[i].data);
zipFile.closeEntry();
}
zipFile.finish();
zipOutput.browseForSave("Select target directory");
zipOutput.addEventListener(Event.SELECT, onSave);
}
private function onSave(e:Event):void
{
var archiveFile:File = e.target as File;
if(!archiveFile.exists)
{
var stream:FileStream = new FileStream();
stream.open(archiveFile,FileMode.WRITE);
stream.writeBytes(zipFile.byteArray);
stream.close();
}
}
As usual you can download the project archive here. Happy experimenting.
from: http://pradeek.blogspot.com/2009/05/creating-zip-files-with-adobe-air-with.html#comments
代码中提到的nochump lib见附件。
其主页如下:
http://nochump.com/blog/?index.html
友情提示:博客地址如果打不开,请FQ。◕‿◕
分享到:
相关推荐
目前已实现Windows, Mac三大平台的支持,采用Adobe Air开发,采用MIT协议发布,代码托管在github上面。 主要特色: 多文件Hosts方案管理 单Hosts文件中分组管理 绑定到机器名或域名...
使用要求:Adobe AIR虚拟机 v1.1或以上 下载地址:http://get.adobe.com/cn/air/ AIR版文档中心下载: http://www.ajaxjs.com/docs/Ext 2 API Documentation.zip ~3MB 用法:直接打开2.1 API Documentation.exe
把文件AdobeAIR3_0.xml放在 C:\Program Files (x86)\Adobe\Adobe Flash CS5.5\Common\Configuration\Players\ 另外需要 拷贝airglobal.swc 到 C:\Program Files (x86)\Adobe\Adobe Flash CS5.5\Common\...
微博AIR是基于Adobe AIR平台的新浪微博桌面客户端 【使用方法】 第一步:安装 Adobe AIR 运行环境(已安装的用户请跳过)http://down.chinaz.com/soft/29198.htm 第二步:安装 微博AIR (1.51) 客户端(解压后...
air-ane-fullscreen, 在Android上,为 Adobe AIR启用 true 全屏支持 全屏显示,适用于 Adobe AIRa的一个最常见的抱怨是,他们无法获得 true 全屏屏幕上的屏幕导航栏( 。包含背面,家庭和任务按钮的按钮) 。如果你是...
Mac 下 图片标注工具,非常方便,体验版能满足临时需求。注意安装markman前先安装Adobe AIR
SinaTair新浪微博桌面客户端(微博air客户端)基于air平台的微博桌面客户端...A5源码友情提示:sinatair是一款基于Adobe AIR环境下的客户端软件,需要Adobe AIR环境支持,如果您未安装AIR环境请下点击下载安装:Adobe AIR
Adobe AIR功能 基于Flash 或 Flex:应用程序根内容(理解为容器)为Flash/Flex (SWF)。 基于HTML,应用程序根内容为HTML, JS, CSS。 基于HTML的Flash/Flex或PDF,应用程序根内容为基于HTML 的Flash/Flex (SWF) ...
AdobeAIRInstaller.zip AdobeAIRInstaller.zip AdobeAIRInstaller.zip
1. 下载Adobe官方的runtime installer ...2.解压缩zip文件,把你的安装程序放到根目录下。在根目录里新建名为 .airinstall.cfg 的文件。内容是你安装程序的名字,如MyApp.air 3. 用winRar 制作自解压文件
AdColony AIR本机扩展修改时间:2021/02/11 Android SDK版本:4.4.1 iOS SDK版本:4.5.0 本机扩展版本:4.4.0概述AdColony提供零缓冲, ,和Aurora:trade_mark:可播放广告,它们可以显示在应用程序中的任何位置。...
restfulx_framework, 开发 Adobe Flex和AIR应用程序的RESTful方法 RestfulX框架:开发 Adobe Flex和AIR应用程序的RESTful方法描述下面是你可以使用RestfulX做的一些事情:在不到 5分钟的时间内,创建完整的Adobe ...
设备指挥官(DevCDR) ...自动更新: 7-Zip,AdobeAir,AdobeReader DC,AdobeReader DC MUI,代码,FileZilla,Firefox,FlashPlayerPlugin,FlashPlayerPPAPI,GIMP,Google Chrome,JavaRuntime8
这个API是一个AIR文件,必须先安装 ADOBE AIR 才能用。 http://sttele1.skycn.com/down/AdobeAIRInstaller.zip 详细安装方法,看我的博客 http://hi.baidu.com/w2y0xy0sf5z/blog/item/d524bf8b835d911ac8fc7aef.html
1、首先确定电脑安装了Adobe Air软件(点这里可以下载Adobe Air) 2、然后解压缩下载的软件 3、双击文件“DesktopiPhone.air”进行安装 4、软件会自动在桌面上创建快捷方式,点击进入后即可使用。
是zip压缩格式,解压缩,得到doc文件夹,大部分文件都在langref子目录里,我们需要的是把这些html文件替换为官方已经翻译好的html文件,重新打包就可以了。 2.接下来就是把官方的对应html文件下载过来了。chm文件...
X64安装Adobeair必备 rebuild_db-1.0-rc1.zip
1、地图编辑器; 2、purMVC示例,有封装和重写,方便管理; 3、MornUI示例; 4、资源管理; 5、自定义事件,有优化处理,提高效率;...6、Adobe Air的本地资源处理; 7、JSON输入输出解码配置文件;
Flash课程作业.zip,个人课程做的一个小作品,需要在Flash CS4和以上版本才能打开。感觉Flash已经过时了,即使是Adobe air也挽救AS3.0脚本的颓势。即使过时的技术也要教,大学的课程确实很无奈