Issue #13094 has been updated by jeremyevans0 (Jeremy Evans).


I've added a pull request to zlib to document this difference in #gets behavior: https://github.com/ruby/zlib/pull/18

----------------------------------------
Bug #13094: Zlib::GzipReader eof?がfalseなのにgetsでnilが返ってくる
https://bugs.ruby-lang.org/issues/13094#change-87537

* Author: iehn (Hironao TSUTSUMIDA)
* Status: Open
* Priority: Normal
* ruby -v: ruby 2.4.0preview2 (2016-09-09 trunk 56129) [x86_64-darwin15]
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
下記のように、eof?がfalseであればgetsでnilが返ってくることはないことを期待してるとエラーが起きてしまいます。
zlibでeof?は非推奨でしょうか?

~~~ ruby
require 'zlib'
o = ('!'..'~').to_a
i = 225
1000.times do
  Zlib::GzipWriter.open('./s.gz') do |gz|
    i.times do
      gz.write(o.sample(10)*""+"\n")
    end
  end
  Zlib::GzipReader.open("./s.gz") { |gz| puts gz.gets.chomp! until gz.eof? }
  puts "#{i}, #{File.size('./s.gz')}"
  if File.size('./s.gz') > 2058
    i -= 1
  else
    i += 1
  end
end
~~~

~~~ ruby
-:10:in `block (2 levels) in <main>': undefined method `chomp!' for nil:NilClass (NoMethodError)
	from -:10:in `open'
	from -:10:in `block in <main>'
	from -:4:in `times'
	from -:4:in `<main>'
~~~

---Files--------------------------------
s.gz (2.01 KB)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>