mirror of
https://github.com/ruby/ruby.git
synced 2025-09-15 08:33:58 +02:00
* lib/net/ftp.rb (gettextfile, getbinaryfile): use the safe
navigation operator. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52239 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
1d3c07633c
commit
3eabc555cb
3 changed files with 147 additions and 15 deletions
|
@ -1,5 +1,4 @@
|
|||
#
|
||||
# -*- frozen_string_literal: true -*-
|
||||
# frozen_string_literal: true
|
||||
#
|
||||
# = net/ftp.rb - FTP Client Library
|
||||
#
|
||||
|
@ -601,7 +600,8 @@ module Net
|
|||
# chunks.
|
||||
#
|
||||
def getbinaryfile(remotefile, localfile = File.basename(remotefile),
|
||||
blocksize = DEFAULT_BLOCKSIZE) # :yield: data
|
||||
blocksize = DEFAULT_BLOCKSIZE, &block) # :yield: data
|
||||
f = nil
|
||||
result = nil
|
||||
if localfile
|
||||
if @resume
|
||||
|
@ -615,15 +615,15 @@ module Net
|
|||
result = String.new
|
||||
end
|
||||
begin
|
||||
f.binmode if localfile
|
||||
f.?binmode
|
||||
retrbinary("RETR #{remotefile}", blocksize, rest_offset) do |data|
|
||||
f.write(data) if localfile
|
||||
yield(data) if block_given?
|
||||
result.concat(data) if result
|
||||
f.?write(data)
|
||||
block.?(data)
|
||||
result.?concat(data)
|
||||
end
|
||||
return result
|
||||
ensure
|
||||
f.close if localfile
|
||||
f.?close
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -634,7 +634,9 @@ module Net
|
|||
# If a block is supplied, it is passed the retrieved data one
|
||||
# line at a time.
|
||||
#
|
||||
def gettextfile(remotefile, localfile = File.basename(remotefile)) # :yield: line
|
||||
def gettextfile(remotefile, localfile = File.basename(remotefile),
|
||||
&block) # :yield: line
|
||||
f = nil
|
||||
result = nil
|
||||
if localfile
|
||||
f = open(localfile, "w")
|
||||
|
@ -644,13 +646,13 @@ module Net
|
|||
begin
|
||||
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
|
||||
f.?print(l)
|
||||
block.?(line, newline)
|
||||
result.?concat(l)
|
||||
end
|
||||
return result
|
||||
ensure
|
||||
f.close if localfile
|
||||
f.?close
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue