jellehermsen / gdunzip Goto Github PK
View Code? Open in Web Editor NEWA zip file browser/decompressor written entirely in GDScript, for usage in the Godot game engine.
License: MIT License
A zip file browser/decompressor written entirely in GDScript, for usage in the Godot game engine.
License: MIT License
here's my code, I'm trying to extract the files from a zip.
$HTTPRequest.request("https://skse.silverlock.org/beta/skse64_2_01_05.7z")
func _on_HTTPRequest_request_completed(result, response_code, headers, body):
var file = File.new()
file.open_compressed("skse64_2_01_05.7z", File.WRITE, 0)
file.store_buffer(body)
var loaded = gdunzip.load('res://skse64_2_01_05.7z')
if loaded:
var uncompressed = gdunzip.uncompress('lorem.txt')
if !uncompressed:
print('Failed uncompressing lorem.txt')
else:
print(uncompressed.get_string_from_utf8())
else:
print('Failed loading zip file')
for f in gdunzip.files.values():
print('File name: ' + f['file_name'])
# "compression_method" will be either -1 for uncompressed data, or
# File.COMPRESSION_DEFLATE for deflate streams
print('Compression method: ' + str(f['compression_method']))
print('Compressed size: ' + str(f['compressed_size']))
print('Uncompressed size: ' + str(f['uncompressed_size']))```
I am trying to extract a large file from a zip. But it gets stuck on it and doesn't continue. It goes through the other files but not that one.
Tester.zip
Hello,
I'm trying to unzip a .zip folder containing only two text files, an .md and a .txt.
When I try to extract files from it, an error prints in console:
Here it is the code:
var unzipper = load("res://addons/github-integration/resources/extraction/gdunzip.gd").new()
[...]
func extraction_process():
var archive = unzipper.load_archive(zip_filepath)
var uncompressed_file : File = File.new()
if archive:
for file in unzipper.files:
var uncompressed = unzipper.uncompress(file)
if uncompressed:
uncompressed_file.open("res://uncompressed/"+file,File.WRITE)
uncompressed_file.store_string(uncompressed.get_string_from_utf8())
uncompressed_file.close()
where zip_filepath
is just the path to the zip I'm getting after a download.
And I'm attaching the zip too, if you need to test.
Thank you very much for your support, waiting for your response, if you need anything more.
Hello!
The script now works fine and is actually really fast.
But sometimes there is a strange bug happening while uncompressing some folders/files.
In console appears a Unicode error: invalid skip
message, even though it doesn't seem to be an error, and there are not unrecognized characters in folders/files names.
When this happens, the script skips folders and directly uncompresses files.
I hope you will be able to reproduce the issue and understand it better with my resources.
func extraction_process():
var archive = unzipper.load(zip_filepath)
if archive:
var root : String = unzipper.files.values()[0].file_name
for file in unzipper.files.values():
var uncompressed = unzipper.uncompress(file.file_name)
if uncompressed:
#print("File:" +file.file_name.lstrip(root))
if file.file_name.lstrip(root).get_base_dir()!='':
var dir : Directory = Directory.new()
dir.make_dir("res://uncompressed/"+file.file_name.lstrip(root).get_base_dir())
#print("Directory:" +file.file_name.lstrip(root).get_base_dir())
var uncompressed_file : File = File.new()
uncompressed_file.open("res://uncompressed/"+file.file_name.lstrip(root),File.WRITE)
uncompressed_file.store_string(uncompressed.get_string_from_utf8())
uncompressed_file.close()
godot engine 3.2beta2
Hi,
Thank you for this addon.
I'm having problems to uncompress the file "song.egg" from this File
It looks like the code gets stuck in an endless loop.
The code I'm using is:
var gdunzip = load('res://addons/gdunzip/gdunzip.gd').new()
var loaded = gdunzip.load(zip_file)
var uncompressed = gdunzip.uncompress(fileName)
return uncompressed
where
zip_file: is the path to the zip file
fileName: is "song.egg"
alice.zip contains a rather large alice.txt (the complete Alice in Wonderland book) and it seems to fail uncompressing the last block.
error(335, 7): Variable "i" already defined in the scope (at line 332).
gdunzip.gd line 335:
func tinf_build_bits_base(target, delta, first):
var i = 0
var sum = first
for i in range(0, delta):
base_tables[target + '_bits'][i] = 0
for i in range(0, 30 - delta):
base_tables[target + '_bits'][i + delta] = i / delta
for i in range(0, 30):
base_tables[target + '_base'][i] = sum
sum += 1 << base_tables[target + '_bits'][i]```
A few things got changed like Pool into Packed and stuff, I tried looking into it but it seems that it needs a deeper rewrite.
The current inflator is a pretty straightforward port of Tinf. I suspect there's a lot of tiny performance improvements that can be made.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.