From b7d78a33825586aa40e16b3c8de5878175051899 Mon Sep 17 00:00:00 2001 From: Leif Warner Date: Wed, 13 Nov 2024 12:13:47 -0800 Subject: [PATCH] Remove checking for negative array size Consolidate two subsequent `.flatMap`s into one. --- fs2-aws-s3/src/main/scala/fs2/aws/s3/S3.scala | 15 +++------------ 1 file changed, 3 insertions(+), 12 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 919ed845..0af599f0 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 @@ -324,20 +324,11 @@ object S3 { .last .flatMap { case Some(resp) => - Pull.pure { - val bs = resp.asByteArrayUnsafe - Option.when(bs.length >= 0)(Chunk.array(bs)) - } + val chunk = Chunk.array(resp.asByteArrayUnsafe) + Pull.output(chunk) >> (if (chunk.size < chunkSizeBytes) Pull.done else go(offset + chunk.size)) case None => - Pull.pure(none) - } - .flatMap { - case Some(o) => - if (o.size < chunkSizeBytes) Pull.output(o) - else Pull.output(o) >> go(offset + o.size) - case None => Pull.done + Pull.done } - go(0).stream }