[#42624] Ruby インストールできません — 水野 あゆみ <chaaneko@...>
Ruby超初心者です。
9 messages
2006/08/07
[#42629] Re: Ruby インストールできません
— Takahiro Kambe <taca@...>
2006/08/07
In message <20060807042520.90137.qmail@web3002.mail.tnz.yahoo.co.jp>
[#42643] メールのSMTP認証の方法(質問) — "Hisashi Yahata" <yahatah@...>
お世話になります。
34 messages
2006/08/09
[#42645] Re: メールのSMTP認証の方法(質問)
— WATANABE Tetsuya <Tetsuya.WATANABE@...>
2006/08/09
渡辺哲也です。
[#42649] Re: メールのSMTP認証の方法(質問)
— OHARA Shigeki <os@...>
2006/08/09
大原です。
[#42650] Re: メールのSMTP認証の方法(質問)
— "Hisashi Yahata" <yahatah@...>
2006/08/09
大原様
[#42651] Re: メールのSMTP認証の方法(質問)
— 植田裕之 <ueda@...>
2006/08/09
植田と申します。
[#42654] Re: メールのSMTP認証の方法(質問)
— "Hisashi Yahata" <yahatah@...>
2006/08/09
植田 裕之様
[#42655] Re: メールのSMTP認証の方法(質問)
— 植田裕之 <ueda@...>
2006/08/09
植田です。
[#42656] Re: メールのSMTP認証の方法(質問)
— "Hisashi Yahata" <yahatah@...>
2006/08/09
植田様
[#42657] Re: メールのSMTP認証の方法(質問)
— WATANABE Tetsuya <Tetsuya.WATANABE@...>
2006/08/09
渡辺哲也です。
[#42659] Re: メールのSMTP認証の方法(質問)
— Kazuhiro NISHIYAMA <zn@...>
2006/08/09
西山和広です。
[#42664] Re: メールのSMTP認証の方法(質問)
— "Hisashi Yahata" <yahatah@...>
2006/08/10
西山和広様
[#42674] Re: メールのSMTP認証の方法(質問)
— Kazuhiro NISHIYAMA <zn@...>
2006/08/11
西山和広です。
[#42665] 組み合わせを作るrubyらしい方法 — しん <dezawa@...>
出沢です
7 messages
2006/08/10
[#42682] Javaの interfaceのようなもの — Yuumi Yoshida <yuumi3@...>
こんにちは、 yuumi3です。
5 messages
2006/08/13
[#42690] StringScanner と case の相性 & メソッド上書きの方法 — take_tk <ggb03124@...>
たけ(tk)です
7 messages
2006/08/15
[#42691] リンクを抜き出す正規表現について — Yosuke Suzuki <yosuke@...>
suzukiといいます。
10 messages
2006/08/15
[#42693] in演算子の提案 — <rubyist@...>
はじめまして。diceと申します。
8 messages
2006/08/15
[#42715] n次元配列#each_index — Sato Hiroshi <hirocy.f01@...>
hirocyです.
4 messages
2006/08/17
[#42720] ベクターに登録されている Windows 用Rubyバイナリ — KIMURA Koichi <kbk@...>
木村です。
6 messages
2006/08/18
[#42724] エスケープシーケンスの画面制御について — リックス <rubyer4649@...>
りっくすです
7 messages
2006/08/19
[#42737] rexmlでのUTF-16の扱いについて — 石田 三英 <ishida@...>
石田と申します。
9 messages
2006/08/22
[#42758] eval substirution with variable — KIRIYAMA Kazuhiko <kiri@...>
桐山です.
6 messages
2006/08/28
[#42765] ?がメソッド名の途中にあるのはNG? — Daisuke Yamazaki <yamajaki@...>
こんにちは.山崎です.
6 messages
2006/08/29
[ruby-list:42729] [Zlib] File.zreadの提案
From:
rubikitch <rubikitch@...>
Date:
2006-08-20 07:59:40 UTC
List:
ruby-list #42729
るびきちです。
gzip圧縮を自動判別して読み込んでくれる File.zread メソッドがあると嬉しいです。
magicで判別しています。また、open-uriと併用できます。
たとえばopen-uriでURIを開いたときに、
Content-Encoding: gzip
だった場合も含めて透過的に「内容」を読み込めます。
どうでしょうか?
require 'zlib'
require 'open-uri'
Zlib::GZIP_MAGIC = "\037\213"
def File.zread(file)
Object.module_eval do
open(file) do |f|
magic = f.read(2)
if magic == Zlib::GZIP_MAGIC
f.rewind
gz = Zlib::GzipReader.new(f)
begin
gz.read
ensure
gz.close
end
else
magic + f.read
end
end
end
end
require 'test/unit'
class TestZread < Test::Unit::TestCase
def make_file(filename, content)
begin
open(filename, "w"){|f| f.write(content)}
yield
ensure
File.unlink filename
end
end
def make_zfile(filename, content)
begin
Zlib::GzipWriter::open(filename){|f| f.write(content)}
yield
ensure
File.unlink filename
end
end
def test_normal_file
make_file("a.file", "normal"){
assert_equal "normal", File.zread("a.file")
}
end
def test_gzip_file
make_zfile("a.gz", "gzipped"){
assert_equal "gzipped", File.zread("a.gz")
}
end
def test_gzipped_html
make_zfile("a.html", "<html>gzipped</html>"){
assert_equal "<html>gzipped</html>", File.zread("a.html")
}
end
def test_uri_normal
assert_equal '<?xml version="1.0" encoding="iso-2022-jp" ?>',
File.zread("http://www.rubyist.net/~rubikitch/").split(/\n/)[0]
end
def test_uri_gzipped
assert_equal '<HTML>', File.zread("http://2ch.net/")[0,6]
end
end
--
rubikitch
http://www.rubyist.net/~rubikitch/