Skip to content

Commit

Permalink
Merge pull request #2955 from keirlawson/add-readutf8
Browse files Browse the repository at this point in the history
Add readUtf8 convenience method
  • Loading branch information
mpilquist committed Aug 9, 2022
2 parents 22f9bff + 657b729 commit 4539df9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions io/shared/src/main/scala/fs2/io/file/Files.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import cats.syntax.all._

import scala.concurrent.duration._
import cats.Traverse
import fs2.text

/** Provides operations related to working with files in the effect `F`.
*
Expand Down Expand Up @@ -273,6 +274,12 @@ sealed trait Files[F[_]] extends FilesPlatform[F] {
*/
def readRange(path: Path, chunkSize: Int, start: Long, end: Long): Stream[F, Byte]

/** Reads all bytes from the file specified and decodes them as a utf8 string. */
def readUtf8(path: Path): Stream[F, String]

/** Reads all bytes from the file specified and decodes them as utf8 lines. */
def readUtf8Lines(path: Path): Stream[F, String]

/** Returns the real path i.e. the actual location of `path`.
* The precise definition of this method is implementation dependent but in general
* it derives from this path, an absolute path that locates the same file as this path,
Expand Down Expand Up @@ -419,6 +426,12 @@ object Files extends FilesCompanionPlatform {
cursor.seek(start).readUntil(chunkSize, end).void.stream
}

def readUtf8(path: Path): Stream[F, String] =
readAll(path).through(text.utf8.decode)

def readUtf8Lines(path: Path): Stream[F, String] =
readUtf8(path).through(text.lines)

def tail(
path: Path,
chunkSize: Int,
Expand Down

0 comments on commit 4539df9

Please sign in to comment.