Class: HTTPX::Plugins::Compression::Encoder
- Inherits:
-
Object
- Object
- HTTPX::Plugins::Compression::Encoder
- Defined in:
- lib/httpx/plugins/compression.rb
Instance Attribute Summary collapse
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
Instance Method Summary collapse
- #bytesize ⇒ Object
- #each(&blk) ⇒ Object
-
#initialize(body, deflater) ⇒ Encoder
constructor
A new instance of Encoder.
Constructor Details
#initialize(body, deflater) ⇒ Encoder
Returns a new instance of Encoder.
132 133 134 135 136 137 |
# File 'lib/httpx/plugins/compression.rb', line 132 def initialize(body, deflater) @content_type = body.content_type @body = body.respond_to?(:read) ? body : StringIO.new(body.to_s) @buffer = StringIO.new("".b, File::RDWR) @deflater = deflater end |
Instance Attribute Details
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
130 131 132 |
# File 'lib/httpx/plugins/compression.rb', line 130 def content_type @content_type end |
Instance Method Details
#bytesize ⇒ Object
148 149 150 151 |
# File 'lib/httpx/plugins/compression.rb', line 148 def bytesize deflate @buffer.size end |
#each(&blk) ⇒ Object
139 140 141 142 143 144 145 146 |
# File 'lib/httpx/plugins/compression.rb', line 139 def each(&blk) return enum_for(__method__) unless blk return deflate(&blk) if @buffer.size.zero? # rubocop:disable Style/ZeroLengthPredicate @buffer.rewind @buffer.each(&blk) end |