mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-20 17:39:54 +00:00
Add support for eml (rfc822 email) files
This commit is contained in:
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user