PlatformFile, including files and folders returned by FileKit dialogs, such as Android content:// documents.
Dependencies
Add kmp-zip and its kotlinx-io adapters alongside FileKit Core:Creating an archive
Supported on Android, iOS, macOS, JVM and Kotlin/Native Linux targets
zip function below writes files and folders into an archive. Each folder keeps its name as the top-level entry, so extracting the archive recreates the folder:
A few things to keep in mind:
- Save the archive outside the files and folders you are zipping. Otherwise,
zipcan read the archive while writing it, or overwrite a source file before reading it. - Symbolic links are followed. A link to a parent folder makes
ziploop through the same folders until it fails. - kmp-zip doesn’t support ZIP64. Each file and the archive must stay under 4 GB, with at most 65,535 entries.
Extracting an archive
Supported on Android, iOS, macOS, JVM and Kotlin/Native Linux targets
unzip function extracts every entry into a destination folder:
Example: Zipping files picked by the user
Combined with FileKit Dialogs, you can let the user pick files and choose where to save the archive:FileKit.openDirectoryPicker() and pass the folder to zip.
Web
Supported on JS and WASM targets
source() and sink() are not available on web. You can still build the archive in memory and download it with FileKit.download: