Skip to content

Commit

Permalink
WIP add more file IO operations
Browse files Browse the repository at this point in the history
  • Loading branch information
LukaJCB committed Jul 16, 2019
1 parent 9827bee commit f94adf6
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion io/src/main/scala/fs2/io/file/file.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ import cats.effect.{Blocker, Concurrent, ContextShift, Resource, Sync, Timer}

/** Provides support for working with files. */
package object file {
import java.nio.file.CopyOption
import java.nio.file.LinkOption
import java.nio.file.Files

/**
* Reads all data synchronously from the file at the specified `java.nio.file.Path`.
*/
def readAll[F[_]: Sync: ContextShift](path: Path, blocker: Blocker, chunkSize: Int): Stream[F, Byte] =
def readAll[F[_]: Sync: ContextShift](path: Path,
blocker: Blocker,
chunkSize: Int): Stream[F, Byte] =
pulls
.fromPath(path, blocker, List(StandardOpenOption.READ))
.flatMap(c => pulls.readAllFromFileHandle(chunkSize)(c.resource))
Expand Down Expand Up @@ -117,4 +122,20 @@ package object file {
Stream
.resource(Watcher.default(blocker))
.flatMap(w => Stream.eval_(w.watch(path, types, modifiers)) ++ w.events(pollTimeout))

def exists[F[_]: Sync](path: Path, flags: Seq[LinkOption] = Seq.empty): F[Boolean] =
Sync[F].delay(Files.exists(path, flags: _*))

def copy[F[_]: Sync: ContextShift](blocker: Blocker, source: Path, target: Path, flags: Seq[CopyOption] = Seq.empty): F[Path] =
blocker.delay(Files.copy(source, target, flags: _*))

def delete[F[_]: Sync: ContextShift](blocker: Blocker, path: Path): F[Unit] =
blocker.delay(Files.delete(path))

def deleteIfExists[F[_]: Sync: ContextShift](blocker: Blocker, path: Path): F[Boolean] =
blocker.delay(Files.deleteIfExists(path))

def size[F[_]: Sync: ContextShift](blocker: Blocker, path: Path): F[Long] =
blocker.delay(Files.size(path))

}

0 comments on commit f94adf6

Please sign in to comment.