Class: HTTPX::Transcoder::Deflater
- Inherits:
-
Object
- Object
- HTTPX::Transcoder::Deflater
- Extended by:
- Forwardable
- Defined in:
- lib/httpx/transcoder/utils/deflater.rb
Direct Known Subclasses
Plugins::Brotli::Deflater, HTTPX::Transcoder::Deflate::Deflater, GZIP::Deflater
Instance Attribute Summary collapse
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
Instance Method Summary collapse
- #bytesize ⇒ Object
- #close ⇒ Object
-
#initialize(body) ⇒ Deflater
constructor
A new instance of Deflater.
- #read(length = nil, outbuf = nil) ⇒ Object
Constructor Details
#initialize(body) ⇒ Deflater
Returns a new instance of Deflater.
13 14 15 16 17 |
# File 'lib/httpx/transcoder/utils/deflater.rb', line 13 def initialize(body) @content_type = body.content_type @body = BodyReader.new(body) @closed = false end |
Instance Attribute Details
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
11 12 13 |
# File 'lib/httpx/transcoder/utils/deflater.rb', line 11 def content_type @content_type end |
Instance Method Details
#bytesize ⇒ Object
19 20 21 22 23 |
# File 'lib/httpx/transcoder/utils/deflater.rb', line 19 def bytesize buffer_deflate! @buffer.size end |
#close ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/httpx/transcoder/utils/deflater.rb', line 44 def close return if @closed @buffer.close if @buffer @body.close @closed = true end |
#read(length = nil, outbuf = nil) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/httpx/transcoder/utils/deflater.rb', line 25 def read(length = nil, outbuf = nil) return @buffer.read(length, outbuf) if @buffer return if @closed chunk = @body.read(length) compressed_chunk = deflate(chunk) return unless compressed_chunk if outbuf outbuf.clear.force_encoding(Encoding::BINARY) outbuf << compressed_chunk else compressed_chunk end end |