Class: Dommy::TextDecoderStream

Inherits:
Object
  • Object
show all
Defined in:
lib/dommy/text_codec.rb

Overview

TextDecoderStream — Stream-shaped wrapper over TextDecoder. write(bytes) flushes decoded strings downstream.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(window, label = "utf-8", _options = nil) ⇒ TextDecoderStream

Returns a new instance of TextDecoderStream.



305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
# File 'lib/dommy/text_codec.rb', line 305

def initialize(window, label = "utf-8", _options = 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

#encodingObject (readonly)

Returns the value of attribute encoding.



303
304
305
# File 'lib/dommy/text_codec.rb', line 303

def encoding
  @encoding
end

#readableObject (readonly)

Returns the value of attribute readable.



303
304
305
# File 'lib/dommy/text_codec.rb', line 303

def readable
  @readable
end

#writableObject (readonly)

Returns the value of attribute writable.



303
304
305
# File 'lib/dommy/text_codec.rb', line 303

def writable
  @writable
end

Instance Method Details

#__js_get__(key) ⇒ Object



321
322
323
324
325
326
327
328
329
330
331
332
# File 'lib/dommy/text_codec.rb', line 321

def __js_get__(key)
  case key
  when "readable"
    @readable
  when "writable"
    @writable
  when "encoding"
    @encoding
  else
    Bridge::ABSENT
  end
end