Skip to content

Commit 4539df9

Browse files
authored
Merge pull request #2955 from keirlawson/add-readutf8
Add readUtf8 convenience method
2 parents 22f9bff + 657b729 commit 4539df9

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

io/shared/src/main/scala/fs2/io/file/Files.scala

+13
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import cats.syntax.all._
3030

3131
import scala.concurrent.duration._
3232
import cats.Traverse
33+
import fs2.text
3334

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

277+
/** Reads all bytes from the file specified and decodes them as a utf8 string. */
278+
def readUtf8(path: Path): Stream[F, String]
279+
280+
/** Reads all bytes from the file specified and decodes them as utf8 lines. */
281+
def readUtf8Lines(path: Path): Stream[F, String]
282+
276283
/** Returns the real path i.e. the actual location of `path`.
277284
* The precise definition of this method is implementation dependent but in general
278285
* it derives from this path, an absolute path that locates the same file as this path,
@@ -419,6 +426,12 @@ object Files extends FilesCompanionPlatform {
419426
cursor.seek(start).readUntil(chunkSize, end).void.stream
420427
}
421428

429+
def readUtf8(path: Path): Stream[F, String] =
430+
readAll(path).through(text.utf8.decode)
431+
432+
def readUtf8Lines(path: Path): Stream[F, String] =
433+
readUtf8(path).through(text.lines)
434+
422435
def tail(
423436
path: Path,
424437
chunkSize: Int,

0 commit comments

Comments
 (0)