mirror of
https://github.com/fromchat-messenger/app.git
synced 2026-09-23 03:25:06 +03:00
Implement robust file downloading, uploading and opening
Signed-off-by: denis0001-dev <denis0001.dev@ya.ru>
This commit is contained in:
+17
@@ -12,6 +12,17 @@ internal actual fun expectWriteBytes(path: String, bytes: ByteArray) {
|
||||
file.writeBytes(bytes)
|
||||
}
|
||||
|
||||
internal actual fun expectAppendBytes(path: String, bytes: ByteArray) {
|
||||
val file = File(path)
|
||||
file.parentFile?.mkdirs()
|
||||
file.appendBytes(bytes)
|
||||
}
|
||||
|
||||
internal actual fun expectFileSize(path: String): Long {
|
||||
val file = File(path)
|
||||
return if (file.isFile) file.length() else 0L
|
||||
}
|
||||
|
||||
internal actual fun expectDelete(path: String) {
|
||||
File(path).delete()
|
||||
}
|
||||
@@ -26,6 +37,12 @@ internal actual fun expectDeleteFilesWithPrefix(dirPath: String, namePrefix: Str
|
||||
}
|
||||
}
|
||||
|
||||
internal actual fun expectListFileNamesInDirectory(dirPath: String): List<String> {
|
||||
val dir = File(dirPath)
|
||||
if (!dir.isDirectory) return emptyList()
|
||||
return dir.listFiles()?.map { it.name } ?: emptyList()
|
||||
}
|
||||
|
||||
internal actual fun expectGetAppCacheDirectory(): String =
|
||||
UtilsLibrary.context.cacheDir.absolutePath
|
||||
|
||||
|
||||
Reference in New Issue
Block a user