AIRアプリでZIPファイルを解凍してみる[お仕事]
(2010-12-09 09:53:44) by shinoda


< ページ移動: 1 2 >

<画像:20101208_as1.jpg>

ActionScriptの標準ライブラリではZIPファイルの解凍機能は提供されていないので、自分で作るか、他人様が作成されて公開されているものを使うしかない。

勉強がてら作ってみるのは面白いのだが、今回の仕事はそういうライブラリが存在していることを前提に作業工数を見積もっているので、

FZip - http://codeazur.com.br/lab/fzip/

という、フリーのライブラリを使ってみた。(商用利用も問題なさげ)

日本語のドキュメントがほとんど存在していないため、英語のサンプルソースを見てどうにかするしかなかったので少し時間がかかったが、例えば任意のZIPファイルを解凍するだけなら以下のようなソースになる。


<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
    initialize="initProc()"
    layout="absolute" width="480" height="208">
    <mx:Label x="183" y="18" text="ZIP解凍 テスト" fontSize="18" id="Title"/>
    <mx:TextArea x="23" y="54" width="428" height="122" id="Message"/>

    <mx:Script>
    <![CDATA[

    import deng.fzip.FZip;    // ZIP操作ライブラリ
    import flash.events.*; 
    import flash.net.URLRequest;

    public var Fzip:FZip;
    public var ZipFileName:String    = "data/cont/ds.zip";
    public var ZipDirName:String    = "data/cont/ds/";

    private function initProc():void {

        Fzip = new FZip();

        var request:URLRequest = new URLRequest();
        var file:File = File.applicationStorageDirectory.resolvePath(ZipFileName);
        request.url = file.nativePath;

        Message.text    += "FN=" + file.nativePath + "\n";

        Fzip.addEventListener(Event.COMPLETE, loadComplete);
        Fzip.addEventListener(IOErrorEvent.IO_ERROR, onIOError);

        Fzip.load(request);
 
    }
 
    public function loadComplete(evt:Event):void {

        var file:File;
        var stream:FileStream;

        for(var i:int=0; i < Fzip.getFileCount(); i++){

            Message.text    += Fzip.getFileAt(i).filename + "\n";

            file = File.applicationStorageDirectory.resolvePath(ZipDirName + Fzip.getFileAt(i).filename);       
            stream    = new FileStream();
            try {
                stream.open(file,FileMode.WRITE);
                stream.writeBytes(Fzip.getFileAt(i).content);

< ページ移動: 1 2 >


コメント投稿
次の記事へ >
< 前の記事へ
TOPへ戻る

Powered by
MT4i 3.0.8