hxnodejs icon indicating copy to clipboard operation
hxnodejs copied to clipboard

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

Open mikkelmr opened this issue 6 years ago • 5 comments

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

mikkelmr avatar Mar 13 '19 15:03 mikkelmr

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();
	}

}

nadako avatar Mar 13 '19 16:03 nadako

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

mikkelmr avatar Mar 14 '19 07:03 mikkelmr

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!

nadako avatar Mar 14 '19 07:03 nadako

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.

mikkelmr avatar Mar 14 '19 09:03 mikkelmr

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

peteshand avatar Sep 25 '19 02:09 peteshand