From 8f9f12f563d96de4d057999ceb6fa26b11c50591 Mon Sep 17 00:00:00 2001 From: David Francoeur Date: Wed, 13 Dec 2023 12:11:21 -0500 Subject: [PATCH] Avoid allocating a vector if you can use the underlying chunks (#1136) --- fs2-aws-s3/src/main/scala/fs2/aws/s3/S3.scala | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fs2-aws-s3/src/main/scala/fs2/aws/s3/S3.scala b/fs2-aws-s3/src/main/scala/fs2/aws/s3/S3.scala index d54504e5..5af07eba 100644 --- a/fs2-aws-s3/src/main/scala/fs2/aws/s3/S3.scala +++ b/fs2-aws-s3/src/main/scala/fs2/aws/s3/S3.scala @@ -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 @@ -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)