problem reading zip data containing folders and empta files (neko target)

63 views
Skip to first unread message

Simon Rofllol

unread,
Sep 13, 2013, 9:42:11 AM9/13/13
to haxe...@googlegroups.com
Hi List or Group,

I've a problem unzipping my files and kinda stuck here.. as long it´s simple data e.g. one zip file with a few files in it i´m completly fine and everything works but as soon as I come to a folder inside my zip-file I´m out..

    static function main() {
//creating folder for unzipped data
       
if (! sys.FileSystem.exists('C:\\test\\TestZip\\unzipped')) {
            sys
.FileSystem.createDirectory('C:\\test\\TestZip\\unzipped');
       
}
       
var fileIn = sys.io.File.read('C:\\test\\TestZip\\testZip.zip', true);
       
var zipDat = haxe.zip.Reader.readZip(fileIn);
       
try {
            trace
(zipDat);
           
for (s in zipDat) {
                trace
(s.fileName);
               
var content = (s.compressed) ? haxe.zip.Reader.unzip(s) : s.data;
                trace
(content);
               
if (content.length != 0) {
//here lays my problem I can#t tell for sure if it´s a folder or just an empty file
//if it´s an folder I need too create it first, before unzipping anything into it
//but i don't see any flags??
                    sys
.io.File.saveBytes('C:\\test\\TestZip\\unzipped\\' + s.fileName, content);
               
}
           
}
            fileIn
.close();
            zipDat
.clear();
       
} catch (e: Dynamic) {
            trace
(e);
       
}
   
}


As in code, I guess I need too create the folder first, before unzipping my content too it. But as I can't tell if it's a empty file or an folder, I don't know when too create an folder?
I tried with content.length but empty files have also the length == 0, I even thougt about scanning the filename for an dot, but you can have dots in folders and you can files without a dot..

Maybe I´m generally doing something terrible wrong and there are better ways for file-handling and unzipping in neko?
testZip.zip

Tom

unread,
Sep 13, 2013, 1:33:42 PM9/13/13
to haxe...@googlegroups.com
Hi!

If I'm not mistaken, the fileName contains the relative path of the file, with folders. So you need only to split() it by separators, and create the folders in the appropriate place. The last element will be the real name of the file.

Tom

unread,
Sep 14, 2013, 4:17:03 AM9/14/13
to haxe...@googlegroups.com
It was a bit "fast" my previous answer, sorry for that.

In your ZIP file there are some empty folders, and or empty files?
If the ZipEntry.fileSize == 0, then the file is empty.
And the ZipEntry.fileName.substr(-1)  /* the last character */ is "/" or "\\", then this is a folder.
Maybe this will help.

Best regards!
Tom

Simon Rofllol

unread,
Sep 15, 2013, 7:13:03 AM9/15/13
to haxe...@googlegroups.com
Thanks a lot! This will help me enourmos! And exactly what I needed :)
Reply all
Reply to author
Forward
0 new messages