Skip to content

Commit

Permalink
Close S3 objects to release connection resources
Browse files Browse the repository at this point in the history
  • Loading branch information
shazraz authored and mpawliszyn committed May 2, 2023
1 parent 83eb314 commit d67d14a
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,18 @@ class RealS3Service @Inject constructor(

override fun getFileStreamStartingAt(bucket: String, key: String, start: Long): BufferedSource {
val s3Object = amazonS3.getObject(GetObjectRequest(bucket, key).withRange(start))
return s3Object.objectContent.source().buffer()
return s3Object.use {
it.objectContent.source().buffer()
}
}

override fun getWithSeek(bucket: String, key: String, seekStart: Long, seekEnd: Long): ByteString {
val s3Object = amazonS3.getObject(GetObjectRequest(bucket, key).withRange(seekStart, seekEnd))
return Buffer().run {
writeAll(s3Object.objectContent.source())
readByteString()
s3Object.use {
writeAll(it.objectContent.source())
readByteString()
}
}
}
}

0 comments on commit d67d14a

Please sign in to comment.