HaxeFoundation / hxnodejs

Haxe externs for working with node.js
MIT License
171 stars 63 forks source link

haxe.zip.Reader doesn't work for hxnodejs 6.9.0 + Haxe 3.4.7 #118

Open mikkelmr opened 5 years ago

mikkelmr commented 5 years ago

After updating from 4.0.9 to 6.9.0 the following doesn't compile with Haxe 3.4.7:

haxe.zip.Reader.unzip(null);

It gives the following error:

C:\HaxeToolkit\haxe\std/haxe/zip/Reader.hx:198: characters 10-38 : haxe.zip.Uncompress does not have a constructor

nadako commented 5 years ago

I don't think it ever worked actually, it was a run-time error instead. Good news is that I actually have a somewhat working haxe.zip.Uncompress for nodejs. Now I just need to find some time to finish/clean it up and add to the repo.

package haxe.zip;

import js.node.Buffer;
import js.node.Zlib;

class Uncompress {

    final windowBits:Null<Int>;

    public function new( ?windowBits : Int ) {
        this.windowBits = windowBits;
    }

    public function execute( src : haxe.io.Bytes, srcPos : Int, dst : haxe.io.Bytes, dstPos : Int ) : { done : Bool, read : Int, write : Int } {
        var src = js.node.Buffer.hxFromBytes(src).slice(srcPos);
        var dst = js.node.Buffer.hxFromBytes(dst);
        var res = cast Zlib.inflateRawSync(src, cast {info: true, /* windowBits: windowBits */});
        var engine = res.engine;
        var res:Buffer = res.buffer;
        dst.set(res, dstPos);
        return {done: true, read: engine.bytesRead, write: res.byteLength};
    }

    public function setFlushMode( f : FlushMode ) {
    }

    public function close() {
    }

    public static function run( src : haxe.io.Bytes, ?bufsize : Int ) : haxe.io.Bytes {
        var buffer = js.node.Zlib.inflateSync(js.node.Buffer.hxFromBytes(src),bufsize == null ? {} : {chunkSize : bufsize});
        return buffer.hxToBytes();
    }

}
mikkelmr commented 5 years ago

Well, I'm pretty sure it used to work, since we have working code that uses haxe.zip.Reader.unzip on the nodejs target.

nadako commented 5 years ago

Could it be the case that your zips are not really compressed? Because then it bails out without trying to call new Uncompress():

https://github.com/HaxeFoundation/haxe/blob/39cdd730c4a1dfa629178a631be8e6baaec1441c/std/haxe/zip/Reader.hx#L198

And the default Haxe's implementation of Uncompress just throws in the constructor:

https://github.com/HaxeFoundation/haxe/blob/39cdd730c4a1dfa629178a631be8e6baaec1441c/std/haxe/zip/Uncompress.hx#L27.

Anyway I'll try to fix this soon!

mikkelmr commented 5 years ago

Ahhh, your are spot on, that is actually the case my colleague just told me. Thanks a lot.

We will just stay on 4.0.9 for now.

peteshand commented 5 years ago

Hey @nadako Any plans on releasing this change? It's easy enough to manually update the Compress class, but it's a bit of a pain with build systems