Skip to content

Instantly share code, notes, and snippets.

@Vistritium
Created July 20, 2024 13:03
Show Gist options
  • Save Vistritium/e87bcbc0442b2fe7a0835e1606d05fc5 to your computer and use it in GitHub Desktop.
Save Vistritium/e87bcbc0442b2fe7a0835e1606d05fc5 to your computer and use it in GitHub Desktop.
def pipeThroughInputStream(pipeThrough: InputStream => InputStream)(implicit mat: Materializer): Flow[ByteString, ByteString, NotUsed] = {
Flow.lazyFlow { () =>
val sink = StreamConverters.asInputStream(5.minutes)
val (is, matSink) = sink.preMaterialize()
val source = StreamConverters.fromInputStream(() => pipeThrough(is))
Flow.fromSinkAndSource(matSink, source)
}.mapMaterializedValue(f =>
f.onComplete {
case Failure(exception) => logger.error("error", exception)
case Success(value) =>
}
akka.NotUsed
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment