Class: HTTPX::Plugins::Compression::Encoder
- Inherits:
-
Object
- Object
- HTTPX::Plugins::Compression::Encoder
- Defined in:
- lib/httpx/plugins/compression.rb
Instance Method Summary collapse
- #bytesize ⇒ Object
- #close ⇒ Object
- #each(&blk) ⇒ Object
-
#initialize(body, deflater) ⇒ Encoder
constructor
A new instance of Encoder.
- #to_s ⇒ Object
Constructor Details
#initialize(body, deflater) ⇒ Encoder
Returns a new instance of Encoder.
82 83 84 85 86 |
# File 'lib/httpx/plugins/compression.rb', line 82 def initialize(body, deflater) @body = body.respond_to?(:read) ? body : StringIO.new(body.to_s) @buffer = StringIO.new("".b, File::RDWR) @deflater = deflater end |
Instance Method Details
#bytesize ⇒ Object
98 99 100 101 |
# File 'lib/httpx/plugins/compression.rb', line 98 def bytesize deflate @buffer.size end |
#close ⇒ Object
109 110 111 112 |
# File 'lib/httpx/plugins/compression.rb', line 109 def close @buffer.close @body.close end |
#each(&blk) ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'lib/httpx/plugins/compression.rb', line 88 def each(&blk) return enum_for(__method__) unless block_given? unless @buffer.size.zero? @buffer.rewind return @buffer.each(&blk) end deflate(&blk) end |
#to_s ⇒ Object
103 104 105 106 107 |
# File 'lib/httpx/plugins/compression.rb', line 103 def to_s deflate @buffer.rewind @buffer.read end |