Class: FtpMultipartDownload::Part
- Inherits:
-
Object
- Object
- FtpMultipartDownload::Part
- Defined in:
- lib/ftp_multipart_download/part.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
-
#download(remotefile, localfile, blocksize, offset, limit) ⇒ Object
download a part of file.
-
#initialize(connection) ⇒ Part
constructor
A new instance of Part.
Constructor Details
#initialize(connection) ⇒ Part
Returns a new instance of Part.
7 8 9 |
# File 'lib/ftp_multipart_download/part.rb', line 7 def initialize(connection) @connection = connection end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
3 4 5 |
# File 'lib/ftp_multipart_download/part.rb', line 3 def connection @connection end |
Instance Method Details
#download(remotefile, localfile, blocksize, offset, limit) ⇒ Object
download a part of file.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ftp_multipart_download/part.rb', line 19 def download(remotefile, localfile, blocksize, offset, limit) old_resume, connection.resume = connection.resume, true File.open(localfile, 'wb') do |f| retrieved = 0 connection.retrbinary("RETR #{remotefile}", blocksize, offset) do |chunk| retrievable = [limit - retrieved, chunk.bytesize].min break if retrievable <= 0 retrieved += f.write(chunk[0, retrievable]) end end ensure connection.resume = old_resume end |