What is the space overhead of Base64 encoding?
lemire.me
lemire.me
Of course there's also the overhead of decoding all those base64 blobs in the browser, but I'm sure that's a topic for another blog post in the future :)
binary -> ASCII -> binary
But I just tested this again and it's not true anymore.
$ wc -c american-english
971578 american-english
$ gzip < american-english | wc -c
259977
$ base64 < american-english | gzip | wc -c
429263
$ hexdump -e '"%x"' < american-english | gzip | wc -c
478411 $ hexdump -e '"%x"' < american-english | gzip | wc -c
463871
$ hexdump -v -e '/1 "%02x"' < american-english | gzip | wc -c
302515
$ base64 < american-english | gzip | wc -c
415737Ack, is there anything little-endian doesn't ruin?
/me misses 68000 assembler …
$ cat index.html | gzip -9 | wc -c
14116
$ cat index.html bing.base64 | gzip -9 | wc -c
15994
$ expr 15994 - 14116
1878
$ cat bing.base64 | gzip -9 | wc -c
1432https://github.com/kstenerud/safe-encoding/blob/master/READM...
radix-64 of course fares the best, but radix-85 isn't much different, and is 10% smaller uncompressed.
i included some text files, hex encoding, and other compression as well :)
raw file list: https://hastebin.com/vazonowuvo.txt
tsv (c/p to spreadsheet: https://hastebin.com/ewohafucem.tsv
---
(interesting) using bzip2, compression is better when the following file are encoded first with base64 or hex: bing.png googlelogo.png peppers_color.jpg
Useless takeaways:
- prefer base64 over hex when encoding already compressed images before further compression
- prefer hex over base64 when encoding plain text / low entropy data before further compression
Otherwise we could pass along some information "for free" in any base-64 encoding scheme by choosing some set of 64 characters (there are lots of choices and whichever set we choose encodes a message), encoding the original message with it, and then compressing it back to the original size - leading to "infinite" compression.
Other reasons base64 can't be compressed exactly back to its original form include the presence of arbitrary newlines, and trailing padding characters.
This doesn't matter in practice for compressing one large base64 encoded file where the overheads go to approximately zero, but for compressing a larger non-base64 file (e.g., HTML file) that contains embedded base64 chunks it is actually a real problem the compressor has to delimit the base64 encoded regions and communicate the new symbol probabilities somehow for each region.
=Endmarker
https://stackoverflow.com/questions/49650847/determine-if-st...
Uh, no.
They are using 'base64 encoded' as a shorthand for 'as an embedded base64 blob inside an HTML page.' - to distinguish it from 'as an individually requested resource'.
So what they are referring to is that by embedding resources as base64 blobs inside HTML pages, and transferring those over SSL, an observer sees one large encrypted bundle being requested. If you transfer the resources as separate response entities, then an observer sees the large HTML bundle request, followed by the series of specific resources - and they can infer from the sizes and patterns of those requests some things about the page requested or the resources used.
(for example, if I know the size of the HTML and every image on wikipedia, perhaps by observing the set of sizes of resources being downloaded by a client over HTTPS I can determine which wikipedia pages a client is browsing?)
> In some instances, base64 encoding might even improve performance, because it avoids the need for distinct server requests.
I.e. they are arguing inlining all resources and grabbing them in a single request has a smaller fingerprint. This is probably less true with HTTP/2 or QUIC
Furthermore the article begins with the premise of using text-only data transfer protocols such as MIME, then goes on to talk about base64-encoding then gzipping data. If he were to continue talking about text-only data transfer, then he should've talked about gzipping, then base64-encoding the data or if he were talking about reducing the size of the data he should've been talking about gzipping instead of base64-encoding the data. Instead he seems to be talking about something which isn't compatible with MIME. So the article doesn't really seem to have a clear direction. If the point was to cut down on a single round-trip to the server then congratulations -- you've increased your page size by 2.5% and added the overhead of compression to the request -- a much higher toll than the cost of a 2nd request for non-trivial assets of the sort gzip would be effective for since it has its own overhead requirements.
Would your opinion change if you reread the content with the understanding HTTPS is assumed when talking about web privacy in 2019? The author made no claim whatsoever base64 was encrypting the data, just bundling it into one generic request.
> Furthermore the article begins with the premise of using text-only data transfer protocols such as MIME, then goes on to talk about base64-encoding then gzipping data...
Would your opinion change if you reread the content with the assumption the author means to set "Content-Encoding: gzip" in the server config rather than literally gzipping the content?
I think both of these are fair assumptions for the target audience of the article to assume but your disagreements with the article are only true without them.
Well he began by talking about email, so no. If we want to talk about HTTPS and 2019, then let's serve the whole shebang with HTTP/2 and not worry about reducing the number of requests, which seems to be the only advantage offered.
> Would your opinion change if you reread the content with the assumption
That's the assumption I was forced to make, and the crux of my argument. Content-Encoding: gzip works in most servers by compressing the content on the fly -- not by precompiling. Hence my comment about adding the overhead of compression to the request.
It could be slightly less if you want to remove the padding and calculate what the padding should be on the decoding side: base64string.length % 4.
Edit: If no entropy is added, it's still ~33%. C'mon :P
This is from my personal experience utilizing gzip and bzip2 via Boost Iostreams to compress network payloads over a 1Gbps link. End to end latency was far superior with gzip than bzip2, despite bzip2 having a smaller transmission size.
Near the space/time tradeoff point that gzip lives, however, it is thoroughly outclassed by more modern compressors such as zstd or brotli with the appropriate settings.
So if you want to efficiently store some emails, it doesn't really matter whether you decode and store attachments separately or just compress the raw text. (Although decoding and separating allows deduping.)