I’m trying to load a zip file from the web via an urlloader. The zip contains .pngs and .txts.
/**
* External zip file is loaded
* @param {Event.COMPLETE} e
*/
private function onLoadComplete(e:Event):Void {
var byteArray:ByteArray = cast(e.target, URLLoader).data;
var bytes:Bytes = Bytes.ofData(byteArray);
var bytesInput = new haxe.io.BytesInput(bytes);
var reader = new format.zip.Reader(bytesInput);
var entries:List<format.zip.Data.Entry> = reader.read();
for(entry in entries) {
trace(entry.fileName + " Loaded")
var uncompressedBytes:Bytes = haxe.zip.Uncompress(entry.data); // fails
...
entery.fileName traces fine. Entry claims to be compressed, but uncompressing the Bytes always gives me Error #2058: There was an error decompressing the data. Converting bytes to bytearray and using bytearray,uncompress() fails too - same error. What am I missing?
[Fault] exception, information=Not implemented for this platform
I’ve tried Uncompress.run() as well. It appears that uncompressing zip entries isn’t available on anything but neko target?
Edit:
As a note, calling haxe.zip.Reader.unzip(entry)…
public static function unzip( f : Entry ) {
if( !f.compressed )
return f.data;
var c = new haxe.zip.Uncompress(-15);
var s = haxe.io.Bytes.alloc(f.fileSize);
var r = c.execute(f.data,0,s,0);
c.close();
if( !r.done || r.read != f.data.length || r.write != f.fileSize )
throw "Invalid compressed data for "+f.fileName;
… ends there and throws that error.
At the moment I can only parse zips using no compression. Anyone have a working unzipper for flash target?
Can you try change reader and entry to haxe default zip library?
private function onLoadComplete(e:Event):Void {
var byteArray:ByteArray = cast(e.target, URLLoader).data;
var bytes:Bytes = byteArray;
var bytesInput = new haxe.io.BytesInput(bytes);
var reader = new haxe.zip.Reader(bytesInput);
var entries:List<haxe.zip.Entry> = reader.read();
for(entry in entries) {
trace(entry.fileName + " Loaded")
var uncompressedBytes:Bytes = haxe.zip.Reader.unzip(entry); // fails
...