zipDirectory method

  1. @override
void zipDirectory(
  1. Directory dir, {
  2. String? filename,
  3. int? level,
  4. bool followLinks = true,
  5. DateTime? modified,
  6. void onProgress(
    1. double
    )?,
})

Zips a dir to a Zip file synchronously.

filename determines where the Zip file will be created. If filename is not specified, the name of the directory will be used with a '.zip' extension. If filename is within dir, it will throw a FormatException.

See also:

  • zipDirectoryAsync for the asynchronous version of this method.
  • _composeZipDirectoryPath for the logic of composing the Zip file path.

Implementation

@override
void zipDirectory(
  Directory dir, {
  String? filename,
  int? level,
  bool followLinks = true,
  DateTime? modified,
  void Function(double)? onProgress,
}) {
  final dirPath = dir.path;
  final zipPath = filename ?? '$dirPath.zip';
  level ??= gzip;
  create(zipPath, level: level);
  addDirectory(
    dir,
    includeDirName: false,
    level: level,
    followLinks: followLinks,
  );
  close();
}