Upgrade code base to CE3

This commit is contained in:
eikek
2021-06-21 21:33:54 +02:00
parent 903ec26e54
commit bd791b4593
146 changed files with 638 additions and 758 deletions

View File

@ -13,28 +13,19 @@ import docspell.common.Glob
object Zip {
def unzipP[F[_]: ConcurrentEffect: ContextShift](
chunkSize: Int,
blocker: Blocker,
glob: Glob
): Pipe[F, Byte, Binary[F]] =
s => unzip[F](chunkSize, blocker, glob)(s)
def unzipP[F[_]: Async](chunkSize: Int, glob: Glob): Pipe[F, Byte, Binary[F]] =
s => unzip[F](chunkSize, glob)(s)
def unzip[F[_]: ConcurrentEffect: ContextShift](
chunkSize: Int,
blocker: Blocker,
glob: Glob
)(
def unzip[F[_]: Async](chunkSize: Int, glob: Glob)(
data: Stream[F, Byte]
): Stream[F, Binary[F]] =
data
.through(fs2.io.toInputStream[F])
.flatMap(in => unzipJava(in, chunkSize, blocker, glob))
.flatMap(in => unzipJava(in, chunkSize, glob))
def unzipJava[F[_]: Sync: ContextShift](
def unzipJava[F[_]: Async](
in: InputStream,
chunkSize: Int,
blocker: Blocker,
glob: Glob
): Stream[F, Binary[F]] = {
val zin = new ZipInputStream(in)
@ -52,7 +43,7 @@ object Zip {
.map { ze =>
val name = Paths.get(ze.getName()).getFileName.toString
val data =
fs2.io.readInputStream[F]((zin: InputStream).pure[F], chunkSize, blocker, false)
fs2.io.readInputStream[F]((zin: InputStream).pure[F], chunkSize, false)
Binary(name, data)
}
}

View File

@ -1,16 +1,14 @@
package docspell.files
import scala.concurrent.ExecutionContext
import scala.util.Using
import cats.effect.{Blocker, IO}
import cats.effect._
import cats.effect.unsafe.implicits.global
import cats.implicits._
import munit._
class ImageSizeTest extends FunSuite {
val blocker = Blocker.liftExecutionContext(ExecutionContext.global)
implicit val CS = IO.contextShift(ExecutionContext.global)
//tiff files are not supported on the jdk by default
//requires an external library
@ -37,7 +35,7 @@ class ImageSizeTest extends FunSuite {
test("get sizes from stream") {
files.foreach { case (uri, expect) =>
val stream = uri.readURL[IO](8192, blocker)
val stream = uri.readURL[IO](8192)
val dim = ImageSize.get(stream).unsafeRunSync()
assertEquals(dim, expect.some)
}

View File

@ -1,19 +1,17 @@
package docspell.files
import scala.concurrent.ExecutionContext
import cats.effect._
import cats.effect.unsafe.implicits.global
import docspell.common.MimeTypeHint
object Playing extends IOApp {
val blocker = Blocker.liftExecutionContext(ExecutionContext.global)
def run(args: List[String]): IO[ExitCode] =
IO {
//val ods = ExampleFiles.examples_sample_ods.readURL[IO](8192, blocker)
//val odt = ExampleFiles.examples_sample_odt.readURL[IO](8192, blocker)
val rtf = ExampleFiles.examples_sample_rtf.readURL[IO](8192, blocker)
val rtf = ExampleFiles.examples_sample_rtf.readURL[IO](8192)
val x = for {
odsm1 <-

View File

@ -1,29 +1,26 @@
package docspell.files
import scala.concurrent.ExecutionContext
import cats.effect.{Blocker, IO}
import cats.effect._
import cats.effect.unsafe.implicits.global
import fs2.Stream
object TestFiles {
val blocker = Blocker.liftExecutionContext(ExecutionContext.global)
implicit val CS = IO.contextShift(ExecutionContext.global)
val letterSourceDE: Stream[IO, Byte] =
ExampleFiles.letter_de_pdf
.readURL[IO](8 * 1024, blocker)
.readURL[IO](8 * 1024)
val letterSourceEN: Stream[IO, Byte] =
ExampleFiles.letter_en_pdf
.readURL[IO](8 * 1024, blocker)
.readURL[IO](8 * 1024)
lazy val letterDEText =
ExampleFiles.letter_de_txt
.readText[IO](8 * 1024, blocker)
.readText[IO](8 * 1024)
.unsafeRunSync()
lazy val letterENText =
ExampleFiles.letter_en_txt
.readText[IO](8 * 1024, blocker)
.readText[IO](8 * 1024)
.unsafeRunSync()
}

View File

@ -1,8 +1,7 @@
package docspell.files
import scala.concurrent.ExecutionContext
import cats.effect._
import cats.effect.unsafe.implicits.global
import cats.implicits._
import docspell.common.Glob
@ -11,12 +10,9 @@ import munit._
class ZipTest extends FunSuite {
val blocker = Blocker.liftExecutionContext(ExecutionContext.global)
implicit val CS = IO.contextShift(ExecutionContext.global)
test("unzip") {
val zipFile = ExampleFiles.letters_zip.readURL[IO](8192, blocker)
val uncomp = zipFile.through(Zip.unzip(8192, blocker, Glob.all))
val zipFile = ExampleFiles.letters_zip.readURL[IO](8192)
val uncomp = zipFile.through(Zip.unzip(8192, Glob.all))
uncomp
.evalMap { entry =>