Skip to content

Commit 7a2ca5c

Browse files
add StorageReference
1 parent f0d874f commit 7a2ca5c

File tree

4 files changed

+63
-0
lines changed
  • firebase-storage/src
    • androidMain/kotlin/dev/gitlive/firebase/storage
    • commonMain/kotlin/dev/gitlive/firebase/storage
    • iosMain/kotlin/dev/gitlive/firebase/storage
    • jsMain/kotlin/dev/gitlive/firebase/storage

4 files changed

+63
-0
lines changed

firebase-storage/src/androidMain/kotlin/dev/gitlive/firebase/storage/storage.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,15 @@ actual class FirebaseStorage(val android: com.google.firebase.storage.FirebaseSt
3535

3636
}
3737

38+
actual class StorageReference(val android: com.google.firebase.storage.StorageReference) {
39+
actual val name: String get() = android.name
40+
actual val path: String get() = android.path
41+
actual val bucket: String get() = android.bucket
42+
actual val parent: StorageReference? get() = android.parent?.let { StorageReference(it) }
43+
actual val root: StorageReference get() = StorageReference(android.root)
44+
actual val storage: FirebaseStorage get() = FirebaseStorage(android.storage)
45+
46+
actual fun child(path: String): StorageReference = StorageReference(android.child(path))
47+
}
48+
3849
actual open class StorageException(message: String) : FirebaseException(message)

firebase-storage/src/commonMain/kotlin/dev/gitlive/firebase/storage/storage.kt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,33 @@ expect class FirebaseStorage {
1919
fun useEmulator(host: String, port: Int)
2020
}
2121

22+
expect class StorageReference {
23+
val name: String
24+
val path: String
25+
val bucket: String
26+
val parent: StorageReference?
27+
val root: StorageReference
28+
val storage: FirebaseStorage
29+
fun child(path: String): StorageReference
30+
// fun delete(): Task<Unit>
31+
// fun downloadUrl(): Task<Uri>
32+
// fun getBytes(maxDownloadSizeBytes: Long): Task<ByteArray>
33+
// fun getMetadata(): Task<StorageMetadata>
34+
// fun list(options: ListOptions? = definedExternally): Task<ListResult>
35+
// fun listAll(): Task<ListResult>
36+
// fun putBytes(bytes: ByteArray, metadata: StorageMetadata? = definedExternally): UploadTask
37+
// fun putFile(file: Uri, metadata: StorageMetadata? = definedExternally): UploadTask
38+
// fun putFile(file: Uri, metadata: StorageMetadata? = definedExternally, existingUploadUri: Uri? = definedExternally): UploadTask
39+
// fun putFile(file: Uri, metadata: StorageMetadata? = definedExternally, existingUploadUri: Uri? = definedExternally, existingUploadHeaders: Map<String, String>? = definedExternally): UploadTask
40+
// fun putStream(stream: InputStream, metadata: StorageMetadata? = definedExternally): UploadTask
41+
// fun updateMetadata(metadata: StorageMetadata): Task<StorageMetadata>
42+
// fun getStream(maxDownloadSizeBytes: Long = definedExternally): Flow<ByteReadPacket>
43+
// fun getStream(maxDownloadSizeBytes: Long = definedExternally, progressListener: StreamDownloadTask.StreamProcessor): Flow<ByteReadPacket>
44+
// fun getStream(maxDownloadSizeBytes: Long = definedExternally, progressListener: StreamDownloadTask.StreamProcessor, cancellationFlow: Flow<Unit>): Flow<ByteReadPacket>
45+
// fun getStream(maxDownloadSizeBytes: Long = definedExternally, progressListener: StreamDownloadTask.StreamProcessor, cancellationFlow: Flow<Unit>, executor: Executor): Flow<ByteReadPacket>
46+
// fun getStream(maxDownloadSizeBytes: Long = definedExternally, progressListener: StreamDownloadTask.StreamProcessor, cancellationFlow: Flow<Unit>, executor: Executor, bufferSize: Int): Flow<ByteReadPacket>
47+
// fun getStream(maxDownloadSizeBytes: Long = definedExternally, progressListener: StreamDownloadTask.StreamProcessor, cancellationFlow: Flow<Unit>, executor: Executor, bufferSize: Int, chunkSize: Int): Flow<ByteReadPacket>
48+
// fun getStream(maxDownloadSizeBytes: Long = definedExternally, progressListener: StreamDownloadTask.Stream
49+
}
50+
2251
expect open class StorageException : FirebaseException

firebase-storage/src/iosMain/kotlin/dev/gitlive/firebase/storage/storage.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package dev.gitlive.firebase.storage
66

77
import cocoapods.FirebaseStorage.FIRStorage
8+
import cocoapods.FirebaseStorage.FIRStorageReference
89
import dev.gitlive.firebase.Firebase
910
import dev.gitlive.firebase.FirebaseApp
1011
import dev.gitlive.firebase.FirebaseException
@@ -37,4 +38,15 @@ actual class FirebaseStorage(val ios: FIRStorage) {
3738

3839
}
3940

41+
actual class StorageReference(val ios: FIRStorageReference) {
42+
actual val name: String get() = ios.name()
43+
actual val path: String get() = ios.fullPath()
44+
actual val bucket: String get() = ios.bucket()
45+
actual val parent: StorageReference? get() = ios.parent()?.let { StorageReference(it) }
46+
actual val root: StorageReference get() = StorageReference(ios.root())
47+
actual val storage: FirebaseStorage get() = FirebaseStorage(ios.storage())
48+
49+
actual fun child(path: String): StorageReference = StorageReference(ios.child(path))
50+
}
51+
4052
actual open class StorageException(message: String) : FirebaseException(message)

firebase-storage/src/jsMain/kotlin/dev/gitlive/firebase/storage/storage.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ actual class FirebaseStorage(val js: firebase.storage.Storage) {
3636

3737
}
3838

39+
actual class StorageReference(val js: firebase.storage.Reference) {
40+
actual val path: String get() = js.fullPath
41+
actual val name: String get() = js.name
42+
actual val bucket: String get() = js.bucket
43+
actual val parent: StorageReference? get() = js.parent?.let { StorageReference(it) }
44+
actual val root: StorageReference get() = StorageReference(js.root)
45+
actual val storage: FirebaseStorage get() = FirebaseStorage(js.storage)
46+
47+
actual fun child(path: String): StorageReference = StorageReference(js.child(path))
48+
}
49+
3950
inline fun <T, R> T.rethrow(function: T.() -> R): R = dev.gitlive.firebase.storage.rethrow { function() }
4051

4152
inline fun <R> rethrow(function: () -> R): R {

0 commit comments

Comments
 (0)