[haxe] Re: Problem : Flash uncompress neko zipped file Java Error #2058解压缩数据时出错。

Hi all,

Second day that i’m stuck with a small problem :

I’m generating a zip file with neko using format.zip lib and load this file to flash : there is no problem here, i can read the not compressed file in the zip
the problem occures when i compress the file, i use format.zip.Tools.compress for that -> no problem
but when i want to uncompress it with the ByteArray.uncompress method TADAAAAAA!!!! It crashes :

An ActionScript error has occurred:
Error: Error #2058: There was an error decompressing the data.
at flash.utils::ByteArray/_uncompress()
at flash.utils::ByteArray/uncompress()
at com.chapatiz.vayu.global::ItemsDictionaryLoader/onItemFileLoaded()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()

Where is my mistake?

Here is my code :
- the neko file maker : http://pastebin.com/LtXvZViB
- the flash class : http://pastebin.com/Bsftn9tN

Thanks you for saving me from craziness.

Cheers,
SUCCESS!!!!!!!!!!!!!!!

After losing of 90% of my hairs, i find the solution.
The format.zip.Tools.compress method delete some of the bytes after the compression :

L59 f.data = data.sub(2,data.length-6);

I made my own compress method without this deletion and all works nice.

Most of the code come from www.haxe.com but the compress/decompress system is not really documented,
I give you my corrected code, I think this can help some people :
- neko : http://pastebin.com/qssGRPVM
- flash : http://pastebin.com/k9B1UeBA

Cheers,

Vincent

import flash.events.EventDispatcher;
import flash.events.Event;
import flash.net.URLRequest;
import flash.net.URLLoaderDataFormat;
import flash.net.URLLoader;
import flash.utils.ByteArray;
import flash.utils.CompressionAlgorithm;
import flash.errors.Error;

import Protocol;

import haxe.io.Bytes;

class ItemsDictionaryLoader extends EventDispatcher
{
var loader:flash.net.URLLoader;
//for stats purpose
var startLoadTime:Float;
var startDecompressTime:Float;
var startUnserializeTime:Float;
var endTime:Float;

public function new()
{
super();
loader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.addEventListener(Event.COMPLETE,onItemFileLoaded);
}
public function loadFile(url:String):Void
{
trace(“loading file…”);
startLoadTime = haxe.Timer.stamp();
loader.load(new URLRequest(url));
}

function onItemFileLoaded2( e : Event ) {
var ba : ByteArray = cast e.target.data;
var input = new haxe.io.BytesInput( Bytes.ofData( ba ) );
var zr = new format.zip.Reader( input );
var data = zr.read();
trace( data.first().data );
}

private function onItemFileLoaded(e:Event):Void
{
loader.removeEventListener(Event.COMPLETE,onItemFileLoaded);
trace(“item file loaded”);
startDecompressTime = haxe.Timer.stamp();
var byteArray:ByteArray = cast(e.target, URLLoader).data;
// Convert the ByteArray into Bytes format
var bytes:Bytes = Bytes.ofData(byteArray);
// Populate the BytesInput stream with our bytes
var bytesInput = new haxe.io.BytesInput(bytes);

// From here on exactly like usage on neko/cpp targets…
var reader = new format.zip.Reader(bytesInput);
var entries:List
= reader.read();
var searchEntryFileName = “it.it”;
var data:String = “”;
for (entry in entries )
{
trace(“entry.fileName : “+entry.fileName+” compressed : “+entry.compressed);
if (entry.fileName == searchEntryFileName)
{
var bytes:Bytes = entry.data;
if(entry.compressed)
{
var byteArray:ByteArray = bytes.getData();
byteArray.uncompress();
bytes = Bytes.ofData(byteArray);
}
data = bytes.toString();
trace(“data : “+data);
}
}

if(data != “”)
{
unserialize(data);
}
else
throw new Error(“No item informations loaded”);

traceTimes();
trace(“it’s a fucKing success!!!!!”);

dispatchEvent(new Event(Event.COMPLETE));

}

private function unserialize(data:String):Void
{
startUnserializeTime=haxe.Timer.stamp();
trace(data.substr(0,300));
var items:List = haxe.Unserializer.run(data);
endTime=haxe.Timer.stamp();
trace(“items.length =”+items.length);
}
/**
* DEBUG PURPOSE
*
* Trace time statistics
*/

private function traceTimes():Void
{
trace(“[Item System Time Stats]*******************************”);
trace(“* loading time : “+(startDecompressTime-startLoadTime));
trace(“* decompress time : “+(startUnserializeTime – startDecompressTime));
trace(“* unserialization : “+(endTime – startUnserializeTime));
trace(“* overall time : “+(endTime – startLoadTime));
trace(“*******************************************************”);
}

}



发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

(Spamcheck Enabled)