Class: Protocol::HTTP::Body::Deflate

Inherits:
ZStream show all
Defined in:
lib/protocol/http/body/deflate.rb

Constant Summary

Constants inherited from ZStream

ZStream::DEFAULT_LEVEL, ZStream::DEFLATE, ZStream::ENCODINGS, ZStream::GZIP

Instance Attribute Summary

Attributes inherited from ZStream

#input_length, #output_length

Attributes inherited from Wrapper

#body

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ZStream

#close, #initialize, #inspect, #length, #ratio

Methods inherited from Wrapper

#call, #close, #empty?, #finish, #initialize, #inspect, #length, #ready?, wrap

Methods inherited from Readable

#call, #close, #each, #empty?, #finish, #join, #length, #ready?

Constructor Details

This class inherits a constructor from Protocol::HTTP::Body::ZStream

Class Method Details

.for(body, window_size = GZIP, level = DEFAULT_LEVEL) ⇒ Object



61
62
63
# File 'lib/protocol/http/body/deflate.rb', line 61

def self.for(body, window_size = GZIP, level = DEFAULT_LEVEL)
  self.new(body, Zlib::Deflate.new(level, window_size))
end

Instance Method Details

#readObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/protocol/http/body/deflate.rb', line 71

def read
  return if @stream.finished?
  
  # The stream might have been closed while waiting for the chunk to come in.
  if chunk = super
    @input_length += chunk.bytesize
    
    chunk = @stream.deflate(chunk, Zlib::SYNC_FLUSH)
    
    @output_length += chunk.bytesize
    
    return chunk
  elsif !@stream.closed?
    chunk = @stream.finish
    
    @output_length += chunk.bytesize
    
    return chunk.empty? ? nil : chunk
  end
end

#stream?Boolean

Returns:

  • (Boolean)


65
66
67
68
69
# File 'lib/protocol/http/body/deflate.rb', line 65

def stream?
  # We might want to revisit this design choice.
  # We could wrap the streaming body in a Deflate stream, but that would require an extra stream wrapper which we don't have right now. See also `Digestable#stream?`.
  false
end