2018-10-24 23:03
浏览 172


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.

图片转代码服务由CSDN问答提供 功能建议

因此,我一直在尝试从C转换一些数据以进行压缩并发送到位于golang中的库中 \唯一的问题是,它们彼此之间的实现似乎略有不同。

我所做的是使用C语言中的“ zlib.h”库来压缩字符串 “ hello”,其结果是

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

在golang中输入相同的字符串“ hello”会产生

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

我的问题是,是否有办法使这些输出相似,这是什么? 还是至少可以在zlib中解压缩C中的压缩数据?


  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

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.

    解决 无用
    打赏 举报

相关推荐 更多相似问题