ZipFile.jl
ZipFile.jl copied to clipboard
Add an unzip function
Currently if I need to unzip a folder, I'll have to write:
r = ZipFile.Reader("/tmp/example.zip");
for f in r.files
println("Filename: \$(f.name)")
write(stdout, read(f, String));
end
Instead, there can be a ZipFile.unzip("/tmp/example.zip")
which will place all the data in /tmp/example
directory and return me the path of the directory.
The code above just writes the content of each file to stdout. I'm guessing you want a function that extracts all files in a directory. In that case, I'd rather have the user specify the destination directory rather than return it.
I really don't know how to write a pr but there is decent code here, experimental, but it works for most use cases. Bump for adding this because InfoZIP is not being maintained and has problems with its .toml file, and can't be installed. I'd be very sad if I can't find a package to unzip a file in julia!
Unfortunately, this is quite complicated to do in a cross-platform manner that safely handles all potential errors or malicious zip archives. The code you link to has a few big issues but will sometimes work.
For now, I would recommend using p7zip_jll
Here is an example I have: https://github.com/JuliaIO/ZipArchives.jl/blob/d96b54d03636f0976e3f276896572b398a623d79/test/external_unzippers.jl#L16C1-L26C4