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.
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'lib/dommy/text_codec.rb', line 301 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.__internal_close__ }, "abort" => proc { |r| @readable.__internal_error__(r) } } ) end |
Instance Attribute Details
#encoding ⇒ Object (readonly)
Returns the value of attribute encoding.
299 300 301 |
# File 'lib/dommy/text_codec.rb', line 299 def encoding @encoding end |
#readable ⇒ Object (readonly)
Returns the value of attribute readable.
299 300 301 |
# File 'lib/dommy/text_codec.rb', line 299 def readable @readable end |
#writable ⇒ Object (readonly)
Returns the value of attribute writable.
299 300 301 |
# File 'lib/dommy/text_codec.rb', line 299 def writable @writable end |
Instance Method Details
#__js_get__(key) ⇒ Object
317 318 319 320 321 322 323 324 325 326 |
# File 'lib/dommy/text_codec.rb', line 317 def __js_get__(key) case key when "readable" @readable when "writable" @writable when "encoding" @encoding end end |