Download is a pluggable parser for downloading files without loading them into memory first. You may subclass this class to handle content types you do not wish to load into memory first.
See Mechanize::PluggableParser for instructions on using this class.
Creates a new download retrieved from the given uri and response object. The body_io is an IO-like containing the HTTP response body and code is the HTTP status.
# File lib/mechanize/download.rb, line 30 def initialize uri = nil, response = nil, body_io = nil, code = nil @uri = uri @body_io = body_io @code = code @full_path = false unless defined? @full_path fill_header response extract_filename yield self if block_given? end
The body of this response as a String.
Take care, this may use lots of memory if the response body is large.
# File lib/mechanize/download.rb, line 48 def body @body_io.read.tap { @body_io.rewind } end
Saves a copy of the body_io to filename
# File lib/mechanize/download.rb, line 55 def save filename = nil filename = find_free_name filename save! filename end
Use this method to save the content of body_io to filename. This method will overwrite any existing filename that exists with the same name.
# File lib/mechanize/download.rb, line 67 def save! filename = nil dirname = File.dirname filename FileUtils.mkdir_p dirname open filename, 'wb' do |io| until @body_io.eof? do io.write @body_io.read 16384 end end end
Generated with the Darkfish Rdoc Generator 2.