btoa java_javascript atob()函数和 btoa()函数-Base64的编码与解码-Go语言中文社区

33526523f5fa24dad08508f6a258d5f8.png

在 JavaScript 中,有两个函数被分别用来处理解码和编码 base64 字符串:

atob() //ASCII to Base64

btoa() //Base64 to ASCII

atob() 函数能够解码通过base-64编码的字符串数据。相反地,btoa() 函数能够从二进制数据“字符串”创建一个base-64编码的ASCII字符串。

Encoded size increase(编码大小增长)

Each Base64 digit represents exactly 6 bits of data. So, three 8-bits bytes of the input string/binary file (3×8 bits = 24 bits) can be represented by four 6-bit Base64 digits (4×6 = 24 bits).(每一个base64数位明确表示6位数据,所以3个8位的字符或者二进制输入能够被4个6位的base64位数代表,4×6 = 3×8)

This means that the Base64 version of a string or file will be at most 133% the size of its source (a ~33% increase). The increase may be larger if the encoded data is small. For example, the string “a” with length === 1 gets encoded to “YQ==” with length === 4 — a 300% increase.(这代表着Base64编码的字符串或者文件的大小最大是源的133%倍,如果被编码的数据非常的小,那么这个比例将会非常的大,比如字符串"a" 的长度是1,但是编码后是4个长度的"YQ==")

基本用法

bbc5417b49d6ce51eea0f116809c70b5.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值