stringio
stringio copied to clipboard
How to know what is the last line or the index of the iteration?
Is there any way to know what is the last line, or the index of the iteration?
for await (const line of chunksToLinesAsync(stream)) {
console.log(chomp(line));
}
Thanks for your work!
@jamg44 You’d have to write your own utilities (e.g. via generators):
- A function that returns an iterable over
[currentValue, nextValue](the latter beingundefinedfor the lastcurrentValue. - A function that returns an iterable over
[currentValue, index].
this sounds similar to my problem: expose an interactive process (repl) with a json restful apiserver = connect stdin/stdout streams to request/response buffers
i needed something more "high level" than stringio and by searching for "capture stdout of interactive child process in nodejs" i found a stackoverflow question on interactive terminal emulation aka implementing the TTY protocol in nodejs
@rauschma maybe link to pty and tty as "related projects"? edit: pty is abandoned since node 8, active fork in node-pty