jmonkey-test/src/main/scala/wow/doge/mygame/utils/package.scala

39 lines
1.0 KiB
Scala
Executable File

package wow.doge.mygame
import java.nio.file.StandardOpenOption
import monix.bio.UIO
import monix.execution.Scheduler
import monix.nio.file.AsyncFileChannelConsumer
import monix.nio.text.UTF8Codec.utf8Decode
import monix.nio.{file => mnf}
import wow.doge.mygame.implicits._
package object utils {
def methodName(implicit enclosing: sourcecode.Enclosing) =
enclosing.value.split(" ")(0).split("""\.""").last
def readAsync(
path: os.Path,
chunkSize: Int = 8192
) =
UIO
.deferAction(implicit s => UIO(mnf.readAsync(path.toNIO, chunkSize)))
.flatMap(bytes => UIO(bytes.pipeThrough(utf8Decode)))
@SuppressWarnings(Array("org.wartremover.warts.TraversableOps"))
def readAsyncL(
path: os.Path,
chunkSize: Int = 8192
) =
readAsync(path, chunkSize)
.flatMap(_.toListL.toIO)
.map(_.head)
def writeAsync(path: os.Path, flags: Seq[StandardOpenOption] = Seq.empty)(
implicit s: Scheduler
): AsyncFileChannelConsumer =
mnf.appendAsync(path.toNIO, 0, flags)
}