![JAR search and dependency download from the Maven repository](/logo.png)
dc10.io.FileWriter.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dc10-io_3 Show documentation
Show all versions of dc10-io_3 Show documentation
Code generation tools for Scala
The newest version!
package dc10.io
import cats.effect.Concurrent
import cats.syntax.all.*
import dc10.VirtualFile
import fs2.{Stream, text}
import fs2.io.file.{Files, Path}
trait FileWriter[F[_]]:
def writeFile(vf: VirtualFile): F[Path]
object FileWriter:
def apply[F[_]: Files: Concurrent]: FileWriter[F] =
new FileWriter[F]:
def writeFile(vf: VirtualFile): F[Path] =
for
d <- Concurrent[F].pure(Path.fromNioPath(vf.path.getParent()))
_ <- Files[F].createDirectories(d)
p <- Concurrent[F].pure(Path.fromNioPath(vf.path))
_ <- Stream(vf.contents)
.through(text.utf8.encode)
.through(Files[F].writeAll(p))
.compile
.drain
yield p
© 2015 - 2025 Weber Informatics LLC | Privacy Policy