热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

URL-safebase64解码为R。-URL-safebase64decodingforR

IdontknowifitsjustRbeingnotoriouslyhardtosearchforbutIcantseemtofindaURL-safe

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. 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-b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wgc2Fucy1zZXJpZiI-PGJyPjwvZm9udD48L2Rpdj48ZGl2Pjxmb250IGZhY2U9ImFyaWFsLCBoZWx2ZXRpY2EsIHNhbnMtc2VyaWYiPkkgaG9wZSB5b3UgbWF5IGJlIGFibGUgdG8gYWR2aXNlLCBJJiMzOTt2ZSBydW4gb3V0IG9mIGlkZWFzIGFuZCBleHBlcnRpc2Ugb24gaG93IGVsc2UgdG8gcHJvY2VlZC48L2ZvbnQ-PC9kaXY-PGRpdj48Zm9udCBmYWNlPSJhcmlhbCwgaGVsdmV0aWNhLCBzYW5zLXNlcmlmIj48YnI-PC9mb250PjwvZGl2PjxkaXY-PGZvbnQgZmFjZT0iYXJpYWwsIGhlbHZldGljYSwgc2Fucy1zZXJpZiI-QmVzdCB3aXNoZXMsPC9mb250PjwvZGl2PjxkaXY-PGZvbnQgZmFjZT0iYXJpYWwsIGhlbHZldGljYSwgc2Fucy1zZXJpZiI-PGJyPjwvZm9udD48L2Rpdj48ZGl2Pjxmb250IGZhY2U9ImFyaWFsLCBoZWx2ZXRpY2EsIHNhbnMtc2VyaWYiPkxvdWlzPC9mb250PjwvZGl2PjwvZGl2Pg0K

which an online URL-safe decoder will give as

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

Hi,

I can't install xps because during compile I get:

TMLMath.cxx:51:19: fatal error: TMath.h: No such file or directory

 #include "TMath.h"
                   ^
compilation terminated.
make: *** [TMLMath.o] Error 1
ERROR: compilation failed for package ‘xps’

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 here and full screenshot attached.

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).

I hope you may be able to advise, I've run out of ideas and expertise on how else to proceed.

Best wishes,

Louis

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


TMLMath。cxx:51:19:致命错误:TMath。h:没有这样的文件或目录
>
TMLMath.cxx:51:19: fatal error: TMath.h: No such file or directory
#include "TMath.h"
^<\001\x89\xc8here<


我不能安装xps,因为在编译: 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 ' >

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。


推荐阅读
author-avatar
zhanwang
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有