メインコンテンツにジャンプ

Getting Started

GitHub

Capgo の AI アシスト セットアップを使用してプラグインをインストールできます。AI ツールに Capgo スキルを追加するには、以下のコマンドを実行してください。

ターミナル画面
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

次に、以下のコマンドを使用してください:

Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-zip` plugin in my project.

Manual Setupを使用する場合は、以下のコマンドを実行してください。プラットフォーム固有の指示に従ってください。

ターミナル画面
bun add @capgo/capacitor-zip
bunx cap sync
import { CapacitorZip } from '@capgo/capacitor-zip';

ファイルまたはディレクトリをZIPアーカイブに圧縮します。

指定されたソースファイルまたはディレクトリから圧縮アーカイブを作成します。ソースがフォルダの場合、すべてのディレクトリ構造が含まれます。

プラットフォーム固有の注意

  • iOS: パスワード保護はサポートされていません。パスワードが指定された場合、警告がログに記録され、パスワードは無視されます。
  • Android: パスワードが指定された場合、AES-256暗号化をサポートします。
  • Web: サポートされていません。呼び出された場合にエラーが発生します。
import { CapacitorZip } from '@capgo/capacitor-zip';
// Compress a directory without password
await CapacitorZip.zip({
source: '/path/to/my-folder',
destination: '/path/to/output.zip'
});

ZIPアーカイブから指定された目的地ディレクトリに展開します。

ZIPアーカイブからすべてのファイルとフォルダを抽出します。ディレクトリ構造を維持し、目的地ディレクトリが存在しない場合は作成します。

プラットフォーム固有の注意

  • iOS: ZIPアーカイブを標準サポートしています。パスワード保護されたアーカイブは、提供されたパスワードで展開されます。
  • Android: パスワード付きのAES暗号化されたアーカイブをサポートしています。zip slip脆弱性保護も含まれます。
  • Web: ブラウザのダウンロードフォルダに各ファイルを個別にダウンロードします。ディレクトリ構造を作成することはできません。
import { CapacitorZip } from '@capgo/capacitor-zip';
// Extract a standard ZIP archive
await CapacitorZip.unzip({
source: '/path/to/archive.zip',
destination: '/path/to/extract-folder'
});

ZIPアーカイブを作成するためのオプション

export interface ZipOptions {
/**
* 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.
*
* @since 7.0.0
* @example '/Users/app/Documents/my-folder'
* @example '/var/mobile/Containers/Data/Application/.../Documents/file.pdf'
* @example 'file:///storage/emulated/0/Download/document.pdf'
*/
source: 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.
*
* @since 7.0.0
* @example '/Users/app/Documents/archive.zip'
* @example '/var/mobile/Containers/Data/Application/.../Documents/backup.zip'
* @example 'file:///storage/emulated/0/Download/compressed.zip'
*/
destination: 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.
*
* @since 7.0.0
* @example 'mySecurePassword123'
*/
password?: string;
/**
* 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.
*
* @default true
* @since 8.0.5
* @example
* ```typescript
* // With includeParentFolder: true (default)
* // Source: /cache/temp/ containing [database.backup, media/]
* // ZIP contains: temp/database.backup, temp/media/
* await CapacitorZip.zip({
* source: '/cache/temp',
* destination: '/cache/backup.zip',
* includeParentFolder: true
* });
* ```
* @example
* ```typescript
* // With includeParentFolder: false
* // Source: /cache/temp/ containing [database.backup, media/]
* // ZIP contains: database.backup, media/
* await CapacitorZip.zip({
* source: '/cache/temp',
* destination: '/cache/backup.zip',
* includeParentFolder: false
* });
* ```
*/
includeParentFolder?: boolean;
}

ZIPアーカイブを展開するためのオプション

export interface UnzipOptions {
/**
* 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.
*
* @since 7.0.0
* @example '/Users/app/Documents/archive.zip'
* @example '/var/mobile/Containers/Data/Application/.../Documents/backup.zip'
* @example 'file:///storage/emulated/0/Download/compressed.zip'
* @example 'https://example.com/files/archive.zip' (Web only)
*/
source: 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.
*
* @since 7.0.0
* @example '/Users/app/Documents/extracted'
* @example '/var/mobile/Containers/Data/Application/.../Documents/files'
* @example 'file:///storage/emulated/0/Download/extracted-files'
*/
destination: 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: Supports password-protected ZIP archives.
* - 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.
*
* @since 7.0.0
* @example 'mySecurePassword123'
*/
password?: string;
}

真実の源

「真実の源」

このページはプラグインの src/definitions.ts上流で公開されたAPIが変更された場合に再度同期を実行してください。

Getting Startedから続けてください

「Getting Startedから続けてください」

あなたが Getting Started ダッシュボードとAPIの作業を計画する場合、 Using @capgo/capacitor-zip Using @capgo/capacitor-zip のネイティブ機能のAPIの概要 APIの実装詳細についての概要 概要 __CAPGO_KEEP_0__のキー APIのキーとデバイスの実装詳細について for the implementation detail in API Keys, and 実装詳細についてのデバイスの編集