Signed-off-by: denis0001-dev <denis0001.dev@ya.ru>
This commit is contained in:
2026-02-19 01:20:27 +03:00
Unverified
parent 928d00b665
commit 323ec99c12
9 changed files with 478 additions and 166 deletions
@@ -0,0 +1,57 @@
package com.pr0gramm3r101.utils.files
/**
* Multiplatform file system API for basic file operations.
* Use [getAppCacheDirectory] to obtain the platform cache directory.
*/
object PlatformFileSystem {
/**
* Returns true if a file exists at the given path.
*/
fun exists(path: String): Boolean = expectExists(path)
/**
* Writes [bytes] to the file at [path], overwriting if it exists.
*/
fun writeBytes(path: String, bytes: ByteArray) {
expectWriteBytes(path, bytes)
}
/**
* Deletes the file at [path]. No-op if the file does not exist.
*/
fun delete(path: String) {
expectDelete(path)
}
/**
* Deletes all files in the directory [dirPath] whose filename starts with [namePrefix].
*/
fun deleteFilesWithPrefix(dirPath: String, namePrefix: String) {
expectDeleteFilesWithPrefix(dirPath, namePrefix)
}
/**
* Returns the platform-specific application cache directory path.
* On Android: context.cacheDir (requires UtilsLibrary.init to be called).
* On iOS: NSCachesDirectory.
*/
fun getAppCacheDirectory(): String = expectGetAppCacheDirectory()
/**
* Creates the directory at [path] if it does not exist.
* Returns the absolute path.
*/
fun ensureDirectory(path: String): String {
expectEnsureDirectory(path)
return path
}
}
internal expect fun expectExists(path: String): Boolean
internal expect fun expectWriteBytes(path: String, bytes: ByteArray)
internal expect fun expectDelete(path: String)
internal expect fun expectDeleteFilesWithPrefix(dirPath: String, namePrefix: String)
internal expect fun expectGetAppCacheDirectory(): String
internal expect fun expectEnsureDirectory(path: String)