0

我正在 AIR 中创建一个自定义文件类型,它是一个不同扩展名的 zip 文件。我一直在尝试一些库,并选择了 Fzip。这是为了存放我的应用程序项目文件。

测试似乎运行良好,除了偶尔出现“未知记录签名”错误。我想知道我是否遗漏了什么,也许有人可以提供一些启示。我第一次尝试这样的事情。

它似乎是随机发生的,我有一个基本的应用程序,它允许您在运行时添加新文件。内容显示在列表中,选择后您可以查看文本内容。有时在添加新文件、保存然后重新打开时,我会收到此未知记录错误。可能是原因的主要功能

    private function openComplete( event:Event ):void {
        _zipFile.loadBytes( _file.data );
        dispatch( new ZipServiceEvent( ZipServiceEvent.CONTENTS_CHANGE ) );
    }
    public function saveFile( event:Event=null ):void {
        if( _file.isDirectory ) {
            browseForSave();
            return void;
        }
        if ( _file.extension != _ext )
            _file = new File( _file.nativePath + _ext );
        var stream:FileStream = new FileStream();
        stream.open( _file, FileMode.WRITE );
        _zipFile.serialize( stream );
        stream.close();
    }
    public function getFile( name:String ):FZipFile {
        return _zipFile.getFileByName( name );
    }

    public function addFile( name:String, contents:ByteArray ):void {
        _zipFile.addFile( name, contents );
    }
    private function saveFileHandler( event:Event ):void {
        var contents:ByteArray = new ByteArray();
        contents.writeMultiByte( view.filecontents.text, 'utf-8' );
        model.addFile( view.filename.text, contents );
    }
4

1 回答 1

1

I would need to test you class to look for errors… I wont have time to check it but in the meanwhile I´ll post an Util class I created for this purpose. It´s not very extensive, it was just for a small project but it may help you…</p>

package com.models
{
    import com.events.AppEvent;

    import deng.fzip.FZip;

    import flash.events.Event;
    import flash.events.EventDispatcher;
    import flash.events.IEventDispatcher;
    import flash.utils.ByteArray;

    public class ZIPEncoder extends EventDispatcher
    {
        private var _zip:FZip;
        private var _compressedBytes:ByteArray = new ByteArray();

        public function ZIPEncoder(target:IEventDispatcher=null)
        {
            super(target);
        }

        public function newZip(name:String = ""):void
        {
            if(_zip) _zip = null;
            _zip = new FZip();
            _zip.addEventListener(Event.COMPLETE, onZipComplete);
        }

        public function newEntry(name:String, bytes:ByteArray):void
        {
            if(_zip == null)
            {
                throw(new Error("No zipOutput initialized. Call newZip() to initialize a new ZipOutput object before creating entry instances"));
                return;
            }
            _zip.addFile(name, bytes);
        }

        public function compress():void
        {
            _zip.serialize(_compressedBytes, false);
            dispatchEvent(new AppEvent(AppEvent.ZIP_ENCODED, _compressedBytes));
        }

        private function onZipComplete(event:Event):void
        {
            dispatchEvent(new AppEvent(AppEvent.ZIP_ENCODED, _compressedBytes));
        }
        //public function get zip():ZipOutput { return _zip; }
    }
}

hope it helps…</p>

于 2012-07-20T10:37:03.833 回答