-
-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A way to unzip .zip files #11083
Comments
Is |
ZIPReader only reads the file. Sadly in my case I need to be able to actually unzip the file. By the way there is a way of doing this in Godot by using OS.execute and the unzip command in bash but i believe there should be an easier way to do this. |
You should be able to just write the files you read with ZIPReader, here's a quick proof of concept: var reader := ZIPReader.new()
reader.open("user://application.zip")
# Destination directory.
var root_dir := DirAccess.open("user://")
var files := reader.get_files()
for file_path in files:
# If the current entry is a directory.
if file_path.ends_with("/"):
root_dir.make_dir(file_path)
continue
# Write file contents.
var buffer := reader.read_file(file_path)
var file := FileAccess.open(root_dir.get_current_dir().path_join(file_path), FileAccess.WRITE)
file.store_buffer(buffer) |
Ok yeah my mistake for not testing the ZIPReader extensively, both my method and @raulsntos work, I'll be it the ladder is easier to pull of. As such I am closing this issue. 🎉 |
Describe the project you are working on
An applications installer.
Describe the problem or limitation you are having in your project
The installer needs to download a .zip file from a remote server and then extract it's contents, but there seems to be no way to extract a .zip file.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
Add a method to the FileAccess object that takes in the file path for a .zip file, unzips it and places all its contents in a new file with the same name as the .zip file
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
In GDscript:
FileAccess.unzip(filepath: String)
Example Usecase:
If this enhancement will not be used often, can it be worked around with a few lines of script?
As this is a recommendation for GDscript and not Godot this could not be fixed with a script, because GDscript offers no such functionality.
Is there a reason why this should be core and not an add-on in the asset library?
As stated above there is no way to do something like this with an add-on at least to my knowledge.
The text was updated successfully, but these errors were encountered: