Adobe AIR:解压Zip

博客分享了一段在Adobe AIR中解压ZIP文件的代码。介绍了ZipFile类构造函数以IDataStream对象为参数,可使用包含ZIP文件数据的ByteArray或FileStream对象,还说明了通过相关属性和方法获取文件数据等内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

下面是一段在Adobe air中解压zip的代码,是从一个老外的博客中转来的:

Today, I'm going to show you how you can use the nochump library to extract zip files with Adobe AIR.

The ZipFile class constructor takes an IDataStream object as the parameter.Here you can use a ByteArray or a FileStream object which contains the data of the zip file. The entries property of the ZipFile object contains all the files in the archive as ZipEntry objects. Here the directory itself(excluding the files inside it) also counts as a ZipEntry object, so make sure to check using the isDirectory property of the ZipEntry object. Finally get the data of a single file using zipFile.getInput() method.

Here's the code :

   import flash.filesystem.*;
   import flash.net.FileFilter;
   
   import nochump.util.zip.*;
   
   private var zipInput:File = new File();
   private var zipOutput:File = new File();
   private var zipFile:ZipFile;
   
   private function loadZIP():void
   {
    var filter:FileFilter = new FileFilter("ZIP","*.zip");
    zipInput.browseForOpen("Open ZIP file",[filter]);
    zipInput.addEventListener(Event.SELECT, onSelect);
   }
   
   private function onSelect(e:Event):void
   {
    var stream:FileStream = new FileStream();
    stream.open(zipInput,FileMode.READ);
    
    zipFile = new ZipFile(stream);
    extract.enabled = true;
   }
   
   private function extractZIP():void
   {
    zipOutput.browseForDirectory("Select Directory for extract");
    zipOutput.addEventListener(Event.SELECT, onDirSelect);
   }
   
   private function onDirSelect(e:Event):void
   {
    for(var i:uint = 0; i < zipFile.entries.length; i++)
    {
     var zipEntry:ZipEntry = zipFile.entries[i] as ZipEntry;
     // The class considers the folder itself (without the contents) as a ZipEntry.
     // So the code creates the subdirectories as expected.
     if(!zipEntry.isDirectory())
     {
      var targetDir:File = e.target as File;
      var entryFile:File = new File();
      entryFile = targetDir.resolvePath(zipEntry.name);
      var entry:FileStream = new FileStream();
      entry.open(entryFile, FileMode.WRITE);
      entry.writeBytes(zipFile.getInput(zipEntry));
      entry.close();
     }
    }
   }


You can download the project archive here. Happy experimenting

 

from: http://pradeek.blogspot.com/2009/05/extracting-zip-files-in-adobe-air-with.html

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值