为什么base64编码的字符串的大小比原始文件大 [英] Why the size of base64-encoded string is larger than the original file

查看:1231
本文介绍了为什么base64编码的字符串的大小比原始文件大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

快速的问题,我原来的pdf文件大小是24MB左右,但是当我编码到64位的字符串,字符串的大小是31MB左右,只是想知道为什么?

这对图像文件很容易理解,因为它可能会丢失一些压缩,但是它也发生在pdf或其他格式文件中?

解决方案


只是想知道为什么

因为Base64比二进制数据格式(通常是6而不是8)每个字节的有意义比特更少。这是特别的,所以它可以在二进制数据不能进行的各种文本转换的情况下生存。例子rel =noreferrer>维基百科的页面有一个很好的图表显示了这一点:



请注意Base64是如何使用每个字节的底部六位,所以Man最后是四个字节长。


对于图像文件很容易理解,因为它可能会丢失一些压缩的内容。 ,Base64编码是无损的。当你对它进行解码的时候,你会得到字节的字节。


Quick question, my original pdf file size is around 24MB, however when I encode it to based64 string, the string size is around 31MB, just wondering why?

It is easy to understand for image file since since it may lose some compression, but it also happens to pdf or some other format files?

解决方案

just wondering why

Because Base64 has fewer meaningful bits per byte than a binary data format (usually 6 instead of 8). This is specifically so it can survive various textual transformations that binary data would not.

Wikipedia's page has a good diagram showing this:

Note how the Base64 is only using the bottom six bits of each byte, and so "Man" ends up being four bytes long.

It is easy to understand for image file since since it may lose some compression

No, Base64 encoding is lossless. When you decode it, you get byte-for-byte what you started with.

这篇关于为什么base64编码的字符串的大小比原始文件大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆