From cc86f8d609969b40793a227b9af4b41a18657dfb Mon Sep 17 00:00:00 2001 From: Jakob Odersky Date: Thu, 22 Mar 2018 15:47:42 -0700 Subject: Add blob storage abstractions --- .../xyz/driver/core/storage/BlobStorage.scala | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/main/scala/xyz/driver/core/storage/BlobStorage.scala (limited to 'src/main/scala/xyz/driver/core/storage/BlobStorage.scala') diff --git a/src/main/scala/xyz/driver/core/storage/BlobStorage.scala b/src/main/scala/xyz/driver/core/storage/BlobStorage.scala new file mode 100644 index 0000000..b12230e --- /dev/null +++ b/src/main/scala/xyz/driver/core/storage/BlobStorage.scala @@ -0,0 +1,45 @@ +package xyz.driver.core.storage + +import java.net.URL +import java.nio.file.Path + +import akka.stream.scaladsl.{Sink, Source} +import akka.util.ByteString +import akka.{Done, NotUsed} + +import scala.concurrent.Future +import scala.concurrent.duration.Duration + +/** Binary key-value store, typically implemented by cloud storage. */ +trait BlobStorage { + + /** Upload data by value. */ + def uploadContent(name: String, content: Array[Byte]): Future[String] + + /** Upload data from an existing file. */ + def uploadFile(name: String, content: Path): Future[String] + + def exists(name: String): Future[Boolean] + + /** List available keys. The prefix determines which keys should be listed + * and depends on the implementation (for instance, a file system backed + * blob store will treat a prefix as a directory path). */ + def list(prefix: String): Future[Set[String]] + + /** Get all the content of a given object. */ + def content(name: String): Future[Option[Array[Byte]]] + + /** Stream data asynchronously and with backpressure. */ + def download(name: String): Future[Option[Source[ByteString, NotUsed]]] + + /** Get a sink to upload data. */ + def upload(name: String): Future[Sink[ByteString, Future[Done]]] + + /** Delete a stored value. */ + def delete(name: String): Future[String] + +} + +trait SignedBlobStorage extends BlobStorage { + def signedDownloadUrl(name: String, duration: Duration): Future[Option[URL]] +} -- cgit v1.2.3