httptoolkit / brotli-wasm

A reliable compressor and decompressor for Brotli, supporting node & browsers via wasm
Apache License 2.0
264 stars 21 forks source link

Can this be used to compress strings for local storage? #32

Closed thdoan closed 9 months ago

thdoan commented 9 months ago

I'm working with a limited local storage (8kb) and trying to compress the string data to maximize the storage. After trying out brotli, I noticed the compressed string is larger than the original...

Original (446 bytes): Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Compressed (985 bytes): 27,189,1,224,28,9,54,46,210,155,241,104,193,212,68,85,113,115,212,105,216,180,138,189,220,184,155,88,237,11,98,39,159,216,165,79,143,52,108,129,80,107,30,20,104,116,14,192,190,159,14,212,14,150,80,122,195,67,201,115,16,89,138,199,177,221,58,12,104,223,142,43,127,112,85,176,96,189,192,96,177,181,88,125,96,174,173,171,161,252,128,83,245,194,116,248,2,213,55,150,163,24,123,29,40,135,92,222,89,232,194,28,4,193,74,220,75,132,125,210,96,83,255,109,15,44,48,21,48,71,40,21,248,50,101,241,66,173,139,92,183,78,59,248,227,25,170,229,144,123,78,139,177,84,34,146,174,208,149,15,181,193,223,192,48,86,196,242,5,226,245,100,245,128,131,117,17,58,125,216,105,85,137,195,125,248,199,116,30,21,148,248,174,217,187,172,136,175,93,192,123,137,161,57,241,249,33,216,120,247,71,86,200,158,211,176,237,200,170,207,195,234,216,216,32,214,179,176,198,48,14,43,140,222,114,43,43,228,74,236,179,228,76,245,206,138,107,244,220,214,180,226,245,4,224,188,34,239,88,115,170,96,169,128,28,188,160,178,195,226,1

Is there a step that I'm missing to make the compressed string shorter?

I guess what I was looking for is a brotli version of https://jsfiddle.net/raunakkathuria/7PQtC/1/

thdoan commented 9 months ago

Figured it out (I needed to use TextDecoder).