A simple Zip/Unzip plugin for Capacitor, supporting iOS and Android platforms.
This plugin provides zip and unzip functionality for Capacitor applications:
- iOS Implementation: Uses SSZipArchive library for efficient compression/decompression
- Android Implementation: Leverages Java's built-in ZipInputStream/ZipOutputStream
- Platform Support: iOS and Android (Web platform not supported)
npm install capa-zip
npx cap syncZip file manipulation plugin for Capacitor
The plugin emits progress events during zip/unzip operations:
Zip.addListener('zipProgress', (progress: ZipPluginProgress) => {
const percentage = (progress.loaded / progress.total) * 100;
console.log(`Progress: ${percentage.toFixed(2)}%`);
});// Add progress listener
Zip.addListener('zipProgress', (progress: ZipPluginProgress) => {
const percentage = (progress.loaded / progress.total) * 100;
updateProgressUI(percentage);
});
// Perform unzip
try {
await Zip.unzip({
sourceFile: 'path/to/archive.zip',
destinationPath: 'path/to/destination'
});
console.log('Unzip completed successfully');
} catch (error) {
console.error('Unzip failed:', error);
}try {
await Zip.zip({
sourcePath: 'path/to/directory',
destinationPath: 'path/to/archive.zip'
});
console.log('Zip completed successfully');
} catch (error) {
console.error('Zip failed:', error);
}try {
await Zip.zip({
sourcePath: 'path/to/directory',
destinationPath: 'path/to/archive.zip',
files: ['file1.txt', 'subdirectory/file2.jpg']
});
console.log('Zip completed successfully');
} catch (error) {
console.error('Zip failed:', error);
}addListener(eventName: 'zipProgress', listenerFunc: (progress: ZipPluginProgress) => void) => Promise<PluginListenerHandle>Adds a listener for zip progress events.
| Param | Type | Description |
|---|---|---|
eventName |
'zipProgress' |
The name of the event to listen for |
listenerFunc |
(progress: ZipPluginProgress) => void |
The callback function to be called when the event occurs |
Returns: Promise<PluginListenerHandle>
unzip(options: { sourceFile: string; destinationPath: string; }) => Promise<void>Unzips a file to a specified destination directory.
| Param | Type | Description |
|---|---|---|
options |
{ sourceFile: string; destinationPath: string; } |
Options for the unzip operation |
Since: 1.0.0
zip(options: { sourcePath: string; destinationPath: string; files?: string[]; }) => Promise<void>Creates a zip file from a directory or list of files.
| Param | Type | Description |
|---|---|---|
options |
{ sourcePath: string; destinationPath: string; files?: string[]; } |
Options for the zip operation |
Since: 1.1.0
removeAllListeners() => Promise<void>Removes all registered event listeners.
Since: 7.0.0
| Prop | Type |
|---|---|
remove |
() => Promise<void> |
Progress event data for zip operations
| Prop | Type | Description |
|---|---|---|
loaded |
number |
Number of bytes processed |
total |
number |
Total number of bytes to process |