gdunzip's icon

gdunzip 1.0.0 Scripts 3.0.4 Community

Submitted by user jelle; MIT; 2019-01-10

Gdunzip is a zip file browser/decompressor written entirely in a single
GDScript file. You can use this in games you're building with the Godot game
engine. This script is meant for modest zip decompressing purposes, since the
inflate algorithm it contains isn't super fast and gdunzip doesn't do CRC
checks of the uncompressed files. However, gdunzip works fine if you only need
to decompress small files, or when your zip files contain precompressed files
like png's.

In order to create gdunzip, I have made a GDScript port of Jørgen Ibsen's
excellent tiny inflate library: tinf ( for
decompressing the deflate streams. Since the original was written in C and used
some nifty pointer arithmetic, I had to make some minor changes
here and there to be able to translate it. However, I tried to stay as close to
the original code as possible.

The zip file format parsing is all written from scratch and performs pretty

Using gdunzip

# Instance the gdunzip script
var gdunzip = load('res://addons/gdunzip/').new()

# Load a zip file
var loaded = gdunzip.load('res://')

# Uncompress a file, getting a PoolByteArray in return
# (or false if it failed uncompressing)
if loaded:
var uncompressed = gdunzip.uncompress('lorem.txt')
if !uncompressed:
print('Failed uncompressing lorem.txt')
print('Failed loading zip file')

- When gdunzip has loaded a zip file, you can iterate over all the files inside, by
looping through the "files" attribute:

for f in gdunzip.files:
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']))

Class documentation


- bool load(String path)

Tries to load a zip file with a given path. Returns false if it failed
loading the zip, or true if it was successfull.

- PoolByteArray uncompress(String file_name)

Try to uncompress the given file in the loaded zip. The file_name can include
directories. This function returns *false* if the file can't be found, or if
there's an error during uncompression.

- PoolByteArray get_compressed(String file_name)

Returns the compressed data for a given file name (or false if the file can't
be found). Depending on the file compression it can be either uncompressed or a
raw deflate stream. This function returns *false* if the file can't be found.


After you have loaded a file, the gdunzip instance will have a pre-filled
"files" attribute. This is simply an dictionary containing the meta data for
the files that reside in the zip. The dictionary is a mapping from file name
(including directory) to another dictionary with the following keys:

- file_name: the file name
- compression_method: -1 if uncompressed or File.COMPRESSION_DEFLATE
- file_header_offset: the exact byte location of this file's compressed data
inside the zip file
- compressed_size: the compressed file size in bytes
- uncompressed_size: the uncompressed file size in bytes

View files Download Submit an issue Recent Edits

Sha256 Hash: bf5da6d31fbe47a83b6a4df0712114bcc4033cfb0d51352b46080064ee04770e