0

I'd like to encode binary data more efficiently than Base64 for transferring data to browsers. It doesn't need to be human-readable, it should just survive being transferred as UTF-8.

Since not all byte sequences are valid UTF-8, the data needs to be converted somehow.

It would need to be a solution that works in the browser.

Is this possible?

w00t
  • 17,944
  • 8
  • 54
  • 62
  • 1
    Why not use compression like [GZIP](https://github.com/beatgammit/gzip-js) or [LSW](http://pieroxy.net/blog/pages/lz-string/index.html)? – h2ooooooo Jun 15 '17 at 11:36
  • 1
    Please check [Encoding binary data within XML: Are there better alternatives than base64?](https://stackoverflow.com/questions/17301940/encoding-binary-data-within-xml-are-there-better-alternatives-than-base64) and [Binary Data in JSON String. Something better than Base64](https://stackoverflow.com/questions/1443158/binary-data-in-json-string-something-better-than-base64). – Álvaro González Jun 15 '17 at 11:50
  • @h2ooooooo Hmm you are right - I tried converting a compressed image to base64, and then gzipping it, and it yielded only a few % increase. Between that and the excellent links that ÁlvaroGonzález found, I'll close this question. – w00t Jun 18 '17 at 07:32
  • Possible duplicate of [Binary Data in JSON String. Something better than Base64](https://stackoverflow.com/questions/1443158/binary-data-in-json-string-something-better-than-base64) – w00t Jun 18 '17 at 07:32
  • @w00t You shouldn't need to use base64 encoding as long as you're compressing it. I believe that might earn you quite a few % off the final payload. – h2ooooooo Jun 18 '17 at 11:36
  • The problem is transferring the data over a channel JS understands… – w00t Jun 18 '17 at 12:36

0 Answers0