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.



80
81
82
83
84
# File 'lib/httpx/plugins/compression.rb', line 80

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



96
97
98
99
# File 'lib/httpx/plugins/compression.rb', line 96

def bytesize
  deflate
  @buffer.size
end

#closeObject



107
108
109
110
# File 'lib/httpx/plugins/compression.rb', line 107

def close
  @buffer.close
  @body.close
end

#each(&blk) ⇒ Object



86
87
88
89
90
91
92
93
94
# File 'lib/httpx/plugins/compression.rb', line 86

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



101
102
103
104
105
# File 'lib/httpx/plugins/compression.rb', line 101

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