Class: Rack::Compress::Deflater::BrotliStream

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

Instance Method Summary collapse

Constructor Details

#initialize(body, level) ⇒ BrotliStream

Returns a new instance of BrotliStream.



76
77
78
79
# File 'lib/rack/compress/deflater.rb', line 76

def initialize(body, level)
  @body = body
  @level = level
end

Instance Method Details

#closeObject



96
97
98
# File 'lib/rack/compress/deflater.rb', line 96

def close
  @body.close if @body.respond_to?(:close)
end

#each(&block) ⇒ Object



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

def each(&block)
  @writer = block
  # Use String.new instead of '' to support environments with strings frozen by default.
  buffer = String.new
  @body.each do |part|
    buffer << part
  end

  # TODO: implement Brotli using streaming classes

  yield ::Brotli.deflate(buffer, { quality: @level })
ensure
  @writer = nil
end