以下JavaScript的Bash版本是什么?
// url-safe base64 encoding
function b64(bytes){
var str64 = typeof(bytes) === "string" ? window.btoa(bytes) : window.btoa(String.fromCharCode.apply(null, bytes));
return str64.replace(/\//g, "_").replace(/\+/g, "-").replace(/=/g, "");
}
特别是以下部分:
String.fromCharCode.apply(null, bytes)
答案 0 :(得分:2)
#the string comes on stdin
base64 | #encode
tr /+ _- | #translate character sets
tr -d = #remove all =