Class: Dommy::TransformStream
- Inherits:
-
Object
- Object
- Dommy::TransformStream
- Defined in:
- lib/dommy/streams.rb
Overview
TransformStream — links a writable + readable so chunks flow
through a transform callback.
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
-
#initialize(window, transformer = nil) ⇒ TransformStream
constructor
A new instance of TransformStream.
Constructor Details
#initialize(window, transformer = nil) ⇒ TransformStream
Returns a new instance of TransformStream.
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
# File 'lib/dommy/streams.rb', line 308 def initialize(window, transformer = nil) @window = window t = transformer.is_a?(Hash) ? transformer.transform_keys(&:to_s) : {} @readable = ReadableStream.new(window) controller = TransformStreamDefaultController.new(@readable) @writable = WritableStream.new( window, { "write" => proc do |chunk| if t["transform"].respond_to?(:__js_call__) t["transform"].__js_call__("call", [chunk, controller]) elsif t["transform"].respond_to?(:call) t["transform"].call(chunk, controller) else controller.enqueue(chunk) end end, "close" => proc { @readable.__internal_close__ }, "abort" => proc { |reason| @readable.__internal_error__(reason) } } ) if t["start"] if t["start"].respond_to?(:__js_call__) t["start"].__js_call__("call", [controller]) elsif t["start"].respond_to?(:call) t["start"].call(controller) end end end |
Instance Attribute Details
#readable ⇒ Object (readonly)
Returns the value of attribute readable.
306 307 308 |
# File 'lib/dommy/streams.rb', line 306 def readable @readable end |
#writable ⇒ Object (readonly)
Returns the value of attribute writable.
306 307 308 |
# File 'lib/dommy/streams.rb', line 306 def writable @writable end |