Skip to content

Commit

Permalink
fix platform utils
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-tennert committed Sep 26, 2024
1 parent bb3c362 commit 251ccb9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.github.jan.supabase.storage

import io.github.jan.supabase.storage.resumable.Fingerprint
import io.github.jan.supabase.storage.resumable.ResumableClient
import io.github.jan.supabase.storage.resumable.ResumableUpload
import io.ktor.util.cio.readChannel
import io.ktor.utils.io.discard
import java.io.File
Expand All @@ -14,18 +15,18 @@ import kotlin.io.path.fileSize
* If there is an url in the cache for the given [Fingerprint], the upload will be continued.
* @param file The file to upload
* @param path The path to upload the data to
* @param upsert Whether to overwrite existing files
* @param options The options for the upload
*/
suspend fun ResumableClient.createOrContinueUpload(path: String, file: File, upsert: Boolean = false) = createOrContinueUpload({ file.readChannel().apply { discard(it) } }, file.absolutePath, file.length(), path, upsert)
suspend fun ResumableClient.createOrContinueUpload(path: String, file: File, options: UploadOptionBuilder.() -> Unit = {}) = createOrContinueUpload({ file.readChannel().apply { discard(it) } }, file.absolutePath, file.length(), path, options)

/**
* Creates a new resumable upload or continues an existing one.
* If there is an url in the cache for the given [Fingerprint], the upload will be continued.
* @param file The file to upload
* @param path The path to upload the data to
* @param upsert Whether to overwrite existing files
* @param options The options for the upload
*/
suspend fun ResumableClient.createOrContinueUpload(path: String, file: Path, upsert: Boolean = false) = createOrContinueUpload({ file.readChannel().apply { discard(it) } }, file.absolutePathString(), file.fileSize(), path, upsert)
suspend fun ResumableClient.createOrContinueUpload(path: String, file: Path, options: UploadOptionBuilder.() -> Unit = {}) = createOrContinueUpload({ file.readChannel().apply { discard(it) } }, file.absolutePathString(), file.fileSize(), path, options)

/**
* Reads pending uploads from the cache and creates a new [ResumableUpload] for each of them. This done in parallel, so you can start the uploads independently.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import io.ktor.utils.io.jvm.javaio.toByteReadChannel
* Creates a new upload or continues an existing one from the given [uri]
* @param path The path to upload the file to
* @param uri The uri of the file to upload (make sure you have access to it)
* @param upsert Whether to overwrite an existing file
* @param options The options for the upload
*/
suspend fun ResumableClient.createOrContinueUpload(path: String, uri: Uri, upsert: Boolean = false) = createOrContinueUpload(uri.createByteReader(), uri.toString(), uri.contentSize, path, upsert)
suspend fun ResumableClient.createOrContinueUpload(path: String, uri: Uri, options: UploadOptionBuilder.() -> Unit = {}) = createOrContinueUpload(uri.createByteReader(), uri.toString(), uri.contentSize, path, options)

@SuppressLint("Recycle")
private suspend fun Uri.createByteReader(): suspend (Long) -> ByteReadChannel = { offset: Long ->
Expand Down

0 comments on commit 251ccb9

Please sign in to comment.