Working example of compress/decompress with StreamPeerGZIP

Godot Version

4.2.1

Question

Hi guys

Do you have a working example of compress/decompress using StreamPeerGZIP.
I found this one StreamPeerGZIP In Godot - Complete Guide - GameDev Academy
but it doesn’t work.

I found a solution.

## Gzip

func gzip_encode(text: String):
	var gzip = StreamPeerGZIP.new()
	gzip.start_compression()
	gzip.put_data(text.to_utf8_buffer())
	gzip.finish()
	return gzip.get_data(gzip.get_available_bytes())[1]

func gzip_decode(data):
	var gzip = StreamPeerGZIP.new()
	gzip.start_decompression()
	gzip.put_data(data)
	gzip.finish()
	return gzip.get_utf8_string(gzip.get_available_bytes())
1 Like