Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

Capacitor Zip Plugin

Capacitor plugin to zip and unzip files and directories with support for encryption.

Features

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!

Use Cases

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.

Compatibility

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

Demo

A working example can be found here.

Installation

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-plugins

Then 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 sync

Android

Proguard

If you are using Proguard, you need to add the following rules to your proguard-rules.pro file:

-keep class io.capawesome.capacitorjs.plugins.** { *; }

Variables

If needed, you can define the following project variable in your app’s variables.gradle file to change the default version of the dependency:

  • $zip4jVersion version of net.lingala.zip4j:zip4j (default: 2.11.5)

This can be useful if you encounter dependency conflicts with other plugins in your project.

iOS

Minimum Deployment Target

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.0

If 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'

Configuration

No configuration required for this plugin.

Usage

The following examples show how to create a zip archive and extract an existing one.

Zip a file or directory

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',
  });
};

Unzip an archive

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',
  });
};

API

unzip(...)

unzip(options: UnzipOptions) => Promise<void>

Unzip a file.

Only available on Android and iOS.

Param Type
options UnzipOptions

Since: 6.0.0


zip(...)

zip(options: ZipOptions) => Promise<void>

Zip a file or directory.

Only available on Android and iOS.

Param Type
options ZipOptions

Since: 6.0.0


Interfaces

UnzipOptions

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

ZipOptions

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

FAQ

Can I create password-protected zip archives?

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.

Can I zip an entire directory?

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.

Does this plugin work on the Web?

No, the zip(...) and unzip(...) methods are only available on Android and iOS, as documented in the API section.

How is this plugin different from the File Compressor plugin?

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.

Can I use this plugin with Ionic, React, Vue or Angular?

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.

Related Plugins

  • 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.

Newsletter

Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our Capawesome Newsletter.

Changelog

See CHANGELOG.md.

Breaking Changes

See BREAKING.md.

License

See LICENSE.