/flutter_archive

Flutter plugin for creating and extracting ZIP files.

Primary LanguageSwiftBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

flutter_archive

Create and extract ZIP archive files. Uses Android/iOS/macOS platform APIs for high performance and optimal memory usage.

Features

  • Supports Android (API level 16+), iOS 12+ and macOS 10.11+.
  • Modern plugin implementation based on Kotlin (Android) and Swift (iOS/macOS).
  • Uses background processing to keep UI responsive.
  • Zip all files in a directory (optionally recursively).
  • Zip a given list of files.
  • Unzip an archive file to a given directory.
  • Progress reporting.
  • Extract and zip files selectively (allows excluding files).

Examples

Create a zip file from a directory

  final dataDir = Directory("data_dir_path");
  try {
    final zipFile = File("zip_file_path");
    ZipFile.createFromDirectory(
        sourceDir: dataDir, zipFile: zipFile, recurseSubDirs: true);
  } catch (e) {
    print(e);
  }

Create a zip file from a given list of files.

  final sourceDir = Directory("source_dir");
  final files = [
    File(sourceDir.path + "file1"),
    File(sourceDir.path + "file2")
  ];
  final zipFile = File("zip_file_path");
  try {
    ZipFile.createFromFiles(
        sourceDir: sourceDir, files: files, zipFile: zipFile);
  } catch (e) {
    print(e);
  }

Extract a ZIP archive

  final zipFile = File("zip_file_path");
  final destinationDir = Directory("destination_dir_path");
  try {
    ZipFile.extractToDirectory(zipFile: zipFile, destinationDir: destinationDir);
  } catch (e) {
    print(e);
  }

Get progress info while extracting a zip archive.

  final zipFile = File("zip_file_path");
  final destinationDir = Directory("destination_dir_path");
  try {
    await ZipFile.extractToDirectory(
        zipFile: zipFile,
        destinationDir: destinationDir,
        onExtracting: (zipEntry, progress) {
          print('progress: ${progress.toStringAsFixed(1)}%');
          print('name: ${zipEntry.name}');
          print('isDirectory: ${zipEntry.isDirectory}');
          print(
              'modificationDate: ${zipEntry.modificationDate.toLocal().toIso8601String()}');
          print('uncompressedSize: ${zipEntry.uncompressedSize}');
          print('compressedSize: ${zipEntry.compressedSize}');
          print('compressionMethod: ${zipEntry.compressionMethod}');
          print('crc: ${zipEntry.crc}');
          return ZipFileOperation.includeItem;
        });
  } catch (e) {
    print(e);
  }