Compressed output differs from Go to Ruby Implementation

前端 未结 1 608
时光说笑
时光说笑 2021-01-27 11:37

I\'m implementing a program that deflates a file into a git blob and stores it appropriately.

I have a ruby reference implementation that\'s based on an article from the

1条回答
  •  执笔经年
    2021-01-27 12:05

    The deflate algorithm as defined in RFC 1951 (which is used in the zlib format defined by RFC 1950 and also in gzip defined by RFC 1952) allows variations in the implementation which might lead to different results when compressing. But these results will still decompress to the same value. This allows for a tradeoff of compression time to compression level and makes also programs like zopfli possible which achieve better compression than the original zlib library (at the cost of significantly larger compression time).

    Go uses its own implementation of the deflate algorithm written in Go while ruby uses the zlib library. This is the reason your examples create different compressed output on the same input. But if you take the output from the Go or Ruby program and decompress (no matter if done with Ruby or Go or whatever standard-conforming implementation) it again it will result in exactly the same value.

    0 讨论(0)
提交回复
热议问题