zip static method

Future<void> zip(
  1. String srcPath,
  2. String dstPath, {
  3. int compressionLevel = 5,
})

Создание ZIP архива

Implementation

static Future<void> zip(
  String srcPath,
  String dstPath, {
  int compressionLevel = 5,
}) async {
  final archive = Archive();
  // `<dir>/*` (as ComicsViewModel.save passes it) means the contents of <dir>.
  final srcDir = Directory(
    srcPath.endsWith('/*')
        ? srcPath.substring(0, srcPath.length - 2)
        : srcPath,
  );

  if (!await srcDir.exists()) {
    throw Exception('Source directory does not exist: $srcPath');
  }

  await _addDirectoryToArchive(archive, srcDir, '');

  // archive 4.x: encode() returns a non-null List<int> (throws on failure).
  final zipData = ZipEncoder().encode(archive);

  final dstFile = File(dstPath);
  await dstFile.writeAsBytes(zipData);
}