<p>So i am trying to figure out some why to detect if data downloaded from a website using Get is base64 encoded or not. How could i do this in Go?</p>
<hr/>**评论:**<br/><br/>TheMerovius: <pre><p><a href="http://play.golang.org/p/RnEBFCJ9h0" rel="nofollow">Try to decode it. If it error's, it's invalid.</a></p></pre>unique10983240197249: <pre><p>This seems to be the pretty straightforward Go way of doing things.</p></pre>captncraig: <pre><p>perhaps a regex match for valid base 64 chars (alphanumeric, <code>+</code> and <code>/</code>.Whether or not it means anything is up to you from there.</p>
<p>You could also try to decode with the base64 package. If the input contains invalid base64 chars it will return an error. </p>
<p>Why are you downloading unknown data?</p></pre>IntellectualReserve: <pre><p>Link to the data/website?</p></pre>bo-banane: <pre><p>I'd go for http headers, or doesn't the server tell you what it's sending? Not sure if there's a content transfer encoding header in http as there is in mail.</p>
<p>I'm on mobile, so sorry if this doesn't actually exist.</p></pre>martingxx: <pre><p>The last 2 bits of every byte will be zero.</p></pre>anacrolix: <pre><p>I think you mean the 2 most significant bits, and it isn't true anyway. Recommend you look up base64 it's worth being familiar with it.</p></pre>uncle_bad_touches: <pre><p>Check the Content-Transfer-Encoding header. It should indicate base64 encoding or not.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
0 回复
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传