An entangled pair of readable and writeable streams, wherein writing to the stream causes a transform function that can enqueue chunks to the readable side.

Details

Events:

  • start

  • error

  • data

  • drain

  • backpressure

  • pipe

  • tee

  • close

See also

Super class

streams::EventEmitter -> TransformStream

Active bindings

desired_size

1

current_state

1

readable

1

writeable

1

controller

1

Methods

Inherited methods


Method new()

1

Usage

TransformStream$new(
  start = NULL,
  transform = NULL,
  flush = NULL,
  writeable_strategy = NULL,
  readable_strategy = NULL
)

Arguments

start

1

transform

1

flush

1

writeable_strategy

1

readable_strategy

1

Returns

NULL


Method close()

1

Usage

TransformStream$close()

Returns

NULL


Method abort()

1

Usage

TransformStream$abort()

Returns

NULL


Method write()

1

Usage

TransformStream$write(chunk)

Arguments

chunk

1

Returns

NULL


Method pipe()

1

Usage

TransformStream$pipe(destination)

Arguments

destination

1

Returns

NULL


Method tee()

1

Usage

TransformStream$tee()

Returns

NULL


Method print()

1

Usage

TransformStream$print()

Returns

NULL


Method format()

1

Usage

TransformStream$format(...)

Arguments

...

1

Returns

NULL

Examples

# All the functional streams are implemented using
# the transform stream class
# For instance, `streams::map_stream`:

map_stream <- function(fn, ...) {
    fn <- to_function(fn)
    TransformStream$new(
        transform = function(chunk, controller) {
            res <- fn(chunk)
            controller$enqueue(res)
        },
        ...
    )
}

# Or `streams::filter_stream`

filter_stream <- function(fn, ...) {
    fn <- to_function(fn)
    TransformStream$new(
        transform = function(chunk, controller) {
            res <- isTRUE(fn(chunk))
            if (res) {
                controller$enqueue(chunk)
            }
        },
        ...
    )
}