-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
69ea560
commit c9e1171
Showing
2 changed files
with
21 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
calf-file-picker/src/iosMain/kotlin/com.mohamedrejeb.calf.picker/TempFile.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.mohamedrejeb.calf.picker | ||
|
||
import platform.Foundation.NSData | ||
import platform.Foundation.NSTemporaryDirectory | ||
import platform.Foundation.NSURL | ||
import platform.Foundation.NSUUID | ||
import platform.Foundation.dataWithContentsOfURL | ||
import platform.Foundation.writeToURL | ||
|
||
internal fun NSURL.createTempFile(): NSURL? { | ||
val extension = absoluteString?.substringAfterLast('.', "") ?: return null | ||
val data = NSData.dataWithContentsOfURL(this) ?: return null | ||
return NSURL.fileURLWithPath("${NSTemporaryDirectory()}/${NSUUID().UUIDString}.$extension").apply { | ||
data.writeToURL(this, true) | ||
} | ||
} |