用到as3 解压缩zip文件.上网找了都是只能解压缩生成bytearray,而不是直接生成文件或目录结构.所以只能自己根据bytearray手动实现..


<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
creationComplete="init()">
<fx:Script>
<![CDATA[
import com.coltware.airxzip.*;
import com.coltware.airxzip.ZipEntry;
import com.coltware.airxzip.ZipError;
import com.coltware.airxzip.ZipFileReader;
import flash.utils.ByteArray;
import flash.utils.setTimeout;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
[Bindable]
private var arrColl:ArrayCollection;
private var outputPath:String;
private var urlVars:URLVariables;
private var downloadFile:File;
private var urlReq:URLRequest;
private const FILE_URL:String = "http://192.168.2.3/david/plugin/oldversion/2.zip";
private var downloadPath:String;
private function init():void
{
downloadFile = new File();
arrColl = new ArrayCollection();
downloadFile = new File();
downloadFile.addEventListener(Event.CANCEL, doEvent);
downloadFile.addEventListener(Event.COMPLETE, doEvent);
downloadFile.addEventListener(Event.SELECT, doEvent);
downloadFile.addEventListener(HTTPStatusEvent.HTTP_STATUS, doEvent);
downloadFile.addEventListener(IOErrorEvent.IO_ERROR, doEvent);
downloadFile.addEventListener(ProgressEvent.PROGRESS, doEvent);
downloadFile.addEventListener(SecurityErrorEvent.SECURITY_ERROR, doEvent);
}
protected function downloadZip(event:MouseEvent):void
{
urlReq = new URLRequest(FILE_URL);
downloadFile.download(urlReq,"indesign.zip");
}
private function doEvent(evt:Event):void {
var fl:File = evt.currentTarget as File;
//trace(evt.type);
switch(evt.type.toLowerCase()){
case "complete":
downloadPath = fl.url;
uncompress();
break;
case "ioerror":
Alert.show("网络地址错误");
return;
break;
}
/* Add event order and type to the DataGrid control. */
arrColl.addItem({data:arrColl.length+1, type:evt.type, eventString:evt.toString()});
try {
/* Update the Model. */
fileRefModel.creationDate = fl.creationDate;
fileRefModel.creator = fl.creator;
fileRefModel.modificationDate = fl.modificationDate;
fileRefModel.name = fl.name;
fileRefModel.path = fl.url;
fileRefModel.size = fl.size;
fileRefModel.type = fl.type;
/* Display the Text control. */
txt.visible = true;
} catch (err:*) {
/* uh oh, an error of sorts. */
}
}
private function showAlert(item:Object):void {
Alert.show(item.eventString, item.type);
}
private function uncompress():void
{
var reader:ZipFileReader = unzip_init(fileRefModel.path);
var list:Array = reader.getEntries();
var file:File = new File();
var path:String = fileRefModel.path as String;
outputPath = path.substr(0, path.indexOf(fileRefModel.name)) + "indesign/";
for each(var entry:ZipEntry in list){
//创建文件
if(entry.isDirectory()){
file.url = outputPath + entry.getFilename();
if(!file.exists)
file.createDirectory();
//trace("DIR  --->" + entry.getFilename());
}
else{
var bytes:ByteArray = reader.unzip(entry);
file.url = outputPath + entry.getFilename();
file.resolvePath(outputPath + entry.getFilename());
var fileStream:FileStream = new FileStream();
fileStream.open(file, FileMode.WRITE);
fileStream.writeBytes(bytes);
fileStream.close();
}
}
reader.close();//关闭字节流。否则无法删除zip
openIndesign();
setTimeout(delZip,1000);
}
//删除 zip文件
private function delZip():void
{
var zipFile:File = new File(fileRefModel.path);
zipFile.deleteFile();
}
private function openIndesign():void
{
var file:File = new File();
file.url = outputPath + "2/demo/staticImage.html";
file.openWithDefaultApplication();
}
private  function unzip_init(filepath:String):ZipFileReader{
var reader:ZipFileReader = new ZipFileReader();
var file:File = new File(filepath);
reader.open(file);
return reader;
}
]]>
</fx:Script>
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
<fx:Model id="fileRefModel">
<file>
<creationDate>{""}</creationDate>
<creator>{""}</creator>
<modificationDate>{""}</modificationDate>
<name>{""}</name>
<path>{""}</path>
<size>{""}</size>
<type>{""}</type>
</file>
</fx:Model>
</fx:Declarations>
<s:VGroup>
<s:Button id="downloadBtn" label="download" click="downloadZip(event)" toolTip="预览"/>
<mx:DataGrid id="debug" dataProvider="{arrColl}" width="{downloadBtn.width}" rowCount="5" rowHeight="22" itemClick="showAlert(event.currentTarget.selectedItem)">
<mx:columns>
<mx:DataGridColumn dataField="data" headerText="#" width="20" />
<mx:DataGridColumn dataField="type" headerText="Type" showDataTips="true" dataTipField="eventString" />
</mx:columns>
</mx:DataGrid>
<mx:Text id="txt" condenseWhite="true" visible="false">
<mx:text>
creationDate: {fileRefModel.creationDate}
creator: {fileRefModel.creator}
modificationDate: {fileRefModel.modificationDate}
name: {fileRefModel.name}
path: {fileRefModel.path}
size: {fileRefModel.size}
type: {fileRefModel.type}
</mx:text>
</mx:Text>
</s:VGroup>
</s:WindowedApplication>

[转]
在现在开发的游戏中,由于战斗数据比较大,所以尝试对战斗数据进行压缩,然后输出到客户端flash端再解压。

Google到一篇文章,对照翻译工具翻译一下

在我的一些项目中,经常需要对数据做一些转换操作,所以积累一些很有意思的用于数据压缩/解压缩的第三方类库。

当然ByteArray类本身就带了数据压缩和解压缩的方法,可以用在flash player使用zlib算法和AIR程序使用多种算法。在FLASH跟PHP作为后台的编程中,我后来选择了ByteArray的compress方法来做zlib算法的压缩,用这个方法用的比较顺手,而且很快。

下面是一些第三方的类库地址以及介绍:

AS3 Zip: AS 3 下用来读取和写入zip文件的类库
    FZip: FZip 是一个用于AS 3 下读取、创建、修改zip压缩包的类库
    ASZip: AS 3 用于创建zip文件的类库
    LZMA Encoder: AS3下使用LZMA算法压缩数据的类库.
    LZMA Decoder: 跟上面类库对应的用于LZMA算法解压缩数据.
    AsCompress: AS3下 GZIP压缩和解压缩类库,好像需要SDK版本在4.x以上,flash cs3下不可用。
    Gzip for HTTPService/URLLoader: 给你的 Flex/AIR HTTPService/URLLoader增加gzip支持
    airxzip: AIR的zip类库

如果你还知道更多的类库或者其他好东东,欢迎告知!

翻译自:http://blog.yoz.sk/2011/01/quick-tip-compression-in-flash/

While working on one of my projects where I needed compression for transfered data, I hit some very interesting compression libraries. Also the ByteArray class contains compress method, using zlib algorithm in flash player or multiple algorithms in AIR. At the end I decided to useByteArray.compress() method for encoding vs. PHP gzuncompress for decoding, what works correctly, fast and smooth.

Here is a list of 3rd party compression libraries and other good stuff:

AS3 Zip: ActionScript 3 based library for reading and writing zip files
    FZip: FZip is an Actionscript 3 class library to load, modify and create standard ZIP archives.
    ASZip: ActionScript 3 library to generate ZIP files
    LZMA Encoder: AS3 class to compress data using LZMA algorithm.
    LZMA Decoder: A part of the apparat framework.
    GZIP: ActionScript GZIP compression library
    Gzip for HTTPService/URLLoader: Adding Gzip support for Flex/AIR HTTPService/URLLoader
    airxzip: Zip library for ActionScript3 on AIR

If you know some more, please let me know.

from: http://www.cnblogs.com/rob0121/articles/2300556.html

as3压缩解压缩的第三方包及实现DEMO相关推荐

  1. AS3的一些压缩解压缩类库(AS3 ZIP、AS3 GZIP等等)

    原文链接:AS3的一些压缩解压缩类库(AS3 ZIP.AS3 GZIP等等) 在现在开发的游戏中,由于战斗数据比较大,所以尝试对战斗数据进行压缩,然后输出到客户端flash端再解压. Google到一 ...

  2. Java 压缩解压缩 第三方组件,推荐一个强大的Java开发工具类库!

    feilong开发更简便的工具库 Reduce development, Release ideas (灵感从重复简单的代码中释放出来) 让你从大量重复的底层代码中脱身,提高工作效率; 让你的代码更简 ...

  3. linux命令(五)--打/解包、压缩/解压缩、安装软件

    文章目录 1.打包/解包 2.压缩/解压缩 3.软件安装 1.打包/解包 tar是linux中最常用的备份工具,此命令可以把一系列文件打包到一个大文件中,也可以把一个打包的大文件恢复成一系列文件 ta ...

  4. java ant解压缩_java ant包中的org.apache.tools.zip实现压缩和解压缩实例详解

    java ant包中的org.apache.tools.zip实现压缩和解压缩实例详解 发布于 2020-4-7| 复制链接 摘记: java ant包中的org.apache.tools.zip实现 ...

  5. 【SpringBoot】ZIP包 压缩解压缩

    ZIP包 压缩&&解压缩 ZIP包 压缩&&解压缩 ZIP包 压缩&&解压缩 压缩:第一种方法,压缩不支持文件夹压缩,需要指定待压缩的所有文件路径. 压 ...

  6. python安装第三方包_python 怎么安装第三方包

    使用Pip工具进行第三方包安装 Pip工具是Pytho自带的第三包安装工具,在pytho安装过程中已经安装完成,无需独立安装,附上python第三方安装包地址:https://pypi.python. ...

  7. Linux压缩/解压缩

    整合资源,仅供自己参考:) TAR 命令名 tar - tar 档案文件管理程序的 GNU 版本.下面将逐个介绍其含义 总览 tar [ - ] A --catenate --concatenate ...

  8. python第三方包安装方法(两种方法)

    具体有以下两种方法: 第一种方法(不使用pip或者easy_install): Step1:在网上找到的需要的包,下载下来.eg. rsa-3.1.4.tar.gz Step2:解压缩该文件. Ste ...

  9. python 第三方包自动导入_7行代码,彻底告别python第三方包import导入问题!

    最近有不少小伙伴咨询关于pyton第三方包导入的问题,今天我们就来聊聊第三方包导入那些事. 随着对python学习的渐入臻境,越来越多的小伙伴们开始导入自己所需的第三方包,实现各种各样的功能.但是,他 ...

最新文章

  1. python不能处理excel文件-python处理excel文件(xls和xlsx)
  2. 使用python写一个名片管理系统
  3. 「Android」 详细全面的基于vue2.0Weex接入过程(Android视角)
  4. All CUDA devices are used for display and cannot be used while debugging.
  5. map分组后取前10个_海关数据 | 图解前10个月外贸
  6. ubuntu配置安装KBEngine服务器
  7. 在Linux系统下更改或更新SSH密钥密码的方法
  8. 凸优化第二章凸集 2.6对偶锥与广义不等式
  9. android获取手机短信记录,Android开发获取短信的内容并截取短信
  10. 信息检索与利用(第三版)第二章信息资源与信息源
  11. 解读 TiDB Server
  12. 软件构件技术期末复习
  13. SQL server如何自定义服务器名称登陆
  14. Oracle 10g 在win10下的安装
  15. Sunday算法java实现
  16. 厉害了!你的技术真的到天花板了吗?年薪50W
  17. 图解+原理推导完全读懂KPM算法
  18. 统计建模与R软件-附R原程序
  19. Unity3D 200个插件免费分享
  20. Vscode软件,如何启动vue项目

热门文章

  1. 经典查找算法 --- B+树
  2. uc浏览器设置里面的的浏览器ua是什么意思
  3. 2K薪酬收微博评论自动点赞码源 有能力的大佬加Q 9596702
  4. windows下,配置apache2.4.39执行typhon生成的cgi程序
  5. 整理学习之深度迁移学习
  6. linux rm、rm -f、rm -r的区别
  7. 联盟:微信封号最新规则以及解决方法
  8. JAVA学习代码——验证手机号码是否正确
  9. java 怎么写异步方法_java如何学习异步编程?
  10. Aria2一键安装及管理脚本,搭建AriaNg前端