Class: Dommy::TextEncoderStream
- Inherits:
-
Object
- Object
- Dommy::TextEncoderStream
- 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
-
#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
- #encoding ⇒ Object
-
#initialize(window) ⇒ TextEncoderStream
constructor
A new instance of TextEncoderStream.
Constructor Details
#initialize(window) ⇒ TextEncoderStream
Returns a new instance of TextEncoderStream.
265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/dommy/text_codec.rb', line 265 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
#readable ⇒ Object (readonly)
Returns the value of attribute readable.
263 264 265 |
# File 'lib/dommy/text_codec.rb', line 263 def readable @readable end |
#writable ⇒ Object (readonly)
Returns the value of attribute writable.
263 264 265 |
# File 'lib/dommy/text_codec.rb', line 263 def writable @writable end |
Instance Method Details
#__js_get__(key) ⇒ Object
284 285 286 287 288 289 290 291 292 293 |
# File 'lib/dommy/text_codec.rb', line 284 def __js_get__(key) case key when "readable" @readable when "writable" @writable when "encoding" encoding end end |
#encoding ⇒ Object
280 281 282 |
# File 'lib/dommy/text_codec.rb', line 280 def encoding "utf-8" end |