Skip to content

Instantly share code, notes, and snippets.

@romamik
Created November 8, 2016 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romamik/8650cc0ff33db96b681faacc5cda6dc4 to your computer and use it in GitHub Desktop.
Save romamik/8650cc0ff33db96b681faacc5cda6dc4 to your computer and use it in GitHub Desktop.
haxe read zip file in js and flash and sys targets
//add this to html to use in js: <script src="pako_inflate.min.js"></script>
//also put this file near html file: https://github.com/nodeca/pako/blob/master/dist/pako_inflate.min.js
function unzipEntry(entry:haxe.zip.Entry) {
#if flash
if (entry.compressed) {
var data = entry.data.getData();
data.inflate();
entry.data = Bytes.ofData(data);
}
#elseif js
if(entry.compressed) {
var entryData = entry.data.getData();
untyped entryData = window.pako.inflateRaw(entryData);
entry.data = Bytes.ofData(entryData);
}
#else
haxe.zip.Reader.unzip(entry);
#end
}
var data:Bytes; // contents of the zip file
var zip = (new haxe.zip.Reader(new BytesInput(data))).read();
for (entry in zip) {
unzipEntry(entry);
//entry.data is now contents of the unzipped file with name entry.fileName
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment