Class: Dommy::TextEncoderStream

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

Overview

TextEncoderStream — Stream-shaped wrapper over TextEncoder. write(string) flushes UTF-8 bytes downstream.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(window) ⇒ TextEncoderStream

Returns a new instance of TextEncoderStream.



267
268
269
270
271
272
273
274
275
276
277
278
279
280
# File 'lib/dommy/text_codec.rb', line 267

def initialize(window)
  encoder = TextEncoder.new
  @readable = ReadableStream.new(window)
  controller = TransformStreamDefaultController.new(@readable)

  @writable = WritableStream.new(
    window,
    {
      "write" => proc { |chunk| controller.enqueue(encoder.encode(chunk)) },
      "close" => proc { @readable.__internal_close__ },
      "abort" => proc { |r| @readable.__internal_error__(r) }
    }
  )
end

Instance Attribute Details

#readableObject (readonly)

Returns the value of attribute readable.



265
266
267
# File 'lib/dommy/text_codec.rb', line 265

def readable
  @readable
end

#writableObject (readonly)

Returns the value of attribute writable.



265
266
267
# File 'lib/dommy/text_codec.rb', line 265

def writable
  @writable
end

Instance Method Details

#__js_get__(key) ⇒ Object



286
287
288
289
290
291
292
293
294
295
296
297
# File 'lib/dommy/text_codec.rb', line 286

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

#encodingObject



282
283
284
# File 'lib/dommy/text_codec.rb', line 282

def encoding
  "utf-8"
end