Site icon Flutter Packages | Pub dev Packages – Flutter Mobile App World

Flutter plugin for creating and extracting ZIP files

flutter_archive

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

Features

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);
  }

Download flutter archive plugin source code on GitHub

Check out flutter archive plugin implementation guide on Pub.dev

https://pub.dev/packages/flutter_archive

Exit mobile version