1 # Hack ActionController::Streaming to allow streaming from a file handle
 
   2 module ActionController
 
   4     alias_method :old_send_file, :send_file
 
   6     def send_file(file, options = {})
 
   7       if file.is_a? File or file.is_a? Tempfile
 
   8         options[:length] ||= file.stat.size
 
   9         options[:filename] ||= File.basename(file.path) unless options[:url_based_filename]
 
  10         send_file_headers! options
 
  12         @performed_render = false
 
  15           render :status => options[:status], :text => Proc.new { |response, output|
 
  16             logger.info "Streaming file #{file.path}" unless logger.nil?
 
  17             len = options[:buffer_size] || 4096
 
  18             while buf = file.read(len)
 
  23           logger.info "Sending file #{file.path}" unless logger.nil?
 
  24           render :status => options[:status], :text => file.read
 
  27         old_send_file(file, options)