Class: Rack::Deflater::GzipStream

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/deflater.rb

Instance Method Summary collapse

Constructor Details

#initialize(body, mtime) ⇒ GzipStream

Returns a new instance of GzipStream.



69
70
71
72
73
# File 'lib/rack/deflater.rb', line 69

def initialize(body, mtime)
  @body = body
  @mtime = mtime
  @closed = false
end

Instance Method Details

#closeObject



92
93
94
95
96
# File 'lib/rack/deflater.rb', line 92

def close
  return if @closed
  @closed = true
  @body.close if @body.respond_to?(:close)
end

#each(&block) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/rack/deflater.rb', line 75

def each(&block)
  @writer = block
  gzip  =::Zlib::GzipWriter.new(self)
  gzip.mtime = @mtime
  @body.each { |part|
    gzip.write(part)
    gzip.flush
  }
ensure
  gzip.close
  @writer = nil
end

#write(data) ⇒ Object



88
89
90
# File 'lib/rack/deflater.rb', line 88

def write(data)
  @writer.call(data)
end