Created
June 7, 2014 19:36
-
-
Save ruby0x1/8dc3a206c325fbc9a97e to your computer and use it in GitHub Desktop.
Unzip a file with haxe - example
This file contains hidden or 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
public static function unzip( _path:String, _dest:String, ignoreRootFolder:String = "" ) { | |
var _in_file = sys.io.File.read( _path ); | |
var _entries = haxe.zip.Reader.readZip( _in_file ); | |
_in_file.close(); | |
for(_entry in _entries) { | |
var fileName = _entry.fileName; | |
if (fileName.charAt (0) != "/" && fileName.charAt (0) != "\\" && fileName.split ("..").length <= 1) { | |
var dirs = ~/[\/\\]/g.split(fileName); | |
if ((ignoreRootFolder != "" && dirs.length > 1) || ignoreRootFolder == "") { | |
if (ignoreRootFolder != "") { | |
dirs.shift (); | |
} | |
var path = ""; | |
var file = dirs.pop(); | |
for( d in dirs ) { | |
path += d; | |
sys.FileSystem.createDirectory(_dest + "/" + path); | |
path += "/"; | |
} | |
if( file == "" ) { | |
if( path != "" ) Run._trace("created " + path); | |
continue; // was just a directory | |
} | |
path += file; | |
Run._trace("unzip " + path); | |
var data = haxe.zip.Reader.unzip(_entry); | |
var f = File.write (_dest + "/" + path, true); | |
f.write(data); | |
f.close(); | |
} | |
} | |
} //_entry | |
Sys.println(''); | |
Sys.println('unzipped successfully to ${_dest}'); | |
} //unzip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hey used ur code i needed to edit it alittle other than that it works perfectly thx for making this code public