Class: Dommy::TextDecoderStream
- Inherits:
-
Object
- Object
- Dommy::TextDecoderStream
- Defined in:
- lib/dommy/text_codec.rb
Overview
‘TextDecoderStream` — Stream-shaped wrapper over `TextDecoder`. `write(bytes)` flushes decoded strings downstream.
Instance Attribute Summary collapse
-
#encoding ⇒ Object
readonly
Returns the value of attribute encoding.
-
#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, label = "utf-8", _options = nil) ⇒ TextDecoderStream
constructor
A new instance of TextDecoderStream.
Constructor Details
#initialize(window, label = "utf-8", _options = nil) ⇒ TextDecoderStream
Returns a new instance of TextDecoderStream.
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/dommy/text_codec.rb', line 148 def initialize(window, label = "utf-8", = nil) decoder = TextDecoder.new(label) @encoding = decoder.encoding @readable = ReadableStream.new(window) controller = TransformStreamDefaultController.new(@readable) @writable = WritableStream.new( window, { "write" => proc { |chunk| controller.enqueue(decoder.decode(chunk)) }, "close" => proc { @readable.__close__ }, "abort" => proc { |r| @readable.__error__(r) } } ) end |
Instance Attribute Details
#encoding ⇒ Object (readonly)
Returns the value of attribute encoding.
146 147 148 |
# File 'lib/dommy/text_codec.rb', line 146 def encoding @encoding end |
#readable ⇒ Object (readonly)
Returns the value of attribute readable.
146 147 148 |
# File 'lib/dommy/text_codec.rb', line 146 def readable @readable end |
#writable ⇒ Object (readonly)
Returns the value of attribute writable.
146 147 148 |
# File 'lib/dommy/text_codec.rb', line 146 def writable @writable end |
Instance Method Details
#__js_get__(key) ⇒ Object
164 165 166 167 168 169 170 171 172 173 |
# File 'lib/dommy/text_codec.rb', line 164 def __js_get__(key) case key when "readable" @readable when "writable" @writable when "encoding" @encoding end end |