* lib/net/ftp.rb: (getbinaryfile): allow nil for localfile, and
returns retrieved data if localfile is nil. * lib/net/ftp.rb: (gettextfile): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9394 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
190909c0ce
commit
65867866a8
@ -1,3 +1,10 @@
|
|||||||
|
Sat Oct 15 23:52:07 2005 Shugo Maeda <shugo@ruby-lang.org>
|
||||||
|
|
||||||
|
* lib/net/ftp.rb: (getbinaryfile): allow nil for localfile, and
|
||||||
|
returns retrieved data if localfile is nil.
|
||||||
|
|
||||||
|
* lib/net/ftp.rb: (gettextfile): ditto.
|
||||||
|
|
||||||
Sat Oct 15 19:51:29 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
|
Sat Oct 15 19:51:29 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
|
||||||
|
|
||||||
* bin/erb: typo fixed, again. thanks, Doug Kearns.
|
* bin/erb: typo fixed, again. thanks, Doug Kearns.
|
||||||
|
@ -507,11 +507,14 @@ module Net
|
|||||||
|
|
||||||
#
|
#
|
||||||
# Retrieves +remotefile+ in binary mode, storing the result in +localfile+.
|
# Retrieves +remotefile+ in binary mode, storing the result in +localfile+.
|
||||||
|
# If +localfile+ is nil, returns retrieved data.
|
||||||
# If a block is supplied, it is passed the retrieved data in +blocksize+
|
# If a block is supplied, it is passed the retrieved data in +blocksize+
|
||||||
# chunks.
|
# chunks.
|
||||||
#
|
#
|
||||||
def getbinaryfile(remotefile, localfile = File.basename(remotefile),
|
def getbinaryfile(remotefile, localfile = File.basename(remotefile),
|
||||||
blocksize = DEFAULT_BLOCKSIZE, &block) # :yield: data
|
blocksize = DEFAULT_BLOCKSIZE) # :yield: data
|
||||||
|
result = nil
|
||||||
|
if localfile
|
||||||
if @resume
|
if @resume
|
||||||
rest_offset = File.size?(localfile)
|
rest_offset = File.size?(localfile)
|
||||||
f = open(localfile, "a")
|
f = open(localfile, "a")
|
||||||
@ -519,31 +522,45 @@ module Net
|
|||||||
rest_offset = nil
|
rest_offset = nil
|
||||||
f = open(localfile, "w")
|
f = open(localfile, "w")
|
||||||
end
|
end
|
||||||
begin
|
elsif !block_given?
|
||||||
f.binmode
|
result = ""
|
||||||
retrbinary("RETR " + remotefile, blocksize, rest_offset) do |data|
|
|
||||||
f.write(data)
|
|
||||||
yield(data) if block
|
|
||||||
end
|
end
|
||||||
|
begin
|
||||||
|
f.binmode if localfile
|
||||||
|
retrbinary("RETR " + remotefile, blocksize, rest_offset) do |data|
|
||||||
|
f.write(data) if localfile
|
||||||
|
yield(data) if block_given?
|
||||||
|
result.concat(data) if result
|
||||||
|
end
|
||||||
|
return result
|
||||||
ensure
|
ensure
|
||||||
f.close
|
f.close if localfile
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Retrieves +remotefile+ in ASCII (text) mode, storing the result in
|
# Retrieves +remotefile+ in ASCII (text) mode, storing the result in
|
||||||
# +localfile+. If a block is supplied, it is passed the retrieved data one
|
# +localfile+.
|
||||||
|
# If +localfile+ is nil, returns retrieved data.
|
||||||
|
# If a block is supplied, it is passed the retrieved data one
|
||||||
# line at a time.
|
# line at a time.
|
||||||
#
|
#
|
||||||
def gettextfile(remotefile, localfile = File.basename(remotefile), &block) # :yield: line
|
def gettextfile(remotefile, localfile = File.basename(remotefile)) # :yield: line
|
||||||
|
result = nil
|
||||||
|
if localfile
|
||||||
f = open(localfile, "w")
|
f = open(localfile, "w")
|
||||||
|
elsif !block_given?
|
||||||
|
result = ""
|
||||||
|
end
|
||||||
begin
|
begin
|
||||||
retrlines("RETR " + remotefile) do |line|
|
retrlines("RETR " + remotefile) do |line|
|
||||||
f.puts(line)
|
f.puts(line) if localfile
|
||||||
yield(line) if block
|
yield(line) if block_given?
|
||||||
|
result.concat(line + "\n") if result
|
||||||
end
|
end
|
||||||
|
return result
|
||||||
ensure
|
ensure
|
||||||
f.close
|
f.close if localfile
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user