doujuan9698 2014-04-21 16:37
浏览 126
已采纳

Golang:无法使用lzw软件包解压缩数据

I'm trying to create compressed string pool with Go. This is my code - http://play.golang.org/p/T5usLfU0fA

I can't decompress what have bin compressed with compress/lzw package. The input to the lzw.Writer is [104 101 108 108 111 32 119 111 114 108 100] and the output of the lzw.Reader is [0 1 0 0 3 0 3 3 2 0 0]. They definitely doesn't match.

I'm creating reader and writer with the same parameters (all except buffer). Buffer for lzw.Reader contains data, previously compressed with lzw.Writer.

  • 写回答

1条回答 默认 最新

  • duanpasi6287 2014-04-21 18:52
    关注

    Change your litWidth parameter for lzw.NewReader and lzw.NewWriter from 2 to 8.

    I don't know much about LZW, but it looks like the litWidth determines how many bits from each incoming byte are considered significant. So, a value of 2 means that all input bytes must be 0x00 - 0x03.

    See http://play.golang.org/p/svjeVFntuE for a minimal example of an LZW round-trip. A litWidth of 7 works (but is presumably not safe for UTF-8 text), anything less than 7 fails.

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

报告相同问题?

悬赏问题

  • ¥15 ssh登录页面的问题
  • ¥60 渗透一个指定银行app,拿到客户信息,需要什么级别
  • ¥50 关于在matlab上对曲柄摇杆机构上一点的运动学仿真
  • ¥15 jetson nano
  • ¥15 :app:debugCompileClasspath'.
  • ¥15 windows c++内嵌qt出现数据转换问题。
  • ¥20 公众号如何实现点击超链接后自动发送文字
  • ¥15 用php隐藏类名和增加类名
  • ¥15 算法设计与分析课程的提问
  • ¥15 用MATLAB汇总拟合图