Created
November 20, 2019 11:54
-
-
Save kellydavid/804303cd40622c117d7ae60b0d411661 to your computer and use it in GitHub Desktop.
Print lines of file using ZStream
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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