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.

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

报告相同问题?

悬赏问题

  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样