Skip to content

Commit

Permalink
Avoid copying of the underlying array in AsyncBody#asArray (#2923)
Browse files Browse the repository at this point in the history
Avoid copying of the underlying array in AsyncBody#asArray
  • Loading branch information
kyri-petrou authored Jun 21, 2024
1 parent fd5eb22 commit 033ab36
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion zio-http/jvm/src/main/scala/zio/http/netty/NettyBody.scala
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ object NettyBody extends BodyEncoding {
override val boundary: Option[Boundary] = None,
) extends Body {

override def asArray(implicit trace: Trace): Task[Array[Byte]] = asChunk.map(_.toArray)
override def asArray(implicit trace: Trace): Task[Array[Byte]] = asChunk.map {
case b: Chunk.ByteArray => b.array
case other => other.toArray
}

override def asChunk(implicit trace: Trace): Task[Chunk[Byte]] =
ZIO.async { cb =>
Expand Down

0 comments on commit 033ab36

Please sign in to comment.