Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compression algorithm that produces url safe data

I'm looking to store cookie data in a compact form.

Is there such a thing as a compression algorithm that produces URL safe output? Currently my approach is

String jsonData = GSON.toJson(data);
byte[] cookieBinaryData = jsonData.getBytes("UTF-8");
byte[] cookieSnappyData = Snappy.compress(cookieBinaryData);
String cookieBase64Data = new Base64(true).encodeToString(cookieSnappyData);

From this cookieBase64Data is the one stored inside the cookie. I would be happy to skip the Base64 hop.

like image 936
Maxim Veksler Avatar asked Nov 14 '22 09:11

Maxim Veksler


1 Answers

How much are you saving by doing this? Is it worth it?

How about just saving an ID in a cookie and then looking up all the data in a database? Sort of like a long-lived session but you're controlling what data you store so there isn't a huge amount.

like image 144
Sarel Botha Avatar answered Dec 08 '22 06:12

Sarel Botha