diff options
author | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-10-12 13:52:37 +0000 |
---|---|---|
committer | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-10-12 13:52:37 +0000 |
commit | 9994d05b7e9b1977637bdf2e4c12883132c76d09 (patch) | |
tree | 5c6ef7659cc7c2855364477ef289cdc7bb7fe6ec | |
parent | 7a063b7416509b9f8e7ba3cfc5169a04fe021c32 (diff) | |
download | ruby-9994d05b7e9b1977637bdf2e4c12883132c76d09.tar.gz |
* lib/net/ftp.rb (retrlines): added a new block parameter.
* lib/net/ftp.rb (gettextfile): preserve missing end-of-line at end
of files. [ruby-core:24590]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25310 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | lib/net/ftp.rb | 16 |
2 files changed, 13 insertions, 10 deletions
@@ -1,3 +1,10 @@ +Mon Oct 12 22:48:25 2009 Shugo Maeda <shugo@ruby-lang.org> + + * lib/net/ftp.rb (retrlines): added a new block parameter. + + * lib/net/ftp.rb (gettextfile): preserve missing end-of-line at end + of files. [ruby-core:24590] + Mon Oct 12 19:48:33 2009 Nobuyoshi Nakada <nobu@ruby-lang.org> * eval.c (ruby_run_node): if an exception occurred in ruby_option, diff --git a/lib/net/ftp.rb b/lib/net/ftp.rb index 40227b69d8..1641f04a3c 100644 --- a/lib/net/ftp.rb +++ b/lib/net/ftp.rb @@ -445,12 +445,7 @@ module Net loop do line = conn.gets break if line == nil - if line[-2, 2] == CRLF - line = line[0 .. -3] - elsif line[-1] == ?\n - line = line[0 .. -2] - end - yield(line) + yield(line.sub(/\r?\n\z/, ""), !line.match(/\n\z/).nil?) end conn.close voidresp @@ -570,10 +565,11 @@ module Net result = "" end begin - retrlines("RETR " + remotefile) do |line| - f.puts(line) if localfile - yield(line) if block_given? - result.concat(line + "\n") if result + retrlines("RETR " + remotefile) do |line, newline| + l = newline ? line + "\n" : line + f.print(l) if localfile + yield(line, newline) if block_given? + result.concat(l) if result end return result ensure |