Skip to content

Commit

Permalink
Refactor example code
Browse files Browse the repository at this point in the history
  • Loading branch information
voidcontext committed Mar 15, 2020
1 parent eca857a commit d64dd3f
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions examples/src/main/scala/vdx/fetchfile/examples/Main.scala
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
package vdx.fetchfile
package examples
package vdx.fetchfile.examples

import cats.effect.{Blocker, IO, IOApp, ExitCode, Resource}
import cats.effect.{Clock => _, _}
import cats.syntax.functor._
import vdx.fetchfile._

import java.net.URL
import java.io.ByteArrayOutputStream
import java.io.{File, FileOutputStream}

object Main extends IOApp {
def run(args: List[String]): IO[ExitCode] = {

implicit val backend: Backend[IO] = HttpURLConnectionBackend[IO]
implicit val clock: Clock = Clock.system

val outFile = new File("/tmp/100MB.bin")

Blocker[IO].use { blocker =>
val out = new ByteArrayOutputStream()
Downloader[IO](blocker, 1024 * 8, Progress.consoleProgress[IO])
.fetch(
new URL("http://localhost:8088/100MB.bin"),
Resource.fromAutoCloseable(IO.delay(out)),

Resource.fromAutoCloseable(IO.delay(new FileOutputStream(outFile)))
)
.as(ExitCode.Success)
}
Expand Down

0 comments on commit d64dd3f

Please sign in to comment.