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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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_typeObject (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

#bytesizeObject



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