<p>Hi, </p>
<p>I'm working with data from mass spectrometers, the peak information is encoded as the example below:</p>
<pre><code><peaks compressionType="zlib"
compressedLen="15843"
precision="64"
byteOrder="network"
contentType="m/z-int">eJwtnWV4VEcXgCFBg2uxDwkOxaVYaS4ubaG4FIcWb5FSiGezG7eNYW(...)"
</peaks>
</code></pre>
<p>I did managed to convert the base64 strings from uncompressed data (code not shown), but I"m not sure how to convert zlib compressed data, I'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'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'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't typically recommend the use of ReadAll, but for debugging it's very useful</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传