In article [email protected],
“NARUSE, Yui” [email protected] writes:
e$B$"$^$j%W%m%0%i%`$K$,$s$P$i$;$?$/$J$$$J$!$H;W$C$F$$$k$N$G$9$,!“e(B
e$B$$$A$$$A0z?t$rM?$($”$j!"e(BRuby e$B<+BN$,$,$s$P$k$N$b$=$NCf$KF~$ke(B
e$B$H$$$&<gD%$b@.$jN)$D$N$G$7$g$&$M$'!#e(B
Dir e$B$Ne(B internal_encoding, external_encoding e$B$r;H$&$K$O!"%W%me(B
e$B%0%i%`$,JQ$JJ}8~$K$,$s$P$kI,MW$,M-$k$h$&$K;W$($^$9!#e(B
e$B$7$+$7!"<B:]$N$H$3$m!“8=:_<+F0JQ49$,9T$o$l$k$N$Oe(B
Windows e$B$/$i$$$J$o$1$Ge(B (e$B$3$l$b8!F$Cf$G$O$”$ke(B)e$B!"e(B
e$B$?$$$F$$$N>l9g$OF0:n$,JQ$o$i$J$$$o$1$G$9!#e(B
e$B$H$9$k$H!“EDCf$5$s$NDs0F$O!”%G%U%)%k%H$r$b$C$H<+F0JQ49B&$Ke(B
e$BE]$7$?>l9g$K??2A$rH/4x$9$k$N$G$9$+$M!#e(B
e$B$$$$$(!#e(B
e$B$?$H$($P!“$”$k%G%#%l%/%H%j$N3F%U%!%$%k$N%5%$%:$rI=<($9$k$3$He(B
e$B$r9M$($F$_$^$7$g$&!#e(B
% mkdir /tmp/xyz
% cd /tmp/xyz
% ruby -e ‘open(“\x91\x92\x93\x94”, “w”)’
% ls
???
e$B$3$3$G!"%(%s%3!<%G%#%s%0$r;XDj$7$J$1$l$P!"0J2<$N$h$&$K$J$j$^e(B
e$B$9!#e(B
% ruby -e ’
Dir.open(“.”) {|d|
while n = d.read
p [File.size(n), n]
end
}’
[4096, “.”]
[45056, “…”]
[0, “\x91\x92\x93\x94”]
e$B$3$N%W%m%0%i%`$O!“e(BUnix e$B$G$OG$0U$N%U%!%$%kL>$K$D$$$FF0:n$7$^e(B
e$B$9!#$?$H$($P!”>e5-$Ne(B \x91\x92\x93\x94 e$B$G$bF0$-$^$9!#e(B
e$B$7$+$7!“e(BWindows e$B$G!“e(BUnicode
e$B$K$O$”$k$,!”%7%9%F%`%3!<%I%Z!<%8e(B
e$B$G$OI=8=$G$-$J$$J8;ze(B (e$BF|K\8lHGe(B Windows
e$B$N>l9g$G$$$($P!“e(BCP932
e$B$G$OI=8=$G$-$J$$J8;ze(B) e$B$,%U%!%$%kL>$K;H$o$l$F$$$k$H!”$*$=$i$/e(B
e$BF0$+$J$$$G$7$g$&!#e(B
Windows e$B$G$=$&$$$&%U%!%$%kL>$b07$*$&$H9M$($?>l9g!"8=;~E@$G$O!"e(B
Ruby e$B$K$O$=$N$?$a$N5!9=$,F~$C$F$$$J$$$N$G$I$&;XDj$9$k$+$OL@e(B
e$B$i$+$G$OM-$j$^$;$s$,!"2>$K!"e(B:external_encoding=>“utf-16le”
e$B$H$9$k$He(B Unicode e$B$J%U%!%$%kL>$r07$&$h$&$K$J$j!"e(B
:external_encoding=>“utf-16le”, :internal_encoding=>“utf-8”
e$B$H$9$k$H$=$l$re(B UTF-8 e$B$K$7$F$o$?$7$F$/$l$k$7$F$_$^$7$g$&!#e(B
e$B$=$&$9$k$H<!$N$h$&$K$J$j$^$9!#e(B
% ./ruby -e ’
Dir.open(“.”, :external_encoding=>“utf-16le”,
:internal_encoding=>“utf-8”) {|d|
while n = d.read
p [File.size(n), n]
end
}’
-e:3:in read': invalid byte sequence (RuntimeError) from -e:3:in
block in ’
from -e:2:in open' from -e:2:in
’
e$B$7$+$7!“;DG0$J$3$H$K!”$3$l$Oe(B Unix e$B$G$OF0$-$^$;$s!#e(B
e$BD>@\E*$K$O!“>e5-$N%(%i!<$O!“e(B”.” e$B$re(B UTF-16LE e$B$+$ie(B UTF-8
e$B$KJQe(B
e$B49$7$h$&$H$7$FH/@8$7$F$$$^$9!#e(B
e$B$^$?!"2>$KJQ49%(%i!<$,5/$-$J$+$C$?$H$7$F$b!"0lHL$KJQ49$r9T$&e(B
e$B$H%P%$%HNs$,JQ2=$7$^$9!#$7$+$7!“e(BFile.size e$B$O%U%!%$%k$r$A$c$se(B
e$B$HF1Dj$9$kI,MW$,$”$j$^$9!#$H$9$k$H!"5UJQ49$,I,MW$K$J$j$^$9$,!“e(B
e$B0lHL$KJQ49!&5UJQ49$G%P%$%HNs$,e(B round trip e$B$9$kJ]>Z$O$”$j$^$;e(B
e$B$s!#e(B
e$BL@$i$+$J%1!<%9$H$7$F$O!“e(BGB18030 e$B$,$”$2$i$l$^$9!#e(BGB18030
e$B$Oe(B
UTF-8 e$B$N%9!<%Q!<%;%C%H$G$9$+$i!"e(BGB18030 → UTF-8 → GB18030
e$B$G$O85$KLa$i$J$$%1!<%9$,B8:_$7$^$9!#e(B
e$B$=$&$9$k$H!"$3$&$$$&JQ49$r9T$&$N$Oe(B Windows e$B$@$1$K8BDj$9$kI,e(B
e$BMW$,M-$j$^$9!#$=$9$k$H<!$N$h$&$K$J$j$^$9!#e(B
% ./ruby -e ’
opt = /windows/ =~ RUBY_PLATFORM ? {:external_encoding=>“utf-16le”,
:internal_encoding=>“utf-8”} : {}
Dir.open(“.”, opt) {|d|
while n = d.read
p [File.size(n), n]
end
}’
e$B7k6I!“e(BFile.size e$B$O3N<B$K%U%!%$%k$rF1Dj$9$kI,MW$,$”$C$F!"$=$Ne(B
e$BE@$G$OJ8;z%3!<%I$NJQ49$O4pK\E*$K<YKb$G!"Lq2p<T$G$7$+M-$j$^$;e(B
e$B$s!#e(B
e$B$b$A$m$s!“$3$NLdBj$Oe(B File.size e$B$@$1$G$O$J$/$F!”%U%!%$%k$N<Be(B
e$BBN$K%"%/%;%9$9$k$9$Y$F$NA`:ne(B (stat, open, unlink, link, …)
e$B$GLdBj$K$J$j$^$9!#e(B
e$B$=$&$9$k$H!"$d$O$jJQ49$7$F$$$J$$@8$N%U%!%$%kL>$,I,MW$G!"e(B
Unix e$B$G$O%P%$%HNs$=$N$^$^$Ge(B locale e$B$Je(B encoding
e$B$,$D$$$?$b$N!"e(B
Windows e$B$G$Oe(B UTF-8 e$B$J$b$N$rJV$9%*%W%7%g%s$r2>$Ke(B
:native_filename=>true e$B$H$9$k$H!"0J2<$N$h$&$K=q$1$^$9!#e(B
% ruby -e ’
Dir.open(“.”, :native_filename=>true) {|d|
while n = d.read
p [File.size(n), n]
end
}’
e$B$3$3$G$O!“@8$N%U%!%$%kL>$re(B p e$B$GI=<($7$F$$$^$9$,!”$A$c$s$He(B
locale e$B$K=>$C$F%(%s%3!<%I$9$k$J$i!"0J2<$N$h$&$KJQ49$7$^$9!#e(B
(e$B$3$3$GJQ49$K<:GT$7$?$H$-$NBP=h$,I,MW$+$b$7$l$^$;$se(B)
e$B$7$+$7!“e(BFile.size e$B$KEO$9%U%!%$%kL>$OJQ49$7$^$;$s$7!”$7$F$O$$e(B
e$B$1$^$;$s!#e(B
% ruby -e ’
Dir.open(“.”, :native_filename=>true) {|d|
while n = d.read
p [File.size(n), n.encode(Encoding.locale_charmap)]
end
}’
e$B$^$?!"%U%!%$%kL>$rI8=`F~NO$K=P$9$N$G$J$/!“e(BGUI e$B$GI=<($9$k$N$Ge(B
e$B$”$l$P!“e(BGUI
e$B$N07$&%3!<%I$KJQ49$9$kI,MW$,$”$k$G$7$g$&!#$7$+$7!“e(B
e$B$d$O$j$=$N>l9g$G$be(B File.size e$B$KEO$9%U%!%$%kL>$OJQ49$7$^$;$se(B
e$B$7!”$7$F$O$$$1$^$;$s!#e(B
e$B$3$N$h$&$K!“7k6I!”%U%!%$%kL>$r3N<B$K07$&$N$KI,MW$J5!9=$O!"3Ne(B
e$B<B$K%U%!%$%k$rF1Dj$G$-$k%U%!%$%kL>$rF@$k$3$H$G!"J8;z%3!<%I$Ne(B
e$BJQ49$O<YKb$G$9!#e(B
e$BJQ49$OI=<($N:]$KI,MW$K$J$j$^$9$,!“BP>]$,%U%!%$%kL>$G$”$k0J>e!"e(B
e$B%U%!%$%k$,F1Dj$G$-$J$/$J$k$N$O$`$7$mLdBj$,Bg$-$$$H9M$($i$l$^e(B
e$B$9!#e(B
e$B$=$l$J$N$K!"$J$s$G$=$s$J5!9=$re(B Dir e$B$K$D$1$k$s$G$7$g$&e(B?
internal_encoding, external_encoding e$B$C$F!“$I$&$$$&%”%W%j%1!<e(B
e$B%7%g%s$GLr$KN)$D$s$G$7$g$&e(B?
e$BEv;~$O$"$^$jL@<(E*$Ke(B force_encoding / encode e$B$5$;$?$/$J$$$H$$$&<q;]$G$7$?!#e(B
locale e$B$K=>$C$F1?MQ$5$l$F$$$k%7%9%F%`$rA[Dj$9$kMQK!$J$ie(B
e$B8=>u$Ge(B force_encoding e$B$be(B encode e$B$bITMW$G$9!#e(B
e$B$=$&$G$J$$A[Dj$r$9$k$J$i!“e(Binternal_encoding,
external_encoding e$B$,Lr$KN)$D%”%W%j%1!<%7%g%s$C$F$I$&$$$&%1!<e(B
e$B%9$G$7$g$&e(B?
Windows e$B$Ge(B Unicode e$B$J%U%!%$%kL>$r07$&$H$-$@$H$7$F$b!“$=$N=qe(B
e$B$-J}$H$7$F!”%]!<%?%V%k$K$J$i$J$$=q$-J}$rDs0F$9$k$N$O$h$/$J$$e(B
e$B$s$8$c$J$$$G$7$g$&$+!#e(B
internal_encoding, external_encoding e$B$,Lr$KN)$D%"%W%j%1!<%7%ge(B
e$B%s$N6qBNE*$JNc$C$F$J$$$s$G$7$g$&$+e(B?
e$B7k6I$N$H$3$m!"%W%m%0%i%`$G4hD%$i$;$k$Y$-$+!"e(B
e$B@_Dj$N<jCJ$r$9$k$Y$-$+$H$$$&=j$J$N$G$9$+$M$'!#e(B
Dir e$B$K$h$kJQ49$O!"%W%m%0%i%`$rJQ$JJ}8~$K$,$s$P$i$;$k$N$G$O$Je(B
e$B$$$G$7$g$&$+!#e(B
Windows e$B$+$I$&$+$r>r7oH=CG$9$k$H$+!"5UJQ49$,I,MW$K$J$k$H$+!#e(B
e$B$D$^$k$H$3$m!"Nc30$,=P$?;~$N=hM}$NMxJX@-$+e(B
e$B5UJQ49$,2DG=$G$“$k$h$&$J>l9g$K$O!“JQ49$7$F$bLdBj$,$J$$$N$+$be(B
e$B$7$l$^$;$s!#$=$&$$$&0UL#$G!”$3$NLdBj$rJQ49$GNc30$,=P$?$H$-$Ne(B
e$BLdBj$H$$$&$H$i$($+$?$O$”$j$($k$G$7$g$&!#e(B
e$B$7$+$7!“;d$O!”$=$b$=$bJQ49$9$k$N$,LdBj$@$H$H$i$($F$$$^$9!#e(B