new zip code?

82 views
Skip to first unread message

tom rhodes

unread,
Apr 3, 2014, 6:34:35 PM4/3/14
to haxe...@googlegroups.com
Hi,

I'm having problems reading the compressed data from a haxe.zip.Entry created from a haxe.zip.Reader instance. 

In JS i'm getting the data like this...

var reader = new FileReader();
reader.onload = fileRead;
reader.readAsDataURL(file);

...then I'm reading it like this...

function fileRead(e:Event)
{
var reader:FileReader = cast e.target;
var zipDataURLParts = reader.result.split(",");
var zipData = Base64.decode(zipDataURLParts[1]);
var zipBytesInput = new BytesInput(zipData);
var zipReader = new Reader(zipBytesInput);
var entries = zipReader.read();
for(entry in entries)
{
var inflatedData = Uncompress.run(entry.data);
}
}

...which kinda works in that the zip file is read by teh reader, it blows up at the Uncompress line though giving this error...

  1. Uncaught Invalid data email-app.js:4559
    1. haxe.zip.InflateImpl.inflateLoopemail-app.js:4559
    2. haxe.zip.InflateImpl.readBytesemail-app.js:4451
    3. haxe.zip.InflateImpl.runemail-app.js:4429
    4. haxe.zip.Uncompress.run

...I'm close I think as I can go through the entries ok, happily tracing out filenames, dataSize everything apart from inflating the data :(

Anybody see where I'm going wrong?

Thanks,

Tom.

tom rhodes

unread,
Apr 4, 2014, 3:18:20 AM4/4/14
to haxe...@googlegroups.com
Anyone?

This code fails on JS and Neko, I've opened the zips fine on Ubuntu, Windows 7/8.1 and OS X 10.6 in a virtual machine. So I'm pretty sure the zips are fine.

David Elahee

unread,
Apr 4, 2014, 3:21:37 AM4/4/14
to haxe...@googlegroups.com
@ncannasse is the only one to be able to help you on this one.


--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.



--
David Elahee


tom rhodes

unread,
Apr 4, 2014, 3:41:17 AM4/4/14
to haxe...@googlegroups.com
Aha! Ok, so is this new in 3.1.2? 

Which version still has a working haxe.zip.Tools.uncompress method?

Thanks for responding David :)

David Elahee

unread,
Apr 4, 2014, 3:49:20 AM4/4/14
to haxe...@googlegroups.com
Indeed it is a new thing that was triggered by trying to fix something that wasn't very documented...

here is the code i use nowaday to unzip (use at your own risk) : 

public static function inflate(src : haxe.io.Bytes, bufsize : Int ) {
#if cpp
var zl = new haxe.zip.Uncompress( -15);
zl.setFlushMode(haxe.zip.FlushMode.SYNC);
var b = haxe.io.Bytes.alloc(bufsize);
var readpos = 0;
var writepos = 0;
var t = zl.execute(src, readpos, b , writepos);
if (!t.done) throw "you should wait a final fix or prepare a buffer with right size.";
zl.close();
return b;
#elseif flash
var b = haxe.io.Bytes.alloc(bufsize);
b.blit( 0, src, 0, src.length);
var data = b.getData();
data.position = 0;
data.inflate();
data.position = 0;
return b;
#else
//might not allways work
return haxe.zip.Uncompress.run(src, bufsize);
#end
}

tom rhodes

unread,
Apr 4, 2014, 4:03:42 AM4/4/14
to haxe...@googlegroups.com
Thanks David,

I need JS and neko for this project, should I go back to 3.0? If not, no worries I'll just have to not use zips... 

David Elahee

unread,
Apr 4, 2014, 4:10:27 AM4/4/14
to haxe...@googlegroups.com
Can't help no more,sry :)

tom rhodes

unread,
Apr 4, 2014, 4:12:05 AM4/4/14
to haxe...@googlegroups.com
no worries :)
Reply all
Reply to author
Forward
0 new messages