Flutter plugin for creating and extracting ZIP files.
Create and extract ZIP archive files. Uses Android/iOS/macOS platform APIs for high performance and optimal memory usage.
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);
}
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);
}
final zipFile = File("zip_file_path");
final destinationDir = Directory("destination_dir_path");
try {
ZipFile.extractToDirectory(zipFile: zipFile, destinationDir: destinationDir);
} catch (e) {
print(e);
}
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);
}