Class: Datastar::Compressor::Brotli::CompressedSocket
- Inherits:
-
Object
- Object
- Datastar::Compressor::Brotli::CompressedSocket
- Defined in:
- lib/datastar/compressor/brotli.rb
Overview
Brotli compressed socket using the ‘brotli` gem. Options are passed directly to Brotli::Compressor.new:
:quality - Compression quality (0-11, default: 11). Lower is faster, higher compresses better.
:lgwin - Base-2 log of the sliding window size (10-24, default: 22).
:lgblock - Base-2 log of the maximum input block size (16-24, 0 = auto, default: 0).
:mode - Compression mode (:generic, :text, or :font, default: :generic).
Use :text for UTF-8 formatted text (HTML, JSON — good for SSE).
Instance Method Summary collapse
- #<<(data) ⇒ Object
- #close ⇒ Object
-
#initialize(socket, options = {}) ⇒ CompressedSocket
constructor
A new instance of CompressedSocket.
Constructor Details
#initialize(socket, options = {}) ⇒ CompressedSocket
Returns a new instance of CompressedSocket.
35 36 37 38 |
# File 'lib/datastar/compressor/brotli.rb', line 35 def initialize(socket, = {}) @socket = socket @compressor = ::Brotli::Compressor.new() end |
Instance Method Details
#<<(data) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/datastar/compressor/brotli.rb', line 40 def <<(data) compressed = @compressor.process(data) @socket << compressed if compressed && !compressed.empty? flushed = @compressor.flush @socket << flushed if flushed && !flushed.empty? self end |
#close ⇒ Object
48 49 50 51 52 |
# File 'lib/datastar/compressor/brotli.rb', line 48 def close final = @compressor.finish @socket << final if final && !final.empty? @socket.close end |