Skip to content

Instantly share code, notes, and snippets.

@lordcodes
Created February 25, 2020 20:19
Show Gist options
  • Save lordcodes/2330e00d30c05bf08a2dd2c5a0532349 to your computer and use it in GitHub Desktop.
Save lordcodes/2330e00d30c05bf08a2dd2c5a0532349 to your computer and use it in GitHub Desktop.
Code for the article: "Uploading a file with progress in Kotlin"
class CountingRequestBody(...) : RequestBody() {
...
@Throws(IOException::class)
override fun writeTo(sink: BufferedSink) {
val countingSink = CountingSink(sink, this, onProgressUpdate)
val bufferedSink = countingSink.buffer()
requestBody.writeTo(bufferedSink)
bufferedSink.flush()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment