Zip loading Error #2058: There was an error decompressing the data

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?

try use “haxe.zip.Reader.unzip()”?

[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? :frowning:

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
    ...

and,you can just pass bytearray to bytes

I’m pretty sure when using format.zip, it resolves to the default haxe.zip library.

from format.zip.Reader

package format.zip;
#if haxe3
typedef Reader = haxe.zip.Reader;
#else
import format.zip.Data;

But I’ll verify tonight.

We have the same problem. Anyon have solution ?

haxe.zip.Reader is too strict when checking some flags. Can you try ZipReader class from https://github.com/restorer/zame-haxe-fileutils ?

We also have a modified version here:

These solutions appear to work only in Neko.

Probably cpp should work either.