Capacitor plugin to zip and unzip files and directories with support for encryption.
The Capacitor Zip plugin is one of the most complete file archiving solutions for Capacitor apps. Here are some of the key features:
- 🖥️ Cross-platform: Supports Android and iOS.
- 📁 File Compression: Zip and unzip single or multiple files.
- 🔑 Encryption: Encrypt and decrypt files.
- 🤝 Compatibility: Compatible with the File Compressor plugin.
- 📦 CocoaPods & SPM: Supports CocoaPods and Swift Package Manager for iOS.
- 🔁 Up-to-date: Always supports the latest Capacitor version.
- ⭐️ Support: Priority support from the Capawesome Team.
- ✨ Handcrafted: Built from the ground up with care and expertise, not forked or AI-generated.
Missing a feature? Just open an issue and we'll add it for you!
The Zip plugin is typically used whenever an app needs to work with zip archives, for example:
- File uploads: Bundle multiple files or an entire directory into a single zip archive before uploading it to a server.
- Content downloads: Unzip archives downloaded from a server, for example to make content available offline.
- Data backups: Compress app data into an archive that can be exported and restored later.
- Sensitive data protection: Encrypt archives with a password when zipping and decrypt them when unzipping.
| Plugin Version | Capacitor Version | Status |
|---|---|---|
| 8.x.x | >=8.x.x | Active support |
| 7.x.x | 7.x.x | Deprecated |
| 6.x.x | 6.x.x | Deprecated |
A working example can be found here.
This plugin is only available to Capawesome Insiders. First, make sure you have the Capawesome npm registry set up. You can do this by running the following commands:
npm config set @capawesome-team:registry https://npm.registry.capawesome.io
npm config set //npm.registry.capawesome.io/:_authToken <YOUR_LICENSE_KEY>
Attention: Replace <YOUR_LICENSE_KEY> with the license key you received from Polar. If you don't have a license key yet, you can get one by becoming a Capawesome Insider.
Next, you can use our AI-Assisted Setup to install the plugin. Add the Capawesome Skills to your AI tool using the following command:
npx skills add capawesome-team/skills --skill capacitor-pluginsThen use the following prompt:
Use the `capacitor-plugins` skill from `capawesome-team/skills` to install the `@capawesome-team/capacitor-zip` plugin in my project.
If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:
npm install @capawesome-team/capacitor-zip
npx cap syncIf you are using Proguard, you need to add the following rules to your proguard-rules.pro file:
-keep class io.capawesome.capacitorjs.plugins.** { *; }
If needed, you can define the following project variable in your app’s variables.gradle file to change the default version of the dependency:
$zip4jVersionversion ofnet.lingala.zip4j:zip4j(default:2.11.5)
This can be useful if you encounter dependency conflicts with other plugins in your project.
If you are using Swift Package Manager, make sure that your iOS deployment target is set to at least 16.0 in your Xcode project settings (usually in ios/App/App.xcodeproj):
-IPHONEOS_DEPLOYMENT_TARGET = 15.0
+IPHONEOS_DEPLOYMENT_TARGET = 16.0If you are using CocoaPods, make sure that your iOS deployment target is set to at least 16.0 in your Podfile:
platform :ios, '16.0'No configuration required for this plugin.
The following examples show how to create a zip archive and extract an existing one.
Create a zip archive from a source file or directory. You can optionally provide a password to encrypt the archive. Only available on Android and iOS:
import { Zip } from '@capawesome-team/capacitor-zip';
const zip = async () => {
await Zip.zip({
source: 'file:///data/user/0/dev.robingenz.capacitor.plugindemo/cache/1714900095398',
destination: 'file:///data/user/0/dev.robingenz.capacitor.plugindemo/cache/1714900095398.zip',
password: 'secret',
});
};Extract a zip archive into a destination directory. If the archive is encrypted, provide the password to decrypt it. Only available on Android and iOS:
import { Zip } from '@capawesome-team/capacitor-zip';
const unzip = async () => {
await Zip.unzip({
source: 'file:///data/user/0/dev.robingenz.capacitor.plugindemo/cache/1714900095398.zip',
destination: 'file:///data/user/0/dev.robingenz.capacitor.plugindemo/cache/1714900095398',
password: 'secret',
});
};unzip(options: UnzipOptions) => Promise<void>Unzip a file.
Only available on Android and iOS.
| Param | Type |
|---|---|
options |
UnzipOptions |
Since: 6.0.0
zip(options: ZipOptions) => Promise<void>Zip a file or directory.
Only available on Android and iOS.
| Param | Type |
|---|---|
options |
ZipOptions |
Since: 6.0.0
| Prop | Type | Description | Since |
|---|---|---|---|
destination |
string |
The destination directory. | 6.0.0 |
password |
string |
The password to decrypt the zip file. | 6.1.0 |
source |
string |
The source file to unzip. | 6.0.0 |
| Prop | Type | Description | Since |
|---|---|---|---|
destination |
string |
The destination file. | 6.0.0 |
password |
string |
The password to encrypt the zip file. | 6.1.0 |
source |
string |
The source file or directory to zip. | 6.0.0 |
Yes. Pass the password option to the zip(...) method to encrypt the archive and pass the same option to the unzip(...) method to decrypt it. See the usage examples above.
Yes. The source option of the zip(...) method accepts either a single file or a directory. When unzipping, the archive is extracted into the directory specified by the destination option.
No, the zip(...) and unzip(...) methods are only available on Android and iOS, as documented in the API section.
The File Compressor plugin reduces the file size of individual image files such as PNG, JPEG, and WebP. The Zip plugin, on the other hand, bundles one or more files or directories into a zip archive and extracts them again. Both plugins are compatible and can be used together, for example to compress images before zipping them.
Yes, the plugin is framework-agnostic. It works in any Capacitor app regardless of the web framework, including Ionic with Angular, React, or Vue, as well as plain JavaScript projects.
- File Compressor: Compress image files such as PNG, JPEG, and WebP.
- File Opener: Open a file with the default application.
- File Picker: Let the user select a file, directory, image, or video from the device.
- Share Target: Receive files shared from other apps.
Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our Capawesome Newsletter.
See CHANGELOG.md.
See BREAKING.md.
See LICENSE.