From 14ce889cc12628405b0f6a1842b7e1ad09ca4b7b Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 27 Jun 2009 15:58:45 -0700 Subject: Make TeeInput easier to use The complexity of making the object persistent isn't worth the potential performance gain here. --- lib/unicorn/tee_input.rb | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) (limited to 'lib/unicorn/tee_input.rb') diff --git a/lib/unicorn/tee_input.rb b/lib/unicorn/tee_input.rb index 9e66837..ac9638d 100644 --- a/lib/unicorn/tee_input.rb +++ b/lib/unicorn/tee_input.rb @@ -15,30 +15,16 @@ require 'tempfile' module Unicorn class TeeInput - def initialize - @rd = @wr = @size = @input = nil - setup - end - - def setup - @tmp = tmp = Tempfile.new(nil) - @rd.close if @rd - @rd = File.open(tmp.path, 'wb+') - @wr.close if @wr - @wr = File.open(tmp.path, 'wb') + def initialize(input, size = nil, buffer = nil) + @wr = Tempfile.new(nil) + @wr.binmode + @rd = File.open(@wr.path, 'rb') + @wr.unlink @rd.sync = @wr.sync = true - tmp.close! - end - - def reopen(input, size = nil, buffer = nil) - @rd.seek(0) - @wr.seek(0) - @rd.truncate(0) # truncate read to flush luserspace read buffers @wr.write(buffer) if buffer @input = input @size = size # nil if chunked - self end def consume -- cgit v1.2.3-24-ge0c7