Class: Dommy::CompressionStream
- Inherits:
-
Object
- Object
- Dommy::CompressionStream
- Defined in:
- lib/dommy/compression_streams.rb
Overview
CompressionStream / DecompressionStream — wrap TransformStream
over Ruby's Zlib to gzip/deflate/raw-deflate byte chunks. Each
write(chunk) accumulates into an internal buffer; close()
finalizes and emits the compressed/decompressed bytes downstream.
Constant Summary collapse
- SUPPORTED =
%w[gzip deflate deflate-raw].freeze
Instance Attribute Summary collapse
-
#readable ⇒ Object
readonly
Returns the value of attribute readable.
-
#writable ⇒ Object
readonly
Returns the value of attribute writable.
Instance Method Summary collapse
- #__js_get__(key) ⇒ Object
-
#initialize(window, format) ⇒ CompressionStream
constructor
A new instance of CompressionStream.
Constructor Details
#initialize(window, format) ⇒ CompressionStream
Returns a new instance of CompressionStream.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/dommy/compression_streams.rb', line 18 def initialize(window, format) raise ArgumentError, "unsupported format #{format.inspect}" unless SUPPORTED.include?(format.to_s) @buffer = +"" compressor = build_compressor(format.to_s) @readable = ReadableStream.new(window) controller = TransformStreamDefaultController.new(@readable) @writable = WritableStream.new( window, { "write" => proc { |chunk| @buffer << coerce(chunk) }, "close" => proc do compressed = compressor.call(@buffer) controller.enqueue(compressed) @readable.__internal_close__ end, "abort" => proc { |r| @readable.__internal_error__(r) } } ) end |
Instance Attribute Details
#readable ⇒ Object (readonly)
Returns the value of attribute readable.
16 17 18 |
# File 'lib/dommy/compression_streams.rb', line 16 def readable @readable end |
#writable ⇒ Object (readonly)
Returns the value of attribute writable.
16 17 18 |
# File 'lib/dommy/compression_streams.rb', line 16 def writable @writable end |