Add support for eml (rfc822 email) files

This commit is contained in:
Eike Kettner
2020-03-19 22:42:40 +01:00
parent 4ed7a137f7
commit 6b1156182c
4 changed files with 142 additions and 25 deletions

View File

@ -6,27 +6,26 @@ import fs2.{Pipe, Stream}
import java.io.InputStream
import java.util.zip.ZipInputStream
import java.nio.file.Paths
import docspell.common.Binary
object Zip {
case class Entry[F[_]](name: String, data: Stream[F, Byte])
def unzipP[F[_]: ConcurrentEffect: ContextShift](
chunkSize: Int,
blocker: Blocker
): Pipe[F, Byte, Entry[F]] =
): Pipe[F, Byte, Binary[F]] =
s => unzip[F](chunkSize, blocker)(s)
def unzip[F[_]: ConcurrentEffect: ContextShift](chunkSize: Int, blocker: Blocker)(
data: Stream[F, Byte]
): Stream[F, Entry[F]] =
): Stream[F, Binary[F]] =
data.through(fs2.io.toInputStream[F]).flatMap(in => unzipJava(in, chunkSize, blocker))
def unzipJava[F[_]: Sync: ContextShift](
in: InputStream,
chunkSize: Int,
blocker: Blocker
): Stream[F, Entry[F]] = {
): Stream[F, Binary[F]] = {
val zin = new ZipInputStream(in)
val nextEntry = Resource.make(Sync[F].delay(Option(zin.getNextEntry))) {
@ -42,7 +41,7 @@ object Zip {
val name = Paths.get(ze.getName()).getFileName.toString
val data =
fs2.io.readInputStream[F]((zin: InputStream).pure[F], chunkSize, blocker, false)
Entry(name, data)
Binary(name, data)
}
}
}