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



74
75
76
77
78
# File 'lib/rack/deflater.rb', line 74

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

Instance Method Details

#closeObject



97
98
99
100
101
# File 'lib/rack/deflater.rb', line 97

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

#each(&block) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/rack/deflater.rb', line 80

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



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

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