stringio icon indicating copy to clipboard operation
stringio copied to clipboard

How to know what is the last line or the index of the iteration?

Open jamg44 opened this issue 4 years ago • 2 comments
trafficstars

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 avatar Jan 27 '21 16:01 jamg44

@jamg44 You’d have to write your own utilities (e.g. via generators):

  • A function that returns an iterable over [currentValue, nextValue] (the latter being undefined for the last currentValue.
  • A function that returns an iterable over [currentValue, index].

rauschma avatar Feb 03 '21 06:02 rauschma

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

milahu avatar Nov 11 '21 06:11 milahu