Skip to content

Instantly share code, notes, and snippets.

@kellydavid
Created November 20, 2019 11:54
Show Gist options
  • Save kellydavid/804303cd40622c117d7ae60b0d411661 to your computer and use it in GitHub Desktop.
Save kellydavid/804303cd40622c117d7ae60b0d411661 to your computer and use it in GitHub Desktop.
Print lines of file using ZStream
import zio._
object PrintBytes extends App {
import zio.stream._
import zio.console._
import zio.duration._
val fileName = "src/main/resources/world-cities_csv.csv"
def fileStream: StreamChunk[IOException, Byte] =
Stream.fromInputStream(new FileInputStream(fileName), 10)
override def run(args: List[String]): ZIO[zio.ZEnv, Nothing, Int] =
fileStream.chunks
.transduce(ZSink.utf8DecodeChunk)
.chunkN(20)
.tap(str => putStr(str.mkString) *> ZIO.sleep(1.second))
// .mapM(str => putStr(str.mkString) *> ZIO.sleep(1.second).as(str))
// .mapM(str => ZIO.sleep(1.second).as(str))
.runDrain.fold(_ => 1, _ => 0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment