Use with FS2
- sbt
libraryDependencies += "uk.gov.nationalarchives" %% "preservica-client-fs2" % "0.0.128"
- Maven
<dependencies> <dependency> <groupId>uk.gov.nationalarchives</groupId> <artifactId>preservica-client-fs2_3</artifactId> <version>0.0.128</version> </dependency> </dependencies>
- Gradle
dependencies { implementation "uk.gov.nationalarchives:preservica-client-fs2_3:0.0.128" }
Most of the methods in the list will work with either Cats effect or ZIO with the only difference being the effect type of cats.effect.IO
vs zio.Task
The exception is the method to stream bitstream content.
object PreservicaFs2 {
import cats.effect.IO
import cats.implicits.*
import sttp.capabilities.fs2.Fs2Streams
import uk.gov.nationalarchives.dp.client.fs2.Fs2Client
import java.util.UUID
val url = "https://test.preservica.com"
def processStream(name: String, stream: fs2.Stream[IO, Byte]): IO[Unit] = ???
def getAndProcessStream(): IO[Unit] = {
for {
client <- Fs2Client.entityClient(url, "secretName")
bitStreamInfo <- client.getBitstreamInfo(UUID.randomUUID())
_ <- bitStreamInfo
.map(eachBitStream => {
client.streamBitstreamContent[Unit](Fs2Streams.apply)(
eachBitStream.url,
stream => processStream(eachBitStream.name, stream) // Pass a function in to handle the stream
)
})
.sequence
} yield ()
}
}