Class: HTTPX::Transcoder::Deflater
- Inherits:
-
Object
- Object
- HTTPX::Transcoder::Deflater
- Extended by:
- Forwardable
- Defined in:
- lib/httpx/transcoder/utils/deflater.rb,
sig/transcoder/utils/deflater.rbs
Direct Known Subclasses
Plugins::Brotli::Deflater, HTTPX::Transcoder::Deflate::Deflater, GZIP::Deflater
Instance Attribute Summary collapse
-
#content_type ⇒ String
readonly
Returns the value of attribute content_type.
Instance Method Summary collapse
-
#buffer_deflate! ⇒ void
rubocop:disable Naming/MemoizedInstanceVariableName.
- #bytesize ⇒ Integer, Float
- #close ⇒ void
- #deflate ⇒ String?
-
#initialize(body) ⇒ Deflater
constructor
A new instance of Deflater.
- #read(length = nil, outbuf = nil) ⇒ String?
- #rewind ⇒ void
Constructor Details
#initialize(body) ⇒ Deflater
Returns a new instance of Deflater.
10 11 12 13 14 |
# File 'lib/httpx/transcoder/utils/deflater.rb', line 10 def initialize(body) @content_type = body.content_type @body = BodyReader.new(body) @closed = false end |
Instance Attribute Details
#content_type ⇒ String (readonly)
Returns the value of attribute content_type.
8 9 10 |
# File 'lib/httpx/transcoder/utils/deflater.rb', line 8 def content_type @content_type end |
Instance Method Details
#buffer_deflate! ⇒ void
This method returns an undefined value.
rubocop:disable Naming/MemoizedInstanceVariableName
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/httpx/transcoder/utils/deflater.rb', line 59 def buffer_deflate! return @buffer if defined?(@buffer) buffer = Response::Buffer.new( threshold_size: Options::MAX_BODY_THRESHOLD_SIZE ) IO.copy_stream(self, buffer) buffer.rewind if buffer.respond_to?(:rewind) @buffer = buffer end |
#bytesize ⇒ Integer, Float
16 17 18 19 20 |
# File 'lib/httpx/transcoder/utils/deflater.rb', line 16 def bytesize buffer_deflate! @buffer.size end |
#close ⇒ void
This method returns an undefined value.
40 41 42 43 44 45 46 47 48 |
# File 'lib/httpx/transcoder/utils/deflater.rb', line 40 def close return if @closed @buffer.close if @buffer @body.close @closed = true end |
#deflate ⇒ String?
20 |
# File 'sig/transcoder/utils/deflater.rbs', line 20
def deflate: (String? chunk) -> String?
|
#read(length = nil, outbuf = nil) ⇒ String?
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/httpx/transcoder/utils/deflater.rb', line 22 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.replace(compressed_chunk) else compressed_chunk end end |
#rewind ⇒ void
This method returns an undefined value.
50 51 52 53 54 |
# File 'lib/httpx/transcoder/utils/deflater.rb', line 50 def rewind return unless @buffer @buffer.rewind end |