Skip to content

Commit

Permalink
Avoid allocating a vector if you can use the underlying chunks (#1136)
Browse files Browse the repository at this point in the history
  • Loading branch information
daddykotex authored Dec 13, 2023
1 parent 4324f32 commit 8f9f12f
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions fs2-aws-s3/src/main/scala/fs2/aws/s3/S3.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import io.laserdisc.pure.s3.tagless.S3AsyncClientOp
import software.amazon.awssdk.core.async.{AsyncRequestBody, AsyncResponseTransformer}
import software.amazon.awssdk.services.s3.model.*

import java.nio.ByteBuffer
import java.security.MessageDigest
import scala.collection.immutable.ArraySeq
import scala.collection.immutable.ArraySeq.unsafeWrapArray
Expand Down Expand Up @@ -116,8 +115,8 @@ object S3 {
def uploadFile(bucket: BucketName, key: FileKey, modifier: AwsRequestModifier.Upload1): Pipe[F, Byte, ETag] =
in =>
fs2.Stream.eval {
in.compile.toVector.flatMap { vs =>
val bs = ByteBuffer.wrap(vs.toArray)
in.compile.to(Chunk).flatMap { chunks =>
val bs = chunks.toByteBuffer
s3.putObject(
modifier.putObject(PutObjectRequest.builder().bucket(bucket.value).key(key.value)).build(),
AsyncRequestBody.fromByteBuffer(bs)
Expand Down

0 comments on commit 8f9f12f

Please sign in to comment.