URL-safe base64解码为R。

时间:2021-07-06 18:33:41

I don't know if it's just R being notoriously hard to search for but I can't seem to find a URL-safe base64 decoder for R.

我不知道是不是R的搜索非常困难,但是我似乎找不到一个url安全的base64解码器。

Does anyone know of one ?

有人知道吗?

Edit I've used various decoders, the RCurl::base64decode() function as well as online ones and the results are somewhat inconsistent.

编辑我使用了各种解码器,RCurl::base64decode()函数和在线的函数,结果有些不一致。

I admit I don't understand the full details of what differentiates a "URL-safe" base64 decoder but find it dismissive to have my question closed in a matter of minutes due to a moderator's misunderstanding of what I'm asking before anyone gets a chance to answer.

我承认我不明白什么是“url安全”的base64解码器的全部细节,但我发现它对我的问题在几分钟内就关闭了,这是由于主持人误解了我的问题,然后才有机会回答。

Edit 2 The equivalent in Python is base64.urlsafe_b64decode(s), and as yet noone has implemented this in R.

在Python中,等效为base64.urlsafe_b64decode(s),但是没有人在R中实现这个。

Using library(sos) as recommended in the comments brings up 3 packages, and as expected a Google search would have found them had they URL-safe methods.

在注释中推荐的使用库(sos)会带来3个包,并且正如预期的那样,谷歌搜索会发现它们有url安全的方法。

  • base64::decode() has just two parameters, input and output, i.e. only works on files, and attempting this on my string produces a mangled output. URL-safe base64解码为R。 The only other methods in the package are encode() and img (for image file base64-string encoding)
  • base64::decode()只有两个参数,输入和输出,即只对文件进行操作,并且在我的字符串上尝试这个操作会产生一个混乱的输出。包中唯一的其他方法是编码()和img(用于图像文件base64-string编码)
  • base64enc::base64decode() follows much the same, though can use a text connection rather than solely a file input. Again, no option to use a modified URL-safe alphabet
  • base64enc::base64decode()遵循相同的方法,但是可以使用文本连接,而不只是一个文件输入。同样,不能使用修改后的url安全字母。
  • RCurl::base64Decode() can only take text input (befitting a stream-handling package), and a mode parameter can be set to either raw or character. It doesn't seem that either mode permits altering the decoding alphabet.
  • RCurl::base64Decode()只能接收文本输入(适合于流处理包),并且模式参数可以设置为raw或character。看起来,两种模式都不允许改变解码字母。

The Python docs explain that a URL-safe alphabet

Python文档解释了一个url安全的字母。

substitutes - instead of + and _ instead of / in the standard Base64 alphabet.

替代品-取代了+和_而不是标准的Base64字母表。

I'd be interested to know how to use a custom alphabet. If I understand correctly the 'raw' mode has already applied the alphabet, and thus mistranslated.

我很想知道如何使用自定义字母表。如果我正确理解,“原始”模式已经应用了字母表,因此误译。

The example above is the body of an email I retrieved through the Gmail API, which base64-encodes with such a URL-safe encoder:

上面的示例是我通过Gmail API检索的一封邮件的正文,该API使用了这种url安全编码器的base64-encode:

PGRpdiBkaXI9Imx0ciI-SGksPGJyPjxicj5JIGNhbiYjMzk7dCBpbnN0YWxsIHhwcyBiZWNhdXNlIGR1cmluZyBjb21waWxlIEkgZ2V0OjxkaXY-PGJyPjwvZGl2PjxkaXY-PGZvbnQgZmFjZT0ibW9ub3NwYWNlLCBtb25vc3BhY2UiPlRNTE1hdGguY3h4OjUxOjE5OiBmYXRhbCBlcnJvcjogVE1hdGguaDogTm8gc3VjaCBmaWxlIG9yIGRpcmVjdG9yeTxicj48L2ZvbnQ-PC9kaXY-PGRpdj48Zm9udCBmYWNlPSJtb25vc3BhY2UsIG1vbm9zcGFjZSI-PGJyPjwvZm9udD48L2Rpdj48ZGl2PjxkaXY-PGZvbnQgZmFjZT0ibW9ub3NwYWNlLCBtb25vc3BhY2UiPsKgI2luY2x1ZGUgJnF1b3Q7VE1hdGguaCZxdW90OzwvZm9udD48L2Rpdj48ZGl2Pjxmb250IGZhY2U9Im1vbm9zcGFjZSwgbW9ub3NwYWNlIj7CoCDCoCDCoCDCoCDCoCDCoCDCoCDCoCDCoCDCoF48L2ZvbnQ-PC9kaXY-PGRpdj48Zm9udCBmYWNlPSJtb25vc3BhY2UsIG1vbm9zcGFjZSI-Y29tcGlsYXRpb24gdGVybWluYXRlZC48L2ZvbnQ-PC9kaXY-PGRpdj48Zm9udCBmYWNlPSJtb25vc3BhY2UsIG1vbm9zcGFjZSI-bWFrZTogKioqIFtUTUxNYXRoLm9dIEVycm9yIDE8L2ZvbnQ-PC9kaXY-PGRpdj48Zm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aWFsLCBoZWx2ZXRpY2EsIHNhbnMtc2VyaWYiPkkgaG9wZSB5b3UgbWF5IGJlIGFibGUgdG8gYWR2aXNlLCBJJiMzOTt2ZSBydW4gb3V0IG9mIGlkZWFzIGFuZCBleHBlcnRpc2Ugb24gaG93IGVsc2UgdG8gcHJvY2VlZC48L2ZvbnQ-PC9kaXY-PGRpdj48Zm9udCBmYWNlPSJhcmlhbCwgaGVsdmV0aWNhLCBzYW5zLXNlcmlmIj48YnI-PC9mb250PjwvZGl2PjxkaXY-PGZvbnQgZmFjZT0iYXJpYWwsIGhlbHZldGljYSwgc2Fucy1zZXJpZiI-QmVzdCB3aXNoZXMsPC9mb250PjwvZGl2PjxkaXY-PGZvbnQgZmFjZT0iYXJpYWwsIGhlbHZldGljYSwgc2Fucy1zZXJpZiI-PGJyPjwvZm9udD48L2Rpdj48ZGl2Pjxmb250IGZhY2U9ImFyaWFsLCBoZWx2ZXRpY2EsIHNhbnMtc2VyaWYiPkxvdWlzPC9mb250PjwvZGl2PjwvZGl2Pg0K

which an online URL-safe decoder will give as

一个在线的url安全解码器将会提供什么?

<div dir="ltr">Hi,<br><br>I can't install xps because during compile I get:<div><br></div><div><font face="monospace, monospace">TMLMath.cxx:51:19: fatal error: TMath.h: No such file or directory<br></font></div><div><font face="monospace, monospace"><br></font></div><div><div><font face="monospace, monospace"> #include "TMath.h"</font></div><div><font face="monospace, monospace">                   ^</font></div><div><font face="monospace, monospace">compilation terminated.</font></div><div><font face="monospace, monospace">make: *** [TMLMath.o] Error 1</font></div><div><font face="monospace, monospace">ERROR: compilation failed for package ‘xps’</font></div></div><div><br><font face="arial, helvetica, sans-serif">Do you have any idea where I've gone wrong, or how I might fix it? Further details of how I went about it are <a href="https://github.com/lmmx/devnotes/wiki/Installing-CERN's-ROOT-framework">here</a> and full screenshot attached.</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">I tried manually adding in the files the error message said were missing, but eventually it gave a different kind of error and I deleted these additional files again (see the link above).</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">I hope you may be able to advise, I've run out of ideas and expertise on how else to proceed.</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">Best wishes,</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">Louis</font></div></div>

我不能安装xps,因为在编译过程中,我得到了:


< /div>< /div>< font face="monospace, monospace">TMLMath。cxx:51:19:致命错误:TMath。h:没有这样的文件或目录
>< /font face="monospace, monospace">< /font> < span style = ' font - size: 9.0 pt; font - family:宋体;h”< / font > < / div > < div > <字体=“等宽字体,等宽字体”> ^ < / font > < / div > < div > <字体=“等宽字体,等宽字体”> 编译终止。项目名称: < span" tahoma ", " sans-serif"; mso - fareast - font - family:宋体;mso - bidi - font - family: " times new roman "; mso - bidi - font - family: " times new roman "; mso - bidi - font - family: " times new roman ";关于我如何进行的更多细节是 和完整的屏幕截图。我试着在文件中添加了错误信息,但最终它给出了另一种错误,我再次删除了这些附加文件(参见上面的链接)。>

The RCurl function gives a truncated and patchy decoding:

RCurl函数给出了一个截断和不完整的解码:

<div dir=\"lt\001ȈHi,<br><br>I can't install xps because during compile I get:<d\001\xa5\xd8<br></div><d\001\xa5\xd8<font face=\"monospace, monospace\">TMLMath.cxx:51:19: fatal error: TMath.h: No such file or directory<br></fo\001\xb9\xd0</d\001\xa5\xd8<div><font face=\"monospace, monospac\001\x94\x88<br></font></div><div><d\001\xa5\xd8<font face=\"monospace, monospace\"> #include "TMath.h"</font></div><div><font face=\"monospace, monospace\"> ^</fo\001\xb9\xd0</d\001\xa5\xd8<div><font face=\"monospace, monospac\001\x94\x88compilation terminated.</fo\001\xb9\xd0</d\001\xa5\xd8<div><font face=\"monospace, monospac\001\x94\x88make: *** [TMLMath.o] Error 1</fo\001\xb9\xd0</d\001\xa5\xd8<div><font face=\"monospace, monospac\001\x94\x88ERROR: compilation failed for package ‘xps’</fo\001\xb9\xd0</d\001\xa5\xd8</d\001\xa5\xd8<div><\001\x89\xc8<font face=\"arial, helvetica, sans-seri\001\x98\x88Do you have any idea where I've gone wrong, or how I might fix it? Further details of how I went about it are <a href=\"https://github.com/lmmx/devnotes/wiki/Installing-CERN's-ROOT-framework\">here<

< div dir = \ " lt \ 001Ȉhi,< br > < br >我不能安装xps,因为在编译:< d \ 001 \ xa5 \ xd8 < br > < / div > < d \ 001 \ xa5 \ xd8 <字体= \ "等宽字体,等宽字体\ "> TMLMath。cxx:51:19:致命错误:TMath。h:没有这样的文件或目录
. " tahoma ", " sans - serif "; mso - fareast - font - family:宋体;mso - bidi - font - family: " times new roman "; mso - bidi - theme - font: minor - bidi ' > < span < / span >< span style = ' font - size: 9.0 pt; font - family:宋体;mso - ascii - font - family: tahoma;1 . < span lang = en - us style = ' font - size: 9.0 pt; font - family:宋体;mso - fareast - font - family:宋体;mso - fareast - theme - font: minor - fareast; mso - bidi - font - family: " tahoma ", " sans- serif ";关于我如何进行的更多细节是 "

While the online base64 decoder I was using won't decode it at all, reporting an error.

虽然我使用的在线base64解码器不会解码,但报告一个错误。

I'll have to write something to use a custom alphabet myself if noone knows a way to do this with existing R packages. I'd prefer not to have to invoke Python, if possible.

如果没有人知道如何使用现有的R包,我将不得不编写一些东西来使用自定义字母表。如果可能的话,我希望不需要调用Python。

1 个解决方案

#1


2  

Well... that was embarrassingly easy.

嗯…这是尴尬的容易。

base64Decode(gsub("-","+",gsub("/","_",strtodecode)))

base64Decode(gsub(“-”、“+”、gsub(“/”、“_”strtodecode)))

Sorry to answer my own question, it seems way more complicated than it is

很抱歉回答我自己的问题,看起来比实际要复杂得多。

Edit this actually has to be base64Decode(gsub("-","+",gsub("_","/",strtodecode))) for the case I'm working on, but for an example the above worked - there are multiple base64 alphabets.

编辑这个实际上必须是base64Decode(gsub(“-”,“+”,gsub(“_”,“/”,strtodecode))对于我正在进行的这个例子,但是对于上面的例子,有多个base64 alphabets。

#1


2  

Well... that was embarrassingly easy.

嗯…这是尴尬的容易。

base64Decode(gsub("-","+",gsub("/","_",strtodecode)))

base64Decode(gsub(“-”、“+”、gsub(“/”、“_”strtodecode)))

Sorry to answer my own question, it seems way more complicated than it is

很抱歉回答我自己的问题,看起来比实际要复杂得多。

Edit this actually has to be base64Decode(gsub("-","+",gsub("_","/",strtodecode))) for the case I'm working on, but for an example the above worked - there are multiple base64 alphabets.

编辑这个实际上必须是base64Decode(gsub(“-”,“+”,gsub(“_”,“/”,strtodecode))对于我正在进行的这个例子,但是对于上面的例子,有多个base64 alphabets。