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.



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", _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.



299
300
301
# File 'lib/dommy/text_codec.rb', line 299

def encoding
  @encoding
end

#readableObject (readonly)

Returns the value of attribute readable.



299
300
301
# File 'lib/dommy/text_codec.rb', line 299

def readable
  @readable
end

#writableObject (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