Skip to content

Instantly share code, notes, and snippets.

@theJenix
Forked from ruby0x1/haxe-unzip-example.hx
Created October 30, 2020 15:22
Show Gist options
  • Select an option

  • Save theJenix/f34e2ef85b7eaf6fa6e1e2ef69f08e68 to your computer and use it in GitHub Desktop.

Select an option

Save theJenix/f34e2ef85b7eaf6fa6e1e2ef69f08e68 to your computer and use it in GitHub Desktop.

Revisions

  1. @ruby0x1 ruby0x1 created this gist Jun 7, 2014.
    44 changes: 44 additions & 0 deletions haxe-unzip-example.hx
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    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