# IO.copy\_stream doesn't convert encodings

**URL:** <https://www.ruby-forum.com/t/io-copy-stream-doesnt-convert-encodings/167116>\
**Category:** Development\
**Created:** [May 4, 2009, 8:09am UTC](https://www.ruby-forum.com/t/io-copy-stream-doesnt-convert-encodings/167116 "2009-05-04T08:09:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sheepman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d07c76/32.png) [@sheepman](https://www.ruby-forum.com/u/sheepman)\
**Post date:** [May 4, 2009, 8:09am UTC](https://www.ruby-forum.com/t/io-copy-stream-doesnt-convert-encodings/167116/1 "2009-05-04T08:09:27Z")

</div>

e$B$3$s$K$A$Oe(B sheepman e$B$G$9!#e(B

e$BKhEY:Y$+$$$3$H$G62=L$G$9$,!#e(B  
e$B%(%s%3!\<%G%#%s%0$r;XDj$7$Fe(B open e$B$7$?e(B IO  
e$B%\*%V%8%’%/%H$rM?$($F$b!“e(B  
IO.copy\_stream e$B$,%(%s%3!\<%G%#%s%0$rJQ49$7$^$;$s!#e(B  
e$B$3$l$O!”$3$&$$$&$b$N$G$7$g$&$+!#e(B

$ cat t.rb

# coding:euc-jp

i = File.open(‘i.txt’, ‘r:euc-jp’)  
o = File.open(‘o.txt’, ‘w:sjis’)  
IO.copy\_stream(i, o)

$ cat i.txt  
e$B4A;ze(B

$ ruby-1.9 -v t.rb  
ruby 1.9.2dev (2009-05-02 trunk 23326) [i686-linux]

$ nkf --guess o.txt  
EUC-JP

---

<div class="post-metadata">

**Author:** ![sheepman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d07c76/32.png) [@sheepman](https://www.ruby-forum.com/u/sheepman)\
**Post date:** [May 6, 2009, 7:54am UTC](https://www.ruby-forum.com/t/io-copy-stream-doesnt-convert-encodings/167116/2 "2009-05-06T07:54:04Z")

</div>

In article [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid),  
sheepman [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> e$B%(%s%3!\<%G%#%s%0$r;XDj$7$Fe(B open e$B$7$?e(B IO e$B%\*%V%8%'%/%H$rM?$($F$b!“e(B  
> IO.copy\_stream e$B$,%(%s%3!\<%G%#%s%0$rJQ49$7$^$;$s!#e(B  
> e$B$3$l$O!”$3$&$$$&$b$N$G$7$g$&$+!#e(B

e$B$$$^$N$H$3$m$=$&$$$&$b$N$@$H9M$($F$$$^$9!#e(B

e$BM}M3$O$^$:%3%T!\<$9$k$H$$$&$N$OL5JQ49$,4|BT$5$l$F$$$k$3$H$,B?e(B  
e$B$$$H$$$&?dB,$G$9!#e(B

e$B$^$?!“e(Bcopy\_length e$B$K%P%$%H?t$r;XDj$G$-!”%P%$%H?t$r;XDj$9$k%ae(B  
e$B%=%C%I$O%(%s%3!\<%G%#%s%0JQ49$O9T$o$J$$$H$$$&E@$b$"$j$^$9!#e(B

e$B$?$@$7!"A0\<T$O?dB,$G$9$7!“8e\<T$Oe(B IO#read e$B$H$$$&Nc30$b$”$j$^e(B  
e$B$9!#e(B

e$B$b$7!"A0\<T$N?dB,$,@5$7$/$J$/!“JQ49$,4|BT$5$l$F$$$k$3$H$,B?$$e(B  
e$B$H$$$&OC$,$”$l$PJ9$+$;$F$/$@$5$$!#e(B
