GitHub user mdedetrich added a comment to the discussion: 
`StreamConverters.asInputStream` not workable when using broadcast with 
`ByteString` source?

> `StreamConverters.asInputStream` does not seem like a right tool for your 
> problem, at least to me.

Can you elaborate on this? To me `StreamConverters.asInputStream` is exactly 
what I need, or to put it differently if I was to write a function where I want 
to convert a `Souce[ByteString, _]` to `InputStream`, its function 
design/signature would look very similar.

Explained further you would use a materialized value to represent the 
`InputStream` (since its a reference that represents the entire stream) and 
hence you would have a `Sink[ByteString, InputStream]`. The only thing I would 
change is to return the `InputStream` inside a `Future`/`CompletionStage` to 
make it harder to use incorrectly since you are not allowed to block on it and 
other sinks do this as well (i.e. the various `FileIO` ones with `IOResult`).

Once I figure out the underlying result, I might even make a pull request for 
pekko 2 that would change `Sink[ByteString, InputStream]` to `Sink[ByteString, 
Future[InputStream]]` because as detailed in 
https://github.com/akka/akka/issues/23187, the blocking on `InputStream` in 
materialization stage is a common issue that happens all of the time.

> Higher-level stream operators are not always good enough, I would likely 
> consider using a [custom graph 
> stage](https://pekko.apache.org/docs/pekko/1.0/stream/stream-customize.html#custom-processing-with-graphstage)
>  to implement stateful processing that takes the `ByteString` elements as 
> input and returns the result of `Tika().detect` as output.

I would do this as a last resort as I have a strong suspicion that any graph 
stage implementation would like almost exactly the same as 
`StreamConverters.asInputStream` with only a few adjustments so I don't have 
the issue I am experiencing.

Or to put it differently, my instinct is telling me that the underlying issue 
is most likely a bug with `StreamConverters.asInputStream`, but I wanted to ask 
the community first to see if I am not doing something wildly wrong.

GitHub link: 
https://github.com/apache/pekko/discussions/1807#discussioncomment-12591556

----
This is an automatically sent email for notifications@pekko.apache.org.
To unsubscribe, please send an email to: 
notifications-unsubscr...@pekko.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@pekko.apache.org
For additional commands, e-mail: notifications-h...@pekko.apache.org

Reply via email to