Кон*_*Ван 231 javascript
在Javascript中,window.atob()
方法解码base64字符串,window.btoa()
方法编码string
为base64.
那么,为什么没有他们命名为喜欢的base64Decode()
和base64Encode()
?
atob()
而且btoa()
没有意义,因为它们根本就不是语义.
我想知道原因.
she*_*hen 144
该atob()
和btoa()
方法允许作者进行改造的内容,并从base64编码.
在这些API中,出于助记的目的,"b"可以被认为代表"二进制",而"a"代表"ASCII".但实际上,由于主要的历史原因,这些函数的输入和输出都是Unicode字符串.
来自:http://www.w3.org/TR/html/webappapis.html#atob
der*_*nio 91
总结已经给出的答案:
atob
代表 ASCII to binary
atob("ZXhhbXBsZSELCg==") == "example!^K"
btoa
代表 binary to ASCII
btoa("\x01\x02\xfe\xff") == "AQL+/w=="
为什么一个 SCII和b inary:
ASCII
(a
)是base64
编码的结果.一个安全的唯一的ASCII字符的一个子集(*),可以正确表示和运输组成的文本(例如电子邮件的身体),binary
(b
)是0和1的任何流(在javascript中它必须用字符串类型表示).(*)在base64
这些被限制为:A-Z
,a-z
,0-9
,+
,/
和=
(填充,仅在端部)https://en.wikipedia.org/wiki/Base64
PS我必须承认我自己最初被命名混淆,并认为名称被交换.我认为b
立场" b ase64编码字符串",并a
为" 一个纽约字符串":d.
Wil*_*ton 68
我知道这是旧的,但它最近出现在Twitter上,我想我会分享它,因为它是权威的.
我:
@BrendanEich你选这些名字了吗?
他:
旧的Unix名称,很难找到手册页,但请参阅 https://www.unix.com/man-page/minix/1/btoa/ .... 名称从Unix转移到Netscape代码库.我在1995年匆忙地将它们反映到JS中(在五月的十天之后但很快).
如果Minix链接断开,这里是手册页内容:
BTOA(1) BTOA(1)
NAME
btoa - binary to ascii conversion
SYNOPSIS
btoa [-adhor] [infile] [outfile]
OPTIONS
-a Decode, rather than encode, the file
-d Extracts repair file from diagnosis file
-h Help menu is displayed giving the options
-o The obsolete algorithm is used for backward compatibility
-r Repair a damaged file
EXAMPLES
btoa <a.out >a.btoa # Convert a.out to ASCII
btoa -a <a.btoa >a.out
# Reverse the above
DESCRIPTION
Btoa is a filter that converts a binary file to ascii for transmission over a telephone
line. If two file names are provided, the first in used for input and the second for out-
put. If only one is provided, it is used as the input file. The program is a function-
ally similar alternative to uue/uud, but the encoding is completely different. Since both
of these are widely used, both have been provided with MINIX. The file is expanded about
25 percent in the process.
SEE ALSO
uue(1), uud(1).
Run Code Online (Sandbox Code Playgroud)
资料来源:JavaScript的创建者Brendan Eich.https://twitter.com/BrendanEich/status/998618208725684224
我目前无法找到一个来源,但众所周知,在这种情况下,b代表'二进制',而a代表'ASCII'.
因此,这些函数实际命名为:
ASCII到二进制atob()
,二进制到ASCII btoa()
.
请注意,这是浏览器实现,仅用于传统/向后兼容目的.例如,在Node.js中,这些不存在.
归档时间: |
|
查看次数: |
46514 次 |
最近记录: |