stream-protocol-expect
A tiny function for expecting matching data from a readable stream, e.g. for request-response protocols like SMTP and IMAP.
Usage
First argument: the stream.
Second argument: matcher function or a regexp.
Make sure the stream is textual (an encoding is set), otherwise it will try to call your function or regexp .match
on a Buffer
!
(Your function can handle Buffers if you want, but there's no match
on them :D)
Third argument (optional, default = 4s
): timeout (zeit/ms).
Returns: a Promise that will be resolved with the matching data or rejected with an error.
For example, IMAP authentication:
{ const streamExpect = const tls = const sock = tls sock sock console sock console // exception if not OK sock}
Possibly something like byline might be helpful to ensure that it will actually match line-by-line.
Installation
Install with npm:
npm i stream-protocol-expect
Contributing
Please feel free to submit pull requests!
By participating in this project you agree to follow the Contributor Code of Conduct and to release your contributions under the Unlicense.
The list of contributors is available on GitHub.
License
This is free and unencumbered software released into the public domain.
For more information, please refer to the UNLICENSE
file or unlicense.org.