开发者

Zipping and Unzipping files in Adobe Air/Javascript

I'm not particularly开发者_开发知识库 using Flex but I am using javascript and html and css in a adobe air application. I would like to be able to unzip and zip files. I've looked at a few libraries but none worked as I needed it to. I read somewhere that I could use Fzip library but I need to do this in javascript most preferably but the files are actionscript files. Any advice? Thanks.


You can use almost any actionscript library with html/javascript air app. Example:

  1. Download swc file for airxzip: http://code.google.com/p/airxzip/downloads/list
  2. Rename swc to zip and unzip it
  3. Rename included library.swf to coltware_airxzip.swf
  4. Include the library on your page like this:

<script src="coltware_airxzip.swf" type="application/x-shockwave-flash"></script>

This reads a zip file and writes contents to output folder on the desktop (given you have included jQuery and the AIRAliases.js file from the SDK):

var input = new air.File();
input.addEventListener(air.Event.SELECT, function(event) {
    var outputDirectory = air.File.desktopDirectory.resolvePath('output');
    var reader = new window.runtime.com.coltware.airxzip.ZipFileReader();
    reader.open(event.currentTarget);
    $.each(reader.getEntries(), function(i, entry) {
        if (!entry.isDirectory()) {
            var stream = new air.FileStream();
            stream.open(outputDirectory.resolvePath(entry.getFilename()), air.FileMode.WRITE);
            stream.writeBytes(reader.unzip(entry));
            stream.close();
        }
    });
});
input.browseForOpen('Select a zip file...', [new air.FileFilter('Zip files', '*.zip')]);


I wrote a sample app for Adobe Air + FZip using javascript.

Figured I'd share that here in case anyone else arrives here via Google.

Can never have too many working examples right?

Example -> http://www.drybydesign.com/?p=233

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜