doutidi5037 2018-10-24 23:03
浏览 182
已采纳

我如何使用zlib在C中压缩并在golang中解压缩

So I have been trying to convert some data from C to be compressed and sent to a library which is in golang where it will be decompressed. only issue is, they seem to be slightly different implementations from each other.

What i did was to use "zlib.h" library from C to compress the string "hello" which resulted in bytes of

[120 156 203 72 205 201 201 103 32 5]

while in golang for the same string "hello" results in an array of

[120 156 202 72 205 201 201 7 4 0 0 255 255 6 44 2 21]

My question is if there is a way to make these outputs similar , what is it? or at the very least can a compressed data in C be decompressed in zlib?

I've also looked at How can I use zlib in golang to cooperate with zlib in c? but i'm looking for something more specific like an example.

  • 写回答

1条回答 默认 最新

  • douyuan3842 2018-10-24 23:38
    关注

    Comparing compressed data tells you nothing. Different compressors, or different versions of the same compressor, or the same version used with different settings, can all give different compressed output for the same input. What actually matters for a lossless compressor is whether you can decompress to the original data.

    The problem with your first example is that it is not complete. (The second example is complete and correct.) The first example ends in the middle of a deflate block. There is an error in your usage of zlib, either in managing the resulting data or not properly requesting the completion of the compression.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效