Class: Protocol::WebSocket::Extension::Compression::Deflate
- Inherits:
-
Object
- Object
- Protocol::WebSocket::Extension::Compression::Deflate
- Defined in:
- lib/protocol/websocket/extension/compression/deflate.rb
Overview
Compresses outgoing WebSocket frames using the DEFLATE algorithm.
Instance Attribute Summary collapse
-
#context_takeover ⇒ Object
readonly
Returns the value of attribute context_takeover.
- #The window size in bits used for compression.(windowsize) ⇒ Object readonly
-
#window_bits ⇒ Object
readonly
Returns the value of attribute window_bits.
Class Method Summary collapse
-
.client(parent, client_max_window_bits: 15, client_no_context_takeover: false, **options) ⇒ Object
Client writing to server.
-
.server(parent, server_max_window_bits: 15, server_no_context_takeover: false, **options) ⇒ Object
Server writing to client.
Instance Method Summary collapse
-
#initialize(parent, level: Zlib::DEFAULT_COMPRESSION, memory_level: Zlib::DEF_MEM_LEVEL, strategy: Zlib::DEFAULT_STRATEGY, window_bits: 15, context_takeover: true, **options) ⇒ Deflate
constructor
Initialize a new deflate compressor.
-
#pack_binary_frame(buffer, compress: false, **options) ⇒ Object
Pack a binary frame, optionally compressing the buffer.
-
#pack_text_frame(buffer, compress: true, **options) ⇒ Object
Pack a text frame, optionally compressing the buffer.
- #to_s ⇒ Object
- #Whether the compression context is reused across messages.=(thecompressioncontextisreusedacrossmessages. = (value)) ⇒ Object
Constructor Details
#initialize(parent, level: Zlib::DEFAULT_COMPRESSION, memory_level: Zlib::DEF_MEM_LEVEL, strategy: Zlib::DEFAULT_STRATEGY, window_bits: 15, context_takeover: true, **options) ⇒ Deflate
Initialize a new deflate compressor.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/protocol/websocket/extension/compression/deflate.rb', line 39 def initialize(parent, level: Zlib::DEFAULT_COMPRESSION, memory_level: Zlib::DEF_MEM_LEVEL, strategy: Zlib::DEFAULT_STRATEGY, window_bits: 15, context_takeover: true, **) @parent = parent @deflate = nil @level = level @memory_level = memory_level @strategy = strategy # 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 |
Instance Attribute Details
#context_takeover ⇒ Object (readonly)
Returns the value of attribute context_takeover.
65 66 67 |
# File 'lib/protocol/websocket/extension/compression/deflate.rb', line 65 def context_takeover @context_takeover end |
#The window size in bits used for compression.(windowsize) ⇒ Object (readonly)
63 |
# File 'lib/protocol/websocket/extension/compression/deflate.rb', line 63 attr :window_bits |
#window_bits ⇒ Object (readonly)
Returns the value of attribute window_bits.
63 64 65 |
# File 'lib/protocol/websocket/extension/compression/deflate.rb', line 63 def window_bits @window_bits end |
Class Method Details
.client(parent, client_max_window_bits: 15, client_no_context_takeover: false, **options) ⇒ Object
Client writing to server.
15 16 17 18 19 20 21 |
# File 'lib/protocol/websocket/extension/compression/deflate.rb', line 15 def self.client(parent, client_max_window_bits: 15, client_no_context_takeover: false, **) self.new(parent, window_bits: client_max_window_bits, context_takeover: !client_no_context_takeover, ** ) end |
.server(parent, server_max_window_bits: 15, server_no_context_takeover: false, **options) ⇒ Object
Server writing to client.
24 25 26 27 28 29 30 |
# File 'lib/protocol/websocket/extension/compression/deflate.rb', line 24 def self.server(parent, server_max_window_bits: 15, server_no_context_takeover: false, **) self.new(parent, window_bits: server_max_window_bits, context_takeover: !server_no_context_takeover, ** ) end |
Instance Method Details
#pack_binary_frame(buffer, compress: false, **options) ⇒ Object
Pack a binary frame, optionally compressing the buffer.
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/protocol/websocket/extension/compression/deflate.rb', line 89 def pack_binary_frame(buffer, compress: false, **) if compress buffer = self.deflate(buffer) end frame = @parent.pack_binary_frame(buffer, **) if compress frame.flags |= Frame::RSV1 end return frame end |
#pack_text_frame(buffer, compress: true, **options) ⇒ Object
Pack a text frame, optionally compressing the buffer.
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/protocol/websocket/extension/compression/deflate.rb', line 71 def pack_text_frame(buffer, compress: true, **) if compress buffer = self.deflate(buffer) end frame = @parent.pack_text_frame(buffer, **) if compress frame.flags |= Frame::RSV1 end return frame end |
#to_s ⇒ Object
58 59 60 |
# File 'lib/protocol/websocket/extension/compression/deflate.rb', line 58 def to_s "#<#{self.class} window_bits=#{@window_bits} context_takeover=#{@context_takeover}>" end |
#Whether the compression context is reused across messages.=(thecompressioncontextisreusedacrossmessages. = (value)) ⇒ Object
65 |
# File 'lib/protocol/websocket/extension/compression/deflate.rb', line 65 attr :context_takeover |