Class: Rack::SmartCompress::StreamBody
- Inherits:
-
Object
- Object
- Rack::SmartCompress::StreamBody
- Defined in:
- lib/rack/smart_compress/stream_body.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#encoder_class ⇒ Object
readonly
Returns the value of attribute encoder_class.
-
#encoder_name ⇒ Object
readonly
Returns the value of attribute encoder_name.
-
#level ⇒ Object
readonly
Returns the value of attribute level.
Instance Method Summary collapse
- #close ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(body, encoder_name, encoder_class, level: nil) ⇒ StreamBody
constructor
A new instance of StreamBody.
Constructor Details
#initialize(body, encoder_name, encoder_class, level: nil) ⇒ StreamBody
Returns a new instance of StreamBody.
11 12 13 14 15 16 17 |
# File 'lib/rack/smart_compress/stream_body.rb', line 11 def initialize(body, encoder_name, encoder_class, level: nil) @body = body @encoder_name = encoder_name @encoder_class = encoder_class @level = level @closed = false end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
9 10 11 |
# File 'lib/rack/smart_compress/stream_body.rb', line 9 def body @body end |
#encoder_class ⇒ Object (readonly)
Returns the value of attribute encoder_class.
9 10 11 |
# File 'lib/rack/smart_compress/stream_body.rb', line 9 def encoder_class @encoder_class end |
#encoder_name ⇒ Object (readonly)
Returns the value of attribute encoder_name.
9 10 11 |
# File 'lib/rack/smart_compress/stream_body.rb', line 9 def encoder_name @encoder_name end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
9 10 11 |
# File 'lib/rack/smart_compress/stream_body.rb', line 9 def level @level end |
Instance Method Details
#close ⇒ Object
40 41 42 43 44 45 |
# File 'lib/rack/smart_compress/stream_body.rb', line 40 def close return if @closed @closed = true @body.close if @body.respond_to?(:close) end |
#each(&block) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rack/smart_compress/stream_body.rb', line 19 def each(&block) return enum_for(:each) unless block_given? begin case encoder_name when "gzip" stream_gzip(&block) when "deflate" stream_deflate(&block) when "zstd" stream_zstd(&block) when "br" stream_brotli(&block) else @body.each { |chunk| yield encoder_class.compress(chunk.to_s, level: level) } end ensure close end end |