-
Couldn't load subscription status.
- Fork 1.4k
Integrate ZStream with java.io.Reader #3928
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two small tweaks and this is good to go 💪🏻
| /** | ||
| * Creates a stream from [[java.io.Reader]]. | ||
| */ | ||
| def fromReader(reader: => Reader): ZStream[Blocking, IOException, Char] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahoy! Let's make this similar to fromInputStream. Important points:
- Chunking: there's a
readvariant that reads into a Char array and you can userepeatEffectOptionChunk - The by-name reader needs to be captured in value (otherwise it gets re-initialized every time)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good points. I was overeager to make this super simple :). Updated.
| e => ZIO.fail(Some(e)), | ||
| r => if (r == -1) ZIO.fail(None) else ZIO.succeed(r.toChar) | ||
| ) | ||
| def fromReader(reader: => Reader, chunkSize: Int = ZStream.DefaultChunkSize): ZStream[Blocking, IOException, Char] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I liked your previous approach with repeatEffectOption better :-) How about:
ZStream.fromEffect(reader).flatMap { capturedReader => ZStream.repeatEffectOptionChunk(...)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha, merged it, but dropped the exceptions used in first try.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw. should I do the same for fromInputStream?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah why not. Can you add a few tests for fromReader?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Superb, thank you!
Closes #3872