class Inflate
Decompresses incoming WebSocket frames using the DEFLATE algorithm.
Definitions
def self.client(parent, server_max_window_bits: 15, server_no_context_takeover: false, **options)
Client reading from server.
Implementation
def self.client(parent, server_max_window_bits: 15, server_no_context_takeover: false, **options)
self.new(parent,
window_bits: server_max_window_bits,
context_takeover: !server_no_context_takeover,
)
end
def self.server(parent, client_max_window_bits: 15, client_no_context_takeover: false, **options)
Server reading from client.
Implementation
def self.server(parent, client_max_window_bits: 15, client_no_context_takeover: false, **options)
self.new(parent,
window_bits: client_max_window_bits,
context_takeover: !client_no_context_takeover,
)
end
def initialize(parent, context_takeover: true, window_bits: 15)
Initialize a new inflate decompressor.
Signature
-
parameter
parentObject The parent framer to wrap.
-
parameter
context_takeoverBoolean Whether to reuse the decompression context across messages.
-
parameter
window_bitsInteger The window size in bits for the DEFLATE algorithm.
Implementation
def initialize(parent, context_takeover: true, window_bits: 15)
@parent = parent
@inflate = nil
# This is handled during negotiation:
# if window_bits < MINIMUM_WINDOW_BITS
# window_bits = MINIMUM_WINDOW_BITS
# end
@window_bits = window_bits
@context_takeover = context_takeover
end
def to_s
Signature
-
returns
String A string representation including window bits and context takeover settings.
Implementation
def to_s
"#<#{self.class} window_bits=#{@window_bits} context_takeover=#{@context_takeover}>"
end
attr :window_bits
Signature
-
attribute
Integer The window size in bits used for decompression.
attr :context_takeover
Signature
-
attribute
Boolean Whether the decompression context is reused across messages.
def unpack_frames(frames, **options)
Unpack and decompress frames into a buffer.
Signature
-
parameter
framesArray(Frame) The frames to unpack.
-
returns
String The decompressed payload buffer.
Implementation
def unpack_frames(frames, **options)
buffer = @parent.unpack_frames(frames, **options)
frame = frames.first
if frame.flag?(Frame::RSV1)
buffer = self.inflate(buffer)
frame.flags &= ~Frame::RSV1
end
return buffer
end