About
Gzip utils is a set of utility scripts to work with gzip, tar and, to a lesser extent, zip files.
You can use Gzip utils to extract the contents of .gz and .tar files, and read the metadata of .gz, .tar and
.zip files, listing for example the files contained in an archive with their attributes without actually expanding it.
Moreover, this a GML only asset, you don't need any extension to use it. This means out of the compatibility with almost every export
module that supports buffer operations (with the exception of HTML5 and Javascript based exports).
Limits
This is not a compression utility. All the provided functionalities deal with reading and extracting archives.
Due to HTML5 being able to load only Base64 encoded buffers, this asset does not work properly on HTML5 and javascript based export modules.
Files can be extracted only inside the sandbox. On windows, you can load files outside of the sandbox with get_open_filename, but the
files contained in the archives can only be extracted inside of it.
Function reference
GZIP
Closes an open gzip file opened using gzip_open(). This frees the memory from the file data.
var gzip = gzip_open("sample.gz");
if(gzip >= 0) {
gzip_close(gzip);
}
else {
show_message("Error loading gzip file!");
}
Opens a gzip file, and returns its handle (or a negative number if there is a load error).
The returned file handle is a ds_map holding the gzip metadata and a buffer with the binary data.
See the table at the bottom of this section for a list of available fields.
The file has to be closed with gzip_close(handle) in order to free the memory.
var gzip = gzip_open("sample.gz");
if(gzip >= 0) {
filename = gzip[? "fname"];
gzip_close(gzip);
}
else {
show_message("Error loading gzip file!");
}
Decompresses and extracts a gzip file at a specified location inside the sandbox, and returns
the number of extracted files (or a negative number in case of errors). You don't need to use gzip_open() or gzip_close()
in order to use this function, and in fact, I advise against it.
dest is the path where the files will be extracted, relative to the sandbox directory,
without the starting backslash.
An empty string will therefore extract the files in the root of working_directory.
untar (optional, default = true) if false does not try to untar the decompressed file. If true or omitted,
if the gzip holds a tar archive, it is automatically expanded.
var extracted_files = gzip_unzip("sample.tar.gz","my_folder/");
if(extracted_files >= 0) {show_message(string(extracted_files) + " files extracted");}
else {show_message("Error extracting files");}
Gzip properties
See RFC for details
Key | Type | Required | Description |
compressed_size |
real |
Yes |
Size of the compressed data (in bytes) |
compression_method |
real |
Yes |
Compression method used (8 is the de facto standard and the only supported one) |
crc |
real |
Yes |
CRC checksum |
data |
buffer |
Yes |
Buffer holding the gzip data (with headers) |
data_offset |
real |
Yes |
Offest of the compressed data (from buffer start) |
fcomment |
string |
No |
File comment |
fextra |
boolean |
No |
Extra fields are present |
fhcrc |
fhcrc |
No |
CRC of the header file |
flags |
real |
Yes |
Flags |
fname |
string |
No |
Name of the compressed file |
ftext |
boolean |
Yes |
File contains ASCII text |
mtime |
datetime |
Yes |
Last file modification datetime |
os |
real |
Yes |
Operating system used for compressing |
uncompressed_size |
real |
Yes |
Size of the uncompressed data (in bytes) |
xflags |
real |
Yes |
Extra flags (compression type) |
TAR
Closes an open tar file opened using tar_open(). This frees the memory from the file data.
var tar = gzip_open("sample.tar");
if(tar >= 0) {
tar_close(tar);
}
else {
show_message("Error loading tar file!");
}
Opens a tar file, and returns its handle (or a negative number if there is a load error).
The returned file handle is a ds_map holding the tar metadata and a buffer with the binary data.
See the table at the bottom of this section for a list of available fields.
The file has to be closed with tar_close(handle) in order to free the memory.
var tar = tar_open("sample.tar");
if(tar >= 0) {
files = ds_list_create();
ds_list_copy(files,tar[? "entries"]);
tar_close(tar);
}
else {
show_message("Error loading tar file!");
}
Extracts the contents of a tar file at a specified location inside the sandbox, and returns
the number of extracted files (or a negative number in case of errors). You don't need to use tar_open() or tar_close()
in order to use this function, and in fact, I advise against it.
dest is the path relative to the sandbox directory where the files will be extracted,
without the starting backslash.
An empty string will therefore extract the files in the root of working_directory.
var extracted_files = tar_untar("sample.tar","my_folder/");
if(extracted_files >= 0) {show_message(string(extracted_files) + " files extracted");}
else {show_message("Error extracting files");}
Tar properties
See RFC for details
Key | Type | Required | Description |
data |
buffer |
Yes |
Buffer holding the tar data |
entries |
ds_list |
Yes |
List of the files in the archive, with their properties. Every entry is a ds_map structured as follows |
Entries properties
This table lists the properties of a single entry of a tar file.
Key | Type | Required | Description |
checksum |
string |
Yes |
File checksum |
data_offset |
real |
Yes |
Offset of the file data from buffer start |
devmajor |
string |
No |
Device major number |
devminor |
string |
No |
Device minor number |
filename |
string |
Yes |
Name of the file |
gid |
string |
Yes |
Group ID |
gname |
string |
No |
Owner group name |
linkname |
string |
Yes |
Symbolic link name |
mode |
string |
Yes |
File mode |
mtime |
datetime |
Yes |
Last modification datetime |
name_prefix |
string |
No |
Filename prefix (already computed in filename" |
size |
real |
Yes |
File size (in bytes) |
type |
string |
Yes |
Type of file |
uid |
string |
Yes |
User UD |
uname |
string |
No |
Owner user name |
ustar |
string |
No |
Ustar format fields a present |
version |
string |
No |
Ustar version |
ZIP
Closes an open zip file opened using zip_open(). This frees the memory from the file data.
var zip = zip_open("sample.zip");
if(zip >= 0) {
zip_close(zip);
}
else {
show_message("Error loading zip file!");
}
Opens a zip file, and returns its handle (or a negative number if there is a load error).
The returned file handle is a ds_map holding the zip metadata and a buffer with the binary data.
See the table at the bottom of this section for a list of available fields.
The file has to be closed with zip_close(handle) in order to free the memory.
var zip = zip_open("sample.zip");
if(zip >= 0) {
files = ds_list_create();
ds_list_copy(files,zip[? "entries"]);
zip_close(zip);
}
else {
show_message("Error loading zip file!");
}
Zip properties
See RFC for details
Key | Type | Required | Description |
data |
buffer |
Yes |
Buffer holding the zip data |
eocd_offset |
real |
Yes |
Offset of the end of central directory from buffer start |
cdfh_offset |
real |
Yes |
Offset of the first central directory file header from buffer start |
total_entries |
real |
Yes |
Number of files |
entries |
ds_list |
Yes |
List of the files in the archive, with their properties. Every entry is a ds_map structured as follows |
Entries properties
This table lists the properties of a single entry of a tar file.
Key | Type | Required | Description |
cdfh_offset |
real |
Yes |
Offset of this file central directory header, from buffer start |
comment |
string |
No |
Comment |
compressed_size |
real |
Yes |
Size of compressed file (in bytes) |
compression_method |
real |
Yes |
Compression method used |
crc |
real |
Yes |
Checksum |
datetime_modified |
datetime |
Yes |
Last modification time |
ext_attributes |
real |
Yes |
External file attributes |
filename |
string |
Yes |
Name of the file |
header_offset |
real |
Yes |
Offset of the local file header from buffer start |
os |
real |
Yes |
Operating system used for compression and file attributes |
uncompressed_size |
real |
Yes |
Size of uncompressed file (in bytes) |
version |
real |
Yes |
Zip version used for compression |
version_required |
real |
Yes |
Zip version required to decompress |
Other
These scripts are used by the other gzip utils functions, but are generic enough to be useful for other purposes.
Creates a Game Maker datetime from a dos formatted date and time (as real numbers)
Creates a Game Maker datetime from a unix timestamp.
Returns a dos formatted date from a Game Maker datetime value.
Returns a dos formatted time from a Game Maker datetime value.
Returns the name of the specified file with the extension and path removed.
filename_name_noext("/data/assets.gz");