zip function

Future<void> zip({
  1. required File outputFile,
  2. required Directory sourceDirectory,
  3. bool includeRoot = true,
})

Zips the folder into a non-.zip file

Implementation

Future<void> zip({
  required File outputFile,
  required Directory sourceDirectory,
  bool includeRoot = true,
})async{
  Map<String, dynamic> filesystem;
  try{
    filesystem = await _getFolderAsObject(
      folder: sourceDirectory,
    );
  }catch(error){
    throw ZipperError.outOfRAM;
  }
  try{
    //Include the root folder if stated on the parameters
    if(includeRoot){
      String rootName = sourceDirectory.path.substring(sourceDirectory.path.lastIndexOf("/") + 1);
      //print(rootName);
      filesystem = {
        rootName : filesystem,
      };
    }
  }catch(error){
    throw ZipperError.outOfRAM;
  }
  //Save the resulting object at the outputFile
  await outputFile.create(recursive: true);
  await outputFile.writeAsString(jsonEncode(filesystem));
}