Class: HTTPX::Plugins::Compression::Encoder

Inherits:
Object
  • Object
show all
Defined in:
lib/httpx/plugins/compression.rb

Instance Method Summary collapse

Constructor Details

#initialize(body, deflater) ⇒ Encoder

Returns a new instance of Encoder.



104
105
106
107
108
# File 'lib/httpx/plugins/compression.rb', line 104

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

#bytesizeObject



120
121
122
123
# File 'lib/httpx/plugins/compression.rb', line 120

def bytesize
  deflate
  @buffer.size
end

#closeObject



131
132
133
134
# File 'lib/httpx/plugins/compression.rb', line 131

def close
  @buffer.close
  @body.close
end

#each(&blk) ⇒ Object



110
111
112
113
114
115
116
117
118
# File 'lib/httpx/plugins/compression.rb', line 110

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_sObject



125
126
127
128
129
# File 'lib/httpx/plugins/compression.rb', line 125

def to_s
  deflate
  @buffer.rewind
  @buffer.read
end