@capgo/capacitor-zip
Zip and unzip files in your Capacitor app for free on iOS and Android, and unzip in the browser on the web.
Capgo: push fixes to your Capacitor users in minutes, build signed iOS and Android apps without a Mac, and roll back in one click.
➡️ Get started for free
14-day unlimited free trial. No credit card required
🤖 Building with an AI coding agent? Install Capgo skills so Claude Code, Codex, Cursor, Copilot, or Gemini CLI know how to install and use
@capgo/capacitor-zipin your Capacitor app:npx skills add Cap-go/capgo-skills. Then ask your agent: "Add @capgo/capacitor-zip to my Capacitor app and wire it up." Agent setup guides · Hosted MCP
Key features
- Zip:
zip()compresses a file or a folder into an archive. - Unzip:
unzip()extracts an archive to a destination folder. - Native libraries: ZIPFoundation on iOS and zip4j on Android.
- Passwords on Android: AES-256 encrypted archives when you pass a password.
- Web unzip:
unzip()works in the browser and downloads each file separately, without the folder structure. - Progress events:
addListener('progress', ...)reports byte and file progress duringzipandunzip(web: unzip only). - Platforms: iOS, Android and Web.
zip()is not available on web.
Why Capacitor Zip?
A free and open-source alternative for ZIP file operations in Capacitor apps:
- Native Performance - Uses platform-native ZIP libraries for fast compression
- Password Protection - AES encryption support on Android (iOS coming soon)
- Cross-platform - Works on iOS, Android, and Web
- TypeScript - Full TypeScript definitions included
- Modern APIs - Built with latest Capacitor 7 standards
Perfect for apps that need file compression, backup functionality, data export, or secure file transfers.
Documentation
The most complete doc is available here: https://capgo.app/docs/plugins/zip/
Compatibility
| Plugin version | Capacitor compatibility | Maintained |
|---|---|---|
| v8.*.* | v8.*.* | ✅ |
| v7.*.* | v7.*.* | On demand |
| v6.*.* | v6.*.* | ❌ |
| v5.*.* | v5.*.* | ❌ |
Note: The major version of this plugin follows the major version of Capacitor. Use the version that matches your Capacitor installation (e.g., plugin v8 for Capacitor 8). Only the latest major version is actively maintained.
Install
You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:
npx skills add https://github.com/cap-go/capacitor-skills --skill capacitor-plugins
Then use the following prompt:
Use the `capacitor-plugins` skill from `cap-go/capacitor-skills` to install the `@capgo/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 @capgo/capacitor-zip
npx cap sync
Progress listener
import { CapacitorZip } from '@capgo/capacitor-zip';
const listener = await CapacitorZip.addListener('progress', (event) => {
const percent = Math.round(event.progress * 100);
console.log(`${event.operation} ${percent}%`, event.currentFile ?? '');
});
try {
await CapacitorZip.zip({ source: '/path/to/folder', destination: '/path/to/archive.zip' });
} finally {
await listener.remove();
}
API
Capacitor Zip Plugin for compressing and extracting zip archives.
Provides native ZIP file operations with platform-specific implementations:
- iOS: Uses ZIPFoundation (password protection not supported)
- Android: Uses zip4j with AES encryption support
- Web: Uses zip.js (unzip only, triggers downloads)
addListener('progress', ...)
addListener(eventName: 'progress', listenerFunc: (event: ZipProgressEvent) => void) => Promise<PluginListenerHandle>
Listen for progress updates while zip or unzip is running.
Register before starting the operation. Events are best-effort on web (unzip only).
Each event includes operationId, source, and destination so you can filter when several operations run at once.
Pass a unique operationId per call if you supply your own.
| Param | Type | Description |
|---|---|---|
eventName | 'progress' | The event name (progress). |
listenerFunc | (event: ZipProgressEvent) => void | Called with ZipProgressEvent payloads (includes loaded, total, and lengthComputable like ProgressEvent). |
Returns: Promise<PluginListenerHandle>
Since: 8.2.0
zip(...)
zip(options: ZipOptions) => Promise<void>
Compress a file or directory to create a ZIP archive.
Creates a compressed archive from a source file or directory. The archive will include the entire directory structure if the source is a folder.
Platform-specific notes:
- iOS: Password protection is not supported. If a password is provided, it will be ignored and a warning will be logged.
- Android: Supports AES-256 encryption when a password is provided.
- Web: Not supported. Throws an error if called.
| Param | Type | Description |
|---|---|---|
options | ZipOptions | - Configuration for the zip operation |
Since: 7.0.0
unzip(...)
unzip(options: UnzipOptions) => Promise<void>
Extract a ZIP archive to a specified destination directory.
Extracts all files and folders from a ZIP archive while preserving the directory structure. Creates the destination directory if it doesn't exist.
Platform-specific notes:
- iOS: Supports standard ZIP archives. Password-protected archives are not supported; a provided password is ignored.
- Android: Supports AES-encrypted archives with password. Includes zip slip vulnerability protection.
- Web: Downloads each file individually to the browser's download folder. Cannot create a directory structure.
| Param | Type | Description |
|---|---|---|
options | UnzipOptions | - Configuration for the unzip operation |
Since: 7.0.0
getPluginVersion()
getPluginVersion() => Promise<{ version: string; }>
Get the native plugin version.
Returns the version of the native plugin code, which follows the Capacitor major version (e.g., 7.0.0 for Capacitor 7.x).
Returns: Promise<{ version: string; }>
Since: 7.0.0
Interfaces
PluginListenerHandle
| Prop | Type |
|---|---|
remove | () => Promise<void> |
ZipProgressEvent
Progress payload emitted on the progress listener during zip and unzip.
| Prop | Type | Description | Since |
|---|---|---|---|
operationId | string | Unique id for the zip or unzip call that produced this event. Use this to distinguish concurrent operations when using addListener. | 8.3.0 |
source | string | source path from the zip or unzip options for this operation. | 8.3.0 |
destination | string | destination path from the zip or unzip options for this operation. | 8.3.0 |
operation | 'zip' | 'unzip' | Whether bytes are being compressed or extracted. | |
loaded | number | Bytes processed so far (uncompressed size when known). Same meaning as ProgressEvent.loaded in the Web platform. | |
total | number | Total bytes for the operation when known, otherwise 0. Same meaning as ProgressEvent.total in the Web platform. | |
lengthComputable | boolean | Whether total (or file totals) represent a known length for this operation. Aligns with ProgressEvent.lengthComputable. | |
progress | number | Ratio from 0 to 1 based on bytes when total > 0, otherwise file counts when available. | |
currentFile | string | Path or name of the entry currently being processed. | |
filesCompleted | number | Number of archive entries completed so far. | |
filesTotal | number | Total entries in the archive when known. |
ZipOptions
Options for creating a ZIP archive.
| Prop | Type | Description | Default | Since |
|---|---|---|---|---|
source | string | Path to the file or directory to compress. This can be an absolute path or a path relative to the app's working directory. If the source is a directory, all its contents will be recursively compressed while preserving the directory structure. Platform-specific notes: - iOS: Use file:// URLs or absolute paths. Relative paths are resolved from the app's documents directory. - Android: Use absolute file paths or content:// URIs for files accessible via the Android Storage Access Framework. - Web: Not supported. On iOS and Android, file:// URLs (for example from Cordova FileEntry.nativeURL) and percent-encoded path segments are normalized to filesystem paths before zip/unzip runs. | 7.0.0 | |
destination | string | Path where the ZIP archive will be created. The destination path must include the .zip file extension. If the parent directory doesn't exist, it will be created automatically. Platform-specific notes: - iOS: Use file:// URLs or absolute paths. Relative paths are resolved from the app's documents directory. - Android: Use absolute file paths. The plugin will create any missing parent directories. - Web: Not supported. On iOS and Android, file:// URLs and percent-encoded path segments are normalized to filesystem paths before zip runs. | 7.0.0 | |
password | string | Optional password for encrypting the ZIP archive. When provided, the archive will be encrypted and require this password to extract. Uses AES-256 encryption on Android. Platform-specific notes: - iOS: Password protection is NOT supported. The password will be ignored and a warning will be logged. - Android: Supports AES-256 encryption via zip4j library. The password must be provided during extraction. - Web: Not supported. | 7.0.0 | |
includeParentFolder | boolean | Whether to include the parent folder in the ZIP archive. When true (default), the source folder itself becomes the root directory in the archive. When false, only the contents of the source folder are included at the root level. This option only applies when the source is a directory. For single files, this option is ignored. | true | 8.0.5 |
onProgress | ((event: ZipProgressEvent) => void) | Called with progress updates for this zip operation only. Prefer this over addListener('progress') when running multiple operations at once. The listener is registered and removed automatically. | 8.3.0 | |
operationId | string | Optional operation id. If supplied, it must be unique among concurrent zip and unzip calls. An id is generated automatically when omitted. | 8.3.0 |
UnzipOptions
Options for extracting a ZIP archive.
| Prop | Type | Description | Since |
|---|---|---|---|
source | string | Path to the ZIP archive to extract. The source must be a valid ZIP file. If the file doesn't exist or is corrupted, the operation will fail with an error. Platform-specific notes: - iOS: Use file:// URLs or absolute paths. Relative paths are resolved from the app's documents directory. - Android: Use absolute file paths or content:// URIs for files accessible via the Android Storage Access Framework. - Web: Use HTTP/HTTPS URLs. The file will be fetched and extracted in the browser. On iOS and Android, file:// URLs (for example from Cordova FileEntry.nativeURL) and percent-encoded path segments are normalized to filesystem paths before unzip runs. | 7.0.0 |
destination | string | Path to the directory where files will be extracted. The destination directory will be created if it doesn't exist. All files and folders from the archive will be extracted while preserving the directory structure. Platform-specific notes: - iOS: Use file:// URLs or absolute paths. Relative paths are resolved from the app's documents directory. - Android: Use absolute file paths. Includes protection against zip slip vulnerabilities. - Web: Not applicable. Files are downloaded individually to the browser's download folder. On iOS and Android, file:// URLs and percent-encoded path segments are normalized to filesystem paths before unzip runs. | 7.0.0 |
password | string | Optional password for decrypting password-protected archives. Required if the ZIP archive was encrypted with a password. If the password is incorrect, extraction will fail with an error. Platform-specific notes: - iOS: Password-protected ZIP archives are not supported. If a password is provided, it is ignored and a warning is logged. - Android: Supports AES-encrypted archives created with zip4j or standard password-protected ZIPs. - Web: Not supported. Password-protected archives cannot be extracted in the browser. | 7.0.0 |
onProgress | ((event: ZipProgressEvent) => void) | Called with progress updates for this unzip operation only. Events are best-effort on web (unzip only). Prefer this over addListener('progress') when running multiple operations at once. The listener is registered and removed automatically. | 8.3.0 |
operationId | string | Optional operation id. If supplied, it must be unique among concurrent zip and unzip calls. An id is generated automatically when omitted. | 8.3.0 |
Usage
Basic Zip
import { CapacitorZip } from '@capgo/capacitor-zip';
// Zip a directory
await CapacitorZip.zip({
source: '/path/to/directory',
destination: '/path/to/output.zip'
});
// Zip a single file
await CapacitorZip.zip({
source: '/path/to/file.txt',
destination: '/path/to/output.zip'
});
Zip with Password
import { CapacitorZip } from '@capgo/capacitor-zip';
await CapacitorZip.zip({
source: '/path/to/directory',
destination: '/path/to/output.zip',
password: 'mySecurePassword123'
});
Basic Unzip
import { CapacitorZip } from '@capgo/capacitor-zip';
await CapacitorZip.unzip({
source: '/path/to/archive.zip',
destination: '/path/to/extract'
});
Unzip with Password
import { CapacitorZip } from '@capgo/capacitor-zip';
await CapacitorZip.unzip({
source: '/path/to/encrypted.zip',
destination: '/path/to/extract',
password: 'mySecurePassword123'
});
Get Plugin Version
import { CapacitorZip } from '@capgo/capacitor-zip';
const { version } = await CapacitorZip.getPluginVersion();
console.log('Plugin version:', version);
Platform Support
| Platform | Supported | Password Protection | Notes |
|---|---|---|---|
| iOS | ✅ | ❌ | Uses ZIPFoundation library (password not supported) |
| Android | ✅ | ✅ | Uses zip4j library for password-protected archives, standard Java ZIP for non-encrypted |
| Web | ⚠️ | ❌ | Limited support - unzip only triggers file downloads |
Platform Limitations
iOS
- Password-protected archives are not supported with the current ZIPFoundation library
- If a password is provided, it will be ignored with a console warning
Android
- Full support for password-protected ZIP archives using AES encryption via zip4j
Web
The web implementation has the following limitations:
- Zip: Not supported (throws an error)
- Unzip: Triggers browser downloads for each file in the archive
- Password: Password-protected archives are not supported
For production web applications, consider using a server-side solution for zip operations.
File Paths
iOS
Use paths relative to the app's document directory or full paths:
import { Filesystem, Directory } from '@capacitor/filesystem';
const { uri } = await Filesystem.getUri({
directory: Directory.Documents,
path: 'myfile.zip'
});
await CapacitorZip.unzip({
source: uri,
destination: Directory.Documents + '/extracted'
});
Android
Use paths relative to the app's data directory or full paths:
import { Filesystem, Directory } from '@capacitor/filesystem';
const { uri } = await Filesystem.getUri({
directory: Directory.Data,
path: 'myfile.zip'
});
await CapacitorZip.unzip({
source: uri,
destination: Directory.Data + '/extracted'
});
Error Handling
import { CapacitorZip } from '@capgo/capacitor-zip';
try {
await CapacitorZip.zip({
source: '/path/to/directory',
destination: '/path/to/output.zip'
});
console.log('Zip created successfully!');
} catch (error) {
console.error('Failed to create zip:', error);
}
Dependencies
iOS
- ZIPFoundation - Provides ZIP compression with AES encryption
Android
- zip4j - Provides password-protected ZIP support
Web
- zip.js - JavaScript ZIP library (limited functionality)
License
MIT
Credits
Created by Martin Donadieu for Capgo