diff --git a/README.md b/README.md index fc14c02..e91c6a6 100644 --- a/README.md +++ b/README.md @@ -1,29 +1,42 @@ -# Rack::Emstream +# Super-simple Rack streaming with Thin and other EventMachine-based servers -TODO: Write a gem description +This is the absolute simplest way to turn any Rack app into a streaming- and deferrable-capable service using Thin. +It handles the necessary async calls to make Thin start streaming, then delivers your +response body on each next tick until sent. If you're sending something big, make sure it responds to `each` +in chunks: -## Installation +``` ruby +class FileStreamer + def initialize(file) + @file = file + end -Add this line to your application's Gemfile: + def each + while !@file.eof? + yield @file.read(8192) + end + end +end - gem 'rack-emstream' +# then respond with a FileStreamer -And then execute: +def call(env) + # ... do stuff ... - $ bundle + [ 200, {}, FileStreamer.new(File.open('big-file.mpg')) ] +end +``` -Or install it yourself as: +Nothing to configure, just drop it in to your Rack middleware stack and +use Thin as your server: - $ gem install rack-emstream +``` ruby +# for Rails: -## Usage +config.middleware.insert_before(::Rack::Lock, ::Rack::EMStream) -TODO: Write usage instructions here +# for Rack::Builder and derivatives: -## Contributing +use Rack::EMStream +``` -1. Fork it -2. Create your feature branch (`git checkout -b my-new-feature`) -3. Commit your changes (`git commit -am 'Added some feature'`) -4. Push to the branch (`git push origin my-new-feature`) -5. Create new Pull Request diff --git a/lib/rack-emstream/version.rb b/lib/rack-emstream/version.rb index 991ea1d..5ceb349 100644 --- a/lib/rack-emstream/version.rb +++ b/lib/rack-emstream/version.rb @@ -1,5 +1,5 @@ module Rack - module Emstream - VERSION = "0.0.1" + module EMStream + VERSION = "0.1.0" end end diff --git a/lib/rack/emstream.rb b/lib/rack/emstream.rb new file mode 100644 index 0000000..8fa343f --- /dev/null +++ b/lib/rack/emstream.rb @@ -0,0 +1 @@ +require 'rack-emstream' diff --git a/rack-emstream.gemspec b/rack-emstream.gemspec index c061d7a..adbc8a0 100644 --- a/rack-emstream.gemspec +++ b/rack-emstream.gemspec @@ -13,7 +13,7 @@ Gem::Specification.new do |gem| gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) gem.name = "rack-emstream" gem.require_paths = ["lib"] - gem.version = Rack::Emstream::VERSION + gem.version = Rack::EMStream::VERSION gem.add_dependency 'eventmachine' end