Skip to content

Commit

Permalink
Add S3ByteArrayFetching as a guiding alias
Browse files Browse the repository at this point in the history
  • Loading branch information
rtyley committed Dec 12, 2024
1 parent 1f11a91 commit be27f5c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.gu.etagcaching.aws.sdkv2.s3

import com.gu.etagcaching.Endo
import com.gu.etagcaching.aws.s3.ObjectId
import com.gu.etagcaching.aws.s3.{ObjectId, S3ByteArrayFetching, S3ObjectFetchingUsing}
import com.gu.etagcaching.aws.sdkv2.s3.response.Transformer
import com.gu.etagcaching.aws.sdkv2.s3.response.Transformer.Bytes
import com.gu.etagcaching.fetching.{ETaggedData, Fetching, Missing, MissingOrETagged}
import software.amazon.awssdk.core.internal.util.ThrowableUtils
import software.amazon.awssdk.services.s3.S3AsyncClient
Expand Down Expand Up @@ -42,3 +43,10 @@ case class S3ObjectFetching[Response](s3Client: S3AsyncClient, transformer: Tran
}
}

object S3ObjectFetching extends S3ObjectFetchingUsing[S3AsyncClient] {
/**
* Convenience method for creating a fetcher that just returns a simple byte array.
*/
def byteArrayWith(s3AsyncClient: S3AsyncClient): S3ByteArrayFetching =
S3ObjectFetching(s3AsyncClient, Bytes).mapResponse(_.asByteArray())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.gu.etagcaching.aws.s3

trait S3ObjectFetchingUsing[AWSClient] {
def byteArrayWith(awsClient: AWSClient): S3ByteArrayFetching
}
18 changes: 18 additions & 0 deletions aws-s3/base/src/main/scala/com/gu/etagcaching/aws/s3/package.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.gu.etagcaching.aws

import com.gu.etagcaching.fetching.Fetching

package object s3 {
/**
* To get an instance of `S3ByteArrayFetching`, add "com.gu.etag-caching" %% "aws-s3-sdk-v2"
* as a dependency, then:
*
* {{{
* import com.gu.etagcaching.aws.sdkv2.s3.S3ObjectFetching
*
* val s3AsyncClient: software.amazon.awssdk.services.s3.S3AsyncClient = ??? // use AWS SDK v2
* val s3Fetching: S3ByteArrayFetching = S3ObjectFetching.byteArrayWith(s3AsyncClient)
* }}}
*/
type S3ByteArrayFetching = Fetching[ObjectId, Array[Byte]]
}

0 comments on commit be27f5c

Please sign in to comment.