본문 바로가기

시작하기

GitHub

AI 지원 설정으로 플러그인을 설치할 수 있습니다. 다음 명령어로 AI 도구에 Capgo 스킬을 추가하세요:

터미널 창
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

그다음 아래 prompt를 사용하세요:

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';
import { CapacitorZip } from '@capgo/capacitor-zip';
const listener = await CapacitorZip.addListener('progress', (event) => {
updateBar(event.loaded, event.total);
});
await CapacitorZip.zip({
source: 'file:///data/user/0/.../export/',
destination: 'file:///data/user/0/.../export.zip',
});
await listener.remove();

예시: 업데이트 번들 압축 해제

“예제: 업데이트 번들 압축 해제” 섹션
await CapacitorZip.unzip({
source: downloadedZipUri,
destination: unpackDirUri,
});
  • Web zip: zip() 웹에서는 오류가 발생하므로, 압축 해제 작업을 native 또는 서버로 위임하세요.
  • Android 비밀번호: AES 비밀번호는 현재 Android에서만 지원됩니다. 기기에서 아카이브를 테스트하세요.
  • URI 스킴: 절대 경로를 사용하세요. file:// native code가 읽을 수 있는 경로여야 합니다.

파일이나 디렉토리를 압축하여 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에서 생성되었습니다. public API가 업스트림에서 변경되면 동기화를 다시 실행하세요.

사용 중인 경우 시작하기 대시보드와 API 운영을 계획하려면, 이를 다음 항목과 연결하세요: @capgo/capacitor-zip 사용하기 @capgo/capacitor-zip를 사용하여 네이티브 기능을 구현할 때, API 개요 API Overview의 구현 상세 내용은 소개 Introduction의 구현 상세 내용은 API 키 API Keys의 구현 세부 사항은, 디바이스 Devices의 구현 세부 사항은.