buffer_compress


语法:

buffer_compress(buffer, offset, size);


参数 描述
buffer The index of the buffer to compress.
偏移 The offset within the buffer to compress (in bytes).
大小 The size of the buffer area to compress (in bytes).


Returns: Buffer Index


描述

With this function you can compress part (or all) of a buffer using zlib compression. You supply the ID of 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 a new buffer ID value for the compressed buffer, or a value less than 0 if it has failed for any reason. This function will not alter the original buffer.


例如:

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 will create a buffer then populate it with the data from a string. This buffer is then compressed and saved, and both the source and compressed buffers are deleted