Class: Isomorfeus::Transport::CompressorRack::BrotliStream
- Inherits:
-
Object
- Object
- Isomorfeus::Transport::CompressorRack::BrotliStream
- Defined in:
- lib/isomorfeus/transport/compressor_rack.rb
Constant Summary collapse
- BUFFER_LENGTH =
128 * 1_024
Instance Method Summary collapse
- #close ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(body, sync) ⇒ BrotliStream
constructor
A new instance of BrotliStream.
- #write(data) ⇒ Object
Constructor Details
#initialize(body, sync) ⇒ BrotliStream
Returns a new instance of BrotliStream.
54 55 56 57 |
# File 'lib/isomorfeus/transport/compressor_rack.rb', line 54 def initialize(body, sync) @body = body @sync end |
Instance Method Details
#close ⇒ Object
83 84 85 |
# File 'lib/isomorfeus/transport/compressor_rack.rb', line 83 def close @body.close if @body.respond_to?(:close) end |
#each(&block) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/isomorfeus/transport/compressor_rack.rb', line 59 def each(&block) @writer = block brotli = ::Brotli::Writer.new(self, quality: 5) if @body.is_a? ::File while part = @body.read(BUFFER_LENGTH) brotli.write(part) brotli.flush if @sync end else @body.each do |part| next if part.empty? brotli.write(part) brotli.flush if @sync end end ensure brotli.close end |
#write(data) ⇒ Object
79 80 81 |
# File 'lib/isomorfeus/transport/compressor_rack.rb', line 79 def write(data) @writer.call(data) end |