A method to directly compress a buffer

As a Roblox developer, it is currently hacky to utilise zstd compression within the engine. You can currently acheive this by calling JSONEncode with a buffer and retrieve it from the returned JSON string, however, this is hacky because it relies on the implementation detail here with regards to how its formatted (also it encodes as a Base64 string).

The method for which is as follows:

  • Identify the compressed stream in the JSON string, using JSONDecode doesn’t work because it decompresses the buffer.
  • De-encode the Base64 string

Instead, it would be nice to simply compress the buffer directly without needing to JSONEncode it and doing this hacky workaround.

If Roblox is able to address this issue, it would improve my development experience because I could compress and decompress buffers without needing to rely on a HttpService method that itself is an implementation detail.

1 Like

You aren’t supposed to encode the table into a JSON and then store that json in the buffer

Well its good thats not what I’m asking for. JSONEncode supports buffers as an argument (this isn’t documented anywhere), it sometimes compresses them as well!

This is likely a side effect of other Roblox methods that internally call the same JSON encoder, as you can see, it still works regardless, the z part of zbase64 indicates it was compressed.

im very interested in this could you explain more on how you are compressing a buffer into something even smaller i presume? that could be really helpful to know for networking :pray: