google / modernstorage

ModernStorage is a group of libraries that provide an abstraction layer over storage on Android to simplify its interactions
https://google.github.io/modernstorage/
Apache License 2.0
1.24k stars 60 forks source link

Add support for file paths #87

Closed yrezgui closed 2 years ago

yrezgui commented 2 years ago

With this PR, Path can be Uri but also java.io.File paths, allowing interactions with internal storage.

One very cool feature enabled with these changes would be to copy a MediaStore image to internal storage simply:

val fileSystem = AndroidFileSystem(context)

// Image taken from MediaStore
val imageUri = Uri.parse("content://media/external/images/media/47")
// Target file inside the internal storage
val target = File(appContext.filesDir, "cool-image.jpg")

// Copying a file is now done in one line!
fileSystem.copy(imageUri.toOkioPath(), target.toOkioPath())