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 30: def initialize uri = nil, response = nil, body_io = nil, code = nil 31: @uri = uri 32: @body_io = body_io 33: @code = code 34: 35: @full_path = false unless defined? @full_path 36: 37: fill_header response 38: extract_filename 39: 40: yield self if block_given? 41: 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 48: def body 49: @body_io.read.tap { @body_io.rewind } 50: end
Saves a copy of the body_io to filename
# File lib/mechanize/download.rb, line 55 55: def save filename = nil 56: filename = find_free_name filename 57: 58: dirname = File.dirname filename 59: FileUtils.mkdir_p dirname 60: 61: open filename, 'wb' do |io| 62: until @body_io.eof? do 63: io.write @body_io.read 16384 64: end 65: end 66: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.