Sha256: 6e4df998ea0e5637f0b270d4a651139cb8c217c7c03cea15da8836e6ba9aad34

Contents?: true

Size: 544 Bytes

Versions: 22

Compression:

Stored size: 544 Bytes

Contents

class Rack::App::File::Streamer

  include Enumerable

  def each(&block)
    file { |f| f.each(&block) }
  end

  def render(object=nil)
    file { |f| f.read }
  end

  def mtime(object=nil)
    ::File.mtime(@file_path).httpdate
  end

  def length(object=nil)
    ::Rack::Utils.bytesize(render())
  end

  protected

  def initialize(file_path)
    @file_path = file_path
    @file = File.open(file_path)
  end

  def file(&block)
    @file.reopen(@file_path) if @file.closed?
    return block.call(@file)
  ensure
    @file.close
  end

end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
rack-app-1.4.0 lib/rack/app/file/streamer.rb
rack-app-1.3.0 lib/rack/app/file/streamer.rb
rack-app-1.2.2 lib/rack/app/file/streamer.rb
rack-app-1.2.1 lib/rack/app/file/streamer.rb
rack-app-1.1.0 lib/rack/app/file/streamer.rb
rack-app-1.0.0 lib/rack/app/file/streamer.rb
rack-app-0.24.0 lib/rack/app/file/streamer.rb
rack-app-0.23.0 lib/rack/app/file/streamer.rb
rack-app-0.22.0 lib/rack/app/file/streamer.rb
rack-app-0.21.0 lib/rack/app/file/streamer.rb
rack-app-0.20.0 lib/rack/app/file/streamer.rb
rack-app-0.19.0 lib/rack/app/file/streamer.rb
rack-app-0.18.0 lib/rack/app/file/streamer.rb
rack-app-0.17.0 lib/rack/app/file/streamer.rb
rack-app-0.16.0 lib/rack/app/file/streamer.rb
rack-app-0.15.0 lib/rack/app/file/streamer.rb
rack-app-0.14.0 lib/rack/app/file/streamer.rb
rack-app-0.13.0 lib/rack/app/file/streamer.rb
rack-app-0.12.1 lib/rack/app/file/streamer.rb
rack-app-0.12.0 lib/rack/app/file/streamer.rb