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
  5. rewind

Attributes

Public Class methods

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

Public Instance methods

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