Skip to content

Conversation

@nathenxbrewer
Copy link

Add Password Protection Support for ZIP File Creation

Summary

This PR adds support for creating password-protected ZIP files across Android, iOS, and macOS platforms. The feature is implemented as an optional password parameter to maintain full backward compatibility with existing code.

Changes

API Changes

Added optional password parameter to:

  • ZipFile.createFromDirectory()
  • ZipFile.createFromFiles()

Both methods now accept an optional String? password parameter. When provided, the created ZIP file will be password-protected. When null (default), ZIP files are created without password protection, maintaining existing behavior.

Platform-Specific Implementation

Android

  • Library: Added Zip4j (v2.11.5) dependency
  • Encryption: Uses ZIP_STANDARD encryption method
  • Implementation: Conditionally uses Zip4j for password-protected zips, falls back to existing ZipOutputStream for unprotected zips

iOS/macOS

  • Library: Added SSZipArchive (v2.4+) dependency
  • Encryption: Supports AES encryption for password-protected zips
  • Implementation: Conditionally uses SSZipArchive for password-protected zips, falls back to existing ZIPFoundation for unprotected zips

Dependencies Added

  • Android: net.lingala.zip4j:zip4j:2.11.5
  • iOS/macOS: SSZipArchive ~> 2.4 (via CocoaPods)

Usage

Creating a Password-Protected ZIP from Directory

import 'package:flutter_archive/flutter_archive.dart';

Example

await ZipFile.createFromDirectory(
  sourceDir: Directory('/path/to/source'),
  zipFile: File('/path/to/archive.zip'),
  password: 'mySecurePassword123',
);

@nathenxbrewer
Copy link
Author

#61

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant