mirror of
https://github.com/fromchat-messenger/app.git
synced 2026-09-22 19:15:05 +03:00
Implement robust file downloading, uploading and opening
Signed-off-by: denis0001-dev <denis0001.dev@ya.ru>
This commit is contained in:
+16
@@ -18,6 +18,15 @@ object PlatformFileSystem {
|
||||
expectWriteBytes(path, bytes)
|
||||
}
|
||||
|
||||
/** Appends [bytes] to the file at [path], creating it when missing. */
|
||||
fun appendBytes(path: String, bytes: ByteArray) {
|
||||
if (bytes.isEmpty()) return
|
||||
expectAppendBytes(path, bytes)
|
||||
}
|
||||
|
||||
/** Size in bytes, or 0 when the file does not exist. */
|
||||
fun fileSize(path: String): Long = expectFileSize(path)
|
||||
|
||||
/**
|
||||
* Deletes the file at [path]. No-op if the file does not exist.
|
||||
*/
|
||||
@@ -32,6 +41,10 @@ object PlatformFileSystem {
|
||||
expectDeleteFilesWithPrefix(dirPath, namePrefix)
|
||||
}
|
||||
|
||||
/** Returns filenames (not paths) in [dirPath], or empty if the directory is missing. */
|
||||
fun listFileNamesInDirectory(dirPath: String): List<String> =
|
||||
expectListFileNamesInDirectory(dirPath)
|
||||
|
||||
/**
|
||||
* Returns the platform-specific application cache directory path.
|
||||
* On Android: context.cacheDir (requires UtilsLibrary.init to be called).
|
||||
@@ -51,7 +64,10 @@ object PlatformFileSystem {
|
||||
|
||||
internal expect fun expectExists(path: String): Boolean
|
||||
internal expect fun expectWriteBytes(path: String, bytes: ByteArray)
|
||||
internal expect fun expectAppendBytes(path: String, bytes: ByteArray)
|
||||
internal expect fun expectFileSize(path: String): Long
|
||||
internal expect fun expectDelete(path: String)
|
||||
internal expect fun expectDeleteFilesWithPrefix(dirPath: String, namePrefix: String)
|
||||
internal expect fun expectListFileNamesInDirectory(dirPath: String): List<String>
|
||||
internal expect fun expectGetAppCacheDirectory(): String
|
||||
internal expect fun expectEnsureDirectory(path: String)
|
||||
|
||||
Reference in New Issue
Block a user