Class: Dommy::DecompressionStream
- Inherits:
-
Object
- Object
- Dommy::DecompressionStream
- Defined in:
- lib/dommy/compression_streams.rb
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) ⇒ DecompressionStream
constructor
A new instance of DecompressionStream.
Constructor Details
#initialize(window, format) ⇒ DecompressionStream
Returns a new instance of DecompressionStream.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/dommy/compression_streams.rb', line 85 def initialize(window, format) raise ArgumentError, "unsupported format #{format.inspect}" unless SUPPORTED.include?(format.to_s) @buffer = +"" decompressor = build_decompressor(format.to_s) @readable = ReadableStream.new(window) controller = TransformStreamDefaultController.new(@readable) @writable = WritableStream.new( window, { "write" => proc { |chunk| @buffer << coerce(chunk) }, "close" => proc do plain = decompressor.call(@buffer) controller.enqueue(plain) @readable.__close__ end, "abort" => proc { |r| @readable.__error__(r) } } ) end |
Instance Attribute Details
#readable ⇒ Object (readonly)
Returns the value of attribute readable.
83 84 85 |
# File 'lib/dommy/compression_streams.rb', line 83 def readable @readable end |
#writable ⇒ Object (readonly)
Returns the value of attribute writable.
83 84 85 |
# File 'lib/dommy/compression_streams.rb', line 83 def writable @writable end |
Instance Method Details
#__js_get__(key) ⇒ Object
108 109 110 111 112 113 114 115 |
# File 'lib/dommy/compression_streams.rb', line 108 def __js_get__(key) case key when "readable" @readable when "writable" @writable end end |