Created
November 8, 2016 15:10
-
-
Save romamik/8650cc0ff33db96b681faacc5cda6dc4 to your computer and use it in GitHub Desktop.
haxe read zip file in js and flash and sys targets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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