Zlib :: DataError:不正确的标头检查

时间:2015-07-08 06:24:49

标签: ruby base64 zlib compression

我有一个字符串,但我不知道编码的类型。

这是原始数据的样子:

{
   "securityProxyResponseEnvelope":{
      "resultCode":"OK",
      "apiResponse":"{zlibe}9mtdE350h9rd4h7wlFX3AkeCtNsb40FFaEZAl/CfcNNKrhGXawhgAs2rI4rnEgIwLpgJkKl+qkB0kzJ6+ZFmmz12Pl9/9MPdA1unUKL5OdHcWmAZim3ZjDXFGCW4zruCS/IOSiU1qVKAF5qIbocB4+2rAF7zH18SRtmXM8YW3eYs5w1NPjmYkM31W8x7QvrKkzFscH3kqDwmYn0I2gNNOtfwuKjWd5snunyqxPopZHNX3CBdW/pj4+N0tJXjAoHorCe8Ypmjxnvh3zthkLTbiBLgeULH1hGvVtkI0C9PGMyt/92upVW6qHxqCYoO/LTJK1tq6OpBnMRBNZDDntSRkrzp+1RpvzbBxFtwQ9jh45eSthbG5hq+D2oJkW5zrGi6TM8eG4ztCqRoO9dEvz2JbQsDCTPz70+C6iPYdkvOyqji18ysLjBbGcHw1j45YItcurVxp0FChxXrnHZwu6m430xKEp7ONxvgEZurt3T8qAjrkrbHfd8jRjDydUXYsMoa",
      "session":"n3qp6jzHwZkXWSMW3VBF:jitqBjBmlZbrgcEgY7Od",
      "parameters":{

      }
   }
}

我想在data['securityProxyResponseEnvelope']['apiResponse']中解压缩字符串。

这就是我正在做的事情:

@clear_string_from_data = '9mtdE350h9rd4h7wlFX3AkeCtNsb40FFaEZAl/CfcNNKrhGXawhgAs2rI4rnEgIwLpgJkKl+qkB0kzJ6+ZFmmz12Pl9/9MPdA1unUKL5OdHcWmAZim3ZjDXFGCW4zruCS/IOSiU1qVKAF5qIbocB4+2rAF7zH18SRtmXM8YW3eYs5w1NPjmYkM31W8x7QvrKkzFscH3kqDwmYn0I2gNNOtfwuKjWd5snunyqxPopZHNX3CBdW/pj4+N0tJXjAoHorCe8Ypmjxnvh3zthkLTbiBLgeULH1hGvVtkI0C9PGMyt/92upVW6qHxqCYoO/LTJK1tq6OpBnMRBNZDDntSRkrzp+1RpvzbBxFtwQ9jh45eSthbG5hq+D2oJkW5zrGi6TM8eG4ztCqRoO9dEvz2JbQsDCTPz70+C6iPYdkvOyqji18ysLjBbGcHw1j45YItcurVxp0FChxXrnHZwu6m430xKEp7ONxvgEZurt3T8qAjrkrbHfd8jRjDydUXYsMoa'

@decoded = Base64.decode64(@clear_string_from_data)
@inflated = Zlib::Inflate.inflate(@decoded)

但是这会返回

#=> Zlib::DataError: incorrect header check

造成这种情况的原因是什么,我可以尝试下一步解压缩数据?

2 个答案:

答案 0 :(得分:0)

导致它的原因是它不是zlib数据。您应该询问是谁生成原始数据。

答案 1 :(得分:0)

当我试图对未被Zlib收集的数据调用inflate时,我得到了这个。在我的情况下,这是一个单元测试,我发送一个简单的字符串,只是忘了先打电话.deflate。

在您的情况下,如果您这样做,则不会收到错误:

@decoded = Zlib::Deflate.deflate(@clear_string_from_data) @inflated = Zlib::Inflate.inflate(@decoded)