Improve performance of zip/unzip

Adds tests and includes some cleanup
This commit is contained in:
eikek
2022-06-18 16:37:38 +02:00
parent 483dbf5d2b
commit 6cef9d4f07
24 changed files with 711 additions and 293 deletions

View File

@ -13,7 +13,7 @@ import fs2.io.file.{Files, Path, PosixPermissions}
import docspell.addons.out.AddonOutput
import docspell.common.LenientUri
import docspell.files.Zip
import docspell.common.util.Zip
import io.circe.syntax._
@ -59,9 +59,9 @@ object AddonGenerator {
private def createZip(dir: Path, files: List[Path]) =
Stream
.emits(files)
.map(f => (f.fileName.toString, Files[IO].readAll(f)))
.map(f => (f.fileName.toString, f))
.covary[IO]
.through(Zip.zip[IO](logger, 8192))
.through(Zip[IO](logger.some).zipFiles())
.through(Files[IO].writeAll(dir / "addon.zip"))
.compile
.drain

View File

@ -7,9 +7,10 @@
package docspell.addons
import cats.effect._
import cats.syntax.all._
import docspell.common.Glob
import docspell.files.Zip
import docspell.common.util.{Directory, Zip}
import docspell.logging.TestLoggingConfig
import munit._
@ -26,8 +27,8 @@ class AddonMetaTest extends CatsEffectSuite with TestLoggingConfig with Fixtures
for {
_ <- dummyAddonUrl
.readURL[IO](8192)
.through(Zip.unzip(8192, Glob.all))
.through(Zip.saveTo(logger, dir, moveUp = true))
.through(Zip[IO]().unzip(8192, Glob.all, dir.some))
.evalTap(_ => Directory.unwrapSingle(logger, dir))
.compile
.drain
meta <- AddonMeta.findInDirectory[IO](dir)