Bug #1375
closedZlib::GzipReaderに対するエンコーディング指定
Description
=begin
Zlib::GzipReaderでエンコーディングを指定しても効果がないようですが、これはそういうもので、
読んだ結果を適宜エンコーディングするのが正しいやり方でしょうか。
$irb -rzlib --prompt=simple
RUBY_VERSION
=> "1.9.2"
Encoding.default_external
=> #Encoding:UTF-8
gz = Zlib::GzipReader.open('test.txt.gz', 'r:UTF-8')
ArgumentError: wrong number of arguments (2 for 1)
from (irb):3:ininitialize' from (irb):3:in
open'
from (irb):3
from /usr/local/bin/irb:12:in<main>' gz = Zlib::GzipReader.open('test.txt.gz', encoding: 'UTF-8') => #<Zlib::GzipReader:0x2f0800> str = gz.read => "\xE3\x81\x93\xE3\x82\x93\xE3\x81\xAB\xE3\x81\xA1\xE3\x81\xAF\xE4\xB8\x96\xE7\x95\x8C\n" str.force_encoding 'UTF-8' => "こんにちは世界\n" gz.set_encoding 'UTF-8' NoMethodError: undefined method
set_encoding' for #Zlib::GzipReader:0x2f0800
from (irb):5
from /usr/local/bin/irb:12:in `'
=end
Updated by naruse (Yui NARUSE) over 14 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
=begin
Applied in changeset r24704.
=end
Updated by naruse (Yui NARUSE) over 14 years ago
=begin
設定方法は
Zlib::GzipReader.open('test.txt.gz', encoding: 'UTF-8')
であっています。
Zlib::GzipReader#read では設定されたエンコーディングが反映されない、というのがこのバグでした。
=end