3

I'm reading and writing to an external process using two Pipes. Every command response will be terminated by "\n] ". I'm currently reading from the pipe as an AsyncSequence (readPipe.fileHandleForReading.bytes.characters). I'd like to read from the pipe until the terminator sequence.

I know how to roll my own solution to this, accumulating characters in a window and checking for the delimiter, but I was surprised that there wasn't anything a little more out-of-the-box, including in AsyncAlgorithms. Is there a way to split/chunk an AsyncSequence on a multi-element delimiter, or anything similar to that?

Rob Napier
  • 286,113
  • 34
  • 456
  • 610
  • 1
    Yeah, [`lines`](https://developer.apple.com/documentation/foundation/filehandle/asyncbytes/3766668-lines) works great if your terminator is just a newline. But I think you're going to have to roll your own if you need to use this multi-character terminator. Like you, I'm not seeing anything that does this for you amongst the usual suspects. – Rob Nov 06 '22 at 06:14

0 Answers0