【发布时间】:2017-02-08 19:40:49
【问题描述】:
我正在尝试使用zlib 和jruby 解码压缩后的字符串。这是最小的工作示例。
require 'stringio'
require 'zlib'
str = 'H4sIAAAAAAAA/y2NwQrDIBAFfyXstUbWNWrir5RSrEoQUi2JOZSQf6+EHt8wzDtgKd7VVPIG9n7AMwWwYhj1MBkkwtEwcN7vq/NfsAo5MnhFt6Y8g71WcDXW9I5ggVCYHqlH0xE12RJ1N5SIwGBpJ3UPTVOKa41IssGS5z+Vhhs1SdHo9okxXPXzcf4AY45Ve6EAAAA='
input = StringIO.new(str)
puts Zlib::GzipReader.new(input).read
这是我得到的输出
/Users/duke/.rvm/rubies/jruby-1.7.23/bin/jruby --1.9 -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /Users/duke/RubymineProjects/untitled/gzip_test.rb
Zlib::GzipFile::Error: not in gzip format
initialize at org/jruby/ext/zlib/JZlibRubyGzipReader.java:156
new at org/jruby/ext/zlib/JZlibRubyGzipReader.java:85
(root) at /Users/duke/RubymineProjects/untitled/gzip_test.rb:6
load at org/jruby/RubyKernel.java:1059
(root) at -e:1
Process finished with exit code 1
压缩后的字符串是有效的。你可以在这里试试http://www.txtwizard.net/compression
【问题讨论】:
标签: ruby gzip jruby zlib decoding