switch-writable
Dynamically select a stream's writable target.
Adapted from switchstream.
Usage
const Switch = const from = objconst fs =
If the stream or any of the target streams error or close prematurely, all other streams are destroyed. This also happens if the switch function returns a key for which there is no stream (e.g. c
in the example above).
Target streams can be created lazily:
The list of streams can be an array:
Lastly, a default key can be provided, for when no stream matches the key or when no key is returned:
switchstream
Other differences from - Is and takes a writable stream instead of a duplex stream
- Has backpressure (is as slow as the slowest target)
- Has and expects
destroy()
semantics of Node 8+ - Doesn't coerce keys to the right type (string or number)
- Doesn't support async map function.
Licence
MIT © 2018-present Vincent Weevers. Adapted from switchstream
© Tim Oxley.