Class: HTTPX::Transcoder::Deflater

Inherits:
Object
  • Object
show all
Defined in:
lib/httpx/transcoder/utils/deflater.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#bytesizeObject



16
17
18
19
20
# File 'lib/httpx/transcoder/utils/deflater.rb', line 16

def bytesize
  buffer_deflate!

  @buffer.size
end

#closeObject



41
42
43
44
45
46
47
48
49
# File 'lib/httpx/transcoder/utils/deflater.rb', line 41

def close
  return if @closed

  @buffer.close if @buffer

  @body.close

  @closed = true
end

#read(length = nil, outbuf = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 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.clear.force_encoding(Encoding::BINARY)
    outbuf << compressed_chunk
  else
    compressed_chunk
  end
end

#rewindObject



51
52
53
54
55
# File 'lib/httpx/transcoder/utils/deflater.rb', line 51

def rewind
  return unless @buffer

  @buffer.rewind
end