Reputation: 30172
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.
Upvotes: 5
Views: 1352
Reputation: 12700
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.
Upvotes: 1
Reputation: 12582
No. Compression is often a prefix-free code and not a charset. You can use yEnc encoding to safe some bits. Personally I'm not sure why yEnc is doomed. It uses an extended 8 bit ASCII charset and adds a lot less overhead (2%) to the compressed data: http://en.wikipedia.org/wiki/YEnc
Upvotes: 0