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

> Would it be possible to write a custom stage that materialises a ByteString 
> and then you can call asInputStream on the ByteString instance?

I am not sure what you mean by "materialize a ByteString" because the source 
streams don't have `ByteString` in the materialization, instead its part of the 
actual stream.

As an example, `FileIO.fromPath` which creates a source from a file has the 
following type signature `Source[ByteString, Future[IOResult]]`. In this case 
the materialized value is `Future[IOResult]` and not `ByteString` as the 
`ByteString` is being streamed behind the scenes and the `Future[IOResult]` is 
the materialized value which represents whether the file operation is 
successful (or not) and the reason why its in a `Future` is because 
materialized values have to be returned before the stream starts and so in this 
specific case the `Future` would get completed when the stream finishes 
(successfully or not).

However if by "materialize a ByteString" you mean evaluating the 
`Source[ByteString, _]` to get the bytestring out, yes you can do that but then 
you are essentially evaluated the whole stream so its not really a stream 
anymore. 

I guess you could jerry rig a `Sink.foreach` so that you could manually push 
`ByteString` chunks into a manually created `InputStream` but this would just 
be a more primitive implementation of what currently exists.

I have another theory which is that `.alsoToMat` which internally uses 
`Broadcast` (and this is what should be copying the ByteString in the fanout) 
has `eagerCancel` set to true and this is what may be causing issues. I will 
try this out next week as I can't do it right now.

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

----
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