help with zlib compressed base64 data

xuanbao · · 648 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Hi, </p> <p>I&#39;m working with data from mass spectrometers, the peak information is encoded as the example below:</p> <pre><code>&lt;peaks compressionType=&#34;zlib&#34; compressedLen=&#34;15843&#34; precision=&#34;64&#34; byteOrder=&#34;network&#34; contentType=&#34;m/z-int&#34;&gt;eJwtnWV4VEcXgCFBg2uxDwkOxaVYaS4ubaG4FIcWb5FSiGezG7eNYW(...)&#34; &lt;/peaks&gt; </code></pre> <p>I did managed to convert the base64 strings from uncompressed data (code not shown), but I&#34;m not sure how to convert zlib compressed data, I&#39;m trying something like this:</p> <pre><code>b := bytes.NewReader(contentTypeValue) r, err := zlib.NewReader(b) if err != nil { panic(err) } </code></pre> <p>And this is the output:</p> <pre><code>panic: zlib: invalid header </code></pre> <p>I would appreciate any help on this.</p> <p>Thanks</p> <hr/>**评论:**<br/><br/>Fwippy: <pre><p>You&#39;ll want to convert from base64 representation to real bytes before passing it to zlib.</p> <p>Between your first two lines; some sort of <code>b64 := base64.NewDecoder(base64.StdEncoding, b)</code> (and then using <code>b64</code> as input to a zlib reader).</p></pre>prvst: <pre><p>OK, that resolved the invalid header issue, but now i have a *zlib.reader ... I tried to follow the example on the documentation using:</p> <pre><code>io.Copy(os.Stdout, r) </code></pre> <p>but that only prints a lot of wired characters</p></pre>threemux: <pre><p>are the bytes returned by these mass spectrometers supposed to be human-readable? Your terminal is interpreting the returned bytes as a human-readable string. If the data is in some binary format, it will be garbled. </p></pre>prvst: <pre><p>Yes, the converted data should be readable. This is an example of what I&#39;m expecting to see:</p> <pre><code>[300.0619812011719 7323.220703125 300.2615661621094 876.9365234375 300.2973937988281 768.793701171875 300.9573059082031 3332.693603515625 301.0588684082031 (...)] </code></pre> <p>This is an array of floats, it corresponds to detected events and their intensities. I can actually get here when dealing with uncompressed base64 data.</p></pre>threemux: <pre><p>Ok, it might be worth a try to use ioutil.ReadAll to get everything the reader has in a []byte and then do a fmt.Println(string(b)) and see if that makes a difference. </p> <p>Edit: I don&#39;t typically recommend the use of ReadAll, but for debugging it&#39;s very useful</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

648 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传