@capgo/capacitor-zip

中文文档
8.2.2发布于 2026/10/21MPL-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 4.4万

A free Capacitor plugin for zipping and unzipping files on iOS, Android, and Web.

原始使用文档
文档目录31 节
  1. ➡️ Get started for free
  2. Key features
  3. Why Capacitor Zip?
  4. Documentation
  5. Compatibility
  6. Install
  7. Progress listener
  8. API
  9. addListener('progress', ...)
  10. zip(...)
  11. unzip(...)
  12. getPluginVersion()
  13. Interfaces
  14. Usage
  15. Basic Zip
  16. Zip with Password
  17. Basic Unzip
  18. Unzip with Password
  19. Get Plugin Version
  20. Platform Support
  21. Platform Limitations
  22. File Paths
  23. iOS
  24. Android
  25. Error Handling
  26. Dependencies
  27. iOS
  28. Android
  29. Web
  30. License
  31. Credits

@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 - Build Capacitor apps with AI, ship updates instantly

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-zip in 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

@capgo/capacitor-zip for Capacitor apps

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 during zip and unzip (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 versionCapacitor compatibilityMaintained
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.

ParamTypeDescription
eventName'progress'The event name (progress).
listenerFunc(event: ZipProgressEvent) => voidCalled 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.
ParamTypeDescription
optionsZipOptions- 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.
ParamTypeDescription
optionsUnzipOptions- 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

PropType
remove() => Promise<void>

ZipProgressEvent

Progress payload emitted on the progress listener during zip and unzip.

PropTypeDescriptionSince
operationIdstringUnique id for the zip or unzip call that produced this event. Use this to distinguish concurrent operations when using addListener.8.3.0
sourcestringsource path from the zip or unzip options for this operation.8.3.0
destinationstringdestination path from the zip or unzip options for this operation.8.3.0
operation'zip' | 'unzip'Whether bytes are being compressed or extracted.
loadednumberBytes processed so far (uncompressed size when known). Same meaning as ProgressEvent.loaded in the Web platform.
totalnumberTotal bytes for the operation when known, otherwise 0. Same meaning as ProgressEvent.total in the Web platform.
lengthComputablebooleanWhether total (or file totals) represent a known length for this operation. Aligns with ProgressEvent.lengthComputable.
progressnumberRatio from 0 to 1 based on bytes when total &gt; 0, otherwise file counts when available.
currentFilestringPath or name of the entry currently being processed.
filesCompletednumberNumber of archive entries completed so far.
filesTotalnumberTotal entries in the archive when known.

ZipOptions

Options for creating a ZIP archive.

PropTypeDescriptionDefaultSince
sourcestringPath 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
destinationstringPath 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
passwordstringOptional 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
includeParentFolderbooleanWhether 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.true8.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
operationIdstringOptional 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.

PropTypeDescriptionSince
sourcestringPath 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
destinationstringPath 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
passwordstringOptional 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
operationIdstringOptional 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

PlatformSupportedPassword ProtectionNotes
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

Android

  • zip4j - Provides password-protected ZIP support

Web

  • zip.js - JavaScript ZIP library (limited functionality)

License

MIT

Credits

Created by Martin Donadieu for Capgo

版本与发布记录

@capgo/capacitor-zip 共发布 36 个版本,首次发布于 2025/11/19;过去 12 个月发布了 36 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
8.2.2latest2026/10/2118 天前
8.2.12026/10/1623 天前
8.2.02026/10/1524 天前
8.1.252026/10/1525 天前
8.1.242026/10/1327 天前
8.1.232026/10/091 个月前

关于 @capgo/capacitor-zip 的常见问题

@capgo/capacitor-zip 是什么?

A free Capacitor plugin for zipping and unzipping files on iOS, Android, and Web.

如何安装 @capgo/capacitor-zip?

在项目目录运行 npm install @capgo/capacitor-zip,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@capacitor/core(>=8.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@capgo/capacitor-zip 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@capgo/capacitor-zip 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@capgo/capacitor-zip 可以商用吗?

@capgo/capacitor-zip 使用 MPL-2.0 许可。弱 Copyleft:可以商用,也可以和闭源代码一起使用;但如果分发时修改了 MPL 授权的文件,这些文件的修改需以 MPL 开源。以上为概括,不构成法律意见,请以许可原文为准。

@capgo/capacitor-zip 的下载量有多少?

根据 npm 官方下载统计,@capgo/capacitor-zip 在 2026/10/09 – 2026/11/07 这 30 天内被下载 43,852 次,日均约 1,462 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@capgo/capacitor-zip 还在维护吗?

最新版本 8.2.2 发布于 2026/10/21(18 天前);至今共发布 36 个版本,其中过去 12 个月发布了 36 个;首次发布于 2025/11/19。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。