class HTTPX::Transcoder::Deflater

  1. lib/httpx/transcoder/utils/deflater.rb
Superclass: Object

Methods

Public Class

  1. new

Public Instance

  1. bytesize
  2. close
  3. content_type
  4. read

Attributes

Public Class methods

new(body)
[show source]
   # File lib/httpx/transcoder/utils/deflater.rb
13 def initialize(body)
14   @content_type = body.content_type
15   @body = BodyReader.new(body)
16   @closed = false
17 end

Public Instance methods

bytesize()
[show source]
   # File lib/httpx/transcoder/utils/deflater.rb
19 def bytesize
20   buffer_deflate!
21 
22   @buffer.size
23 end
close()
[show source]
   # File lib/httpx/transcoder/utils/deflater.rb
44 def close
45   return if @closed
46 
47   @buffer.close if @buffer
48 
49   @body.close
50 
51   @closed = true
52 end
read(length = nil, outbuf = nil)
[show source]
   # File lib/httpx/transcoder/utils/deflater.rb
25 def read(length = nil, outbuf = nil)
26   return @buffer.read(length, outbuf) if @buffer
27 
28   return if @closed
29 
30   chunk = @body.read(length)
31 
32   compressed_chunk = deflate(chunk)
33 
34   return unless compressed_chunk
35 
36   if outbuf
37     outbuf.clear.force_encoding(Encoding::BINARY)
38     outbuf << compressed_chunk
39   else
40     compressed_chunk
41   end
42 end