Reader

info.fingo.spata.io.Reader
See theReader companion object
sealed trait Reader[F[_]]

Reader interface with reading operations from various sources. The I/O operations are wrapped in effect F (e.g. cats.effect.IO), allowing deferred computation. The returned fs2.Stream allows further input processing in a very flexible, purely functional manner.

Processing I/O errors, manifested through java.io.IOException, should be handled with fs2.Stream.handleErrorWith. If not handled, they will propagate as exceptions.

Type parameters

F

the effect type

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Plain[F]
class Shifting[F]

Members list

Value members

Abstract methods

def read(source: Source): Stream[F, Char]

Reads a CSV source and returns a stream of character.

Reads a CSV source and returns a stream of character.

The caller of this function is responsible for proper resource acquisition and release. This may be done with fs2.Stream.bracket.

Character encoding has to be handled while creating scala.io.Source.

Value parameters

source

the source containing CSV content

Attributes

Returns

the stream of characters

Example
val stream = Stream
 .bracket(IO(Source.fromFile("input.csv")))(source => IO(source.close()))
 .flatMap(Reader[IO].read)
def read(fis: F[InputStream])(using codec: Codec): Stream[F, Char]

Reads a CSV source and returns a stream of character.

Reads a CSV source and returns a stream of character.

Value parameters

codec

codec used to convert bytes to characters, with default JVM charset as fallback

fis

input stream containing CSV content, wrapped in effect F to defer its creation

Attributes

Returns

the stream of characters

See also

read(source) for more information.

Note

This function does not close the input stream after use, which is different from default behavior of fs2-io functions taking InputStream as parameter.

def read(is: InputStream)(using codec: Codec): Stream[F, Char]

Reads a CSV source and returns a stream of character.

Reads a CSV source and returns a stream of character.

Value parameters

codec

codec used to convert bytes to characters, with default JVM charset as fallback

is

input stream containing CSV content

Attributes

Returns

the stream of characters

See also

read(source) for more information.

Note

This function does not close the input stream after use, which is different from default behavior of fs2-io functions taking InputStream as parameter.

def read(path: Path)(using codec: Codec): Stream[F, Char]

Reads a CSV file and returns a stream of character.

Reads a CSV file and returns a stream of character.

Value parameters

codec

codec used to convert bytes to characters, with default JVM charset as fallback

path

the path to source file

Attributes

Returns

the stream of characters

Example
given codec = new Codec(Charset.forName("UTF-8"))
val path = Path.of("data.csv")
val stream = Reader[IO](1024).read(path)

Concrete methods

def apply[A : CSV](csv: A)(implicit evidence$1: CSV[A], codec: Codec): Stream[F, Char]

Alias for various read methods.

Alias for various read methods.

Type parameters

A

type of source

Value parameters

codec

codec used to convert bytes to characters, with default JVM charset as fallback

csv

the CSV data

Attributes

Returns

the stream of characters

def apply(fis: F[InputStream])(using codec: Codec): Stream[F, Char]

Alias for read.

Alias for read.

Value parameters

codec

codec used to convert bytes to characters, with default JVM charset as fallback

fis

input stream containing CSV content, wrapped in effect F to defer its creation

Attributes

Returns

the stream of characters

def by[A : CSV](implicit evidence$2: CSV[A], codec: Codec): (F, A) => Char

Pipe converting stream with CSV source to stream of characters.

Pipe converting stream with CSV source to stream of characters.

Type parameters

A

type of source

Value parameters

codec

codec used to convert bytes to characters, with default JVM charset as fallback

Attributes

Returns

a pipe to converter CSV source into scala.Chars

Example
val stream = Stream
 .bracket(IO(Source.fromFile("input.csv")))(source => IO(source.close()))
 .through(Reader[IO].by)

Abstract fields

val chunkSize: Int

Size of data chunk loaded at once when reading from source. See also FS2 Chunks.

Size of data chunk loaded at once when reading from source. See also FS2 Chunks.

Attributes