Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
这个JavaScript的等效Bash是什么?_Javascript_Bash_Shell - Fatal编程技术网

这个JavaScript的等效Bash是什么?

这个JavaScript的等效Bash是什么?,javascript,bash,shell,Javascript,Bash,Shell,以下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, "-").re

以下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)

如果您包含一个带有示例输入和该输入的预期输出的小测试用例,我们可能会提供帮助。正当祝你好运。@dknaack你真的需要在Bash中实现b64吗?你不能使用base64命令吗?当base64编码的字符串不包含这些字符时,替换该字符串中的all/和all+,有什么意义呢?@Biffen我已经这样做了。我更新了我的问题。base64 | tr/+|-| tr-d=;字符串应该是标准的
#the string comes on stdin
base64 |      #encode
   tr /+ _- | #translate character sets
   tr -d =    #remove all =