Flustix
(Flustix)
January 17, 2022, 6:14pm
1
i’ve been trying to unzip a file on haxe but i cant find a way because all the functions are not available on sys platforms
tjrhodes
(Tom Rhodes)
January 17, 2022, 8:25pm
2
Hi,
You could try something like this instead:
File.saveBytes(zipPath, zipBytes);
Sys.command("unzip",['-qq','-o',zipPath,'-d',scanDir]);
// cycle through zip and store paths to individual scans.
recursiveLoop(scanDir);
tokiop
(tokiop)
January 17, 2022, 8:50pm
3
There is also an example on code.haxe.org !
Ive been using this without issue (so far):
// https://gist.github.com/ruby0x1/8dc3a206c325fbc9a97e
private static function unzipFile(srcZip:String, dstDir:String, ignoreRootFolder:Bool = false) {
log("Unzipping archive");
FileSystem.createDirectory(dstDir);
var inFile = sys.io.File.read(srcZip);
var entries = haxe.zip.Reader.readZip(inFile);
inFile.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 != false && dirs.length > 1) || ignoreRootFolder == false) {
if (ignoreRootFolder != false) {
dirs.shift();
}
var path = "";
var file = dirs.pop();
This file has been truncated. show original
tjrhodes
(Tom Rhodes)
January 20, 2022, 11:18am
5
I thought the OP was talking about a situation where the haxe method didn’t work on sys targets. Ian’s way is best, using the Reader if you can…