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.



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", _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.__close__ },
      "abort" => proc { |r| @readable.__error__(r) }
    }
  )
end

Instance Attribute Details

#encodingObject (readonly)

Returns the value of attribute encoding.



146
147
148
# File 'lib/dommy/text_codec.rb', line 146

def encoding
  @encoding
end

#readableObject (readonly)

Returns the value of attribute readable.



146
147
148
# File 'lib/dommy/text_codec.rb', line 146

def readable
  @readable
end

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