buffer_compress

This function compresses part (or all) of a buffer using zlib compression and returns a new buffer containing the compressed data.

You supply the buffer to compress (as returned by buffer_create), the offset within the buffer to use in bytes, and the size of the buffer data to compress (also in bytes). The function will return the compressed buffer as a new buffer, or -1 if it has failed for any reason.

The function does not alter the original buffer.

 

Syntax:

buffer_compress(buffer, offset, size);

Argument Type Description
buffer Buffer The buffer to compress.
offset Real The offset within the buffer to compress (in bytes).
size Real The size of the buffer area to compress (in bytes).

 

Returns:

Buffer or -1 in case anything went wrong

 

Example:

var _srcBuff = buffer_create(1024, buffer_grow, 1);
buffer_write(_srcBuff, global.DataString);
var _cmpBuff = buffer_compress(_srcBuff, 0, buffer_tell(_srcBuff));
buffer_save(_cmpBuff, "Player_Save.sav");
buffer_delete(_srcBuff);
buffer_delete(_cmpBuff);

The above code creates a buffer then populates it with the data from a string. This buffer is then compressed and saved, and both the source and compressed buffers are deleted.