Skip to content

Instantly share code, notes, and snippets.

@francescogatto
Created October 15, 2019 17:06
Show Gist options
  • Save francescogatto/319323024ff1c79cf3eb76e915fd107b to your computer and use it in GitHub Desktop.
Save francescogatto/319323024ff1c79cf3eb76e915fd107b to your computer and use it in GitHub Desktop.
#kkd
suspend fun HttpClient.downloadFile(file: File, url: String, callback: suspend (boolean: Boolean) -> Unit) {
val call = call {
url(url)
method = HttpMethod.Get
}
if (!call.response.status.isSuccess()) {
callback(false)
}
call.response.content.copyAndClose(file.writeChannel())
return callback(true)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment