/// <summary> /// Zips all files in the path to the target. /// </summary> /// <param name="path">The files to compress.</param> /// <param name="target"> /// The path of the target zip file. /// If target has more than one file, only the first one is used.</param> /// <param name="fileSystemToZip"> /// A function that maps the paths of the files and directories to zip into relative paths inside the zip. /// </param> /// <returns>The zipped path.</returns> public static Path Zip(this Path path, Path target, Func <Path, Path> fileSystemToZip) { var files = path.AllFiles() .ToDictionary( fileSystemToZip, p => p); Zip(target, new Path(files.Keys), p => files[p].ReadBytes()); return(target); }
/// <summary> /// Zips all files in the path to the target. /// <remarks> /// When a directory is being pointed to as a source, all contents are recursively added. /// Individual files are added at the root, and directories are added at the root under their name. /// To have more control over the path of the files in the zip, use the overload. /// </remarks> /// </summary> /// <param name="path">The files to compress.</param> /// <param name="target"> /// The path of the target zip file. /// If target has more than one file, only the first one is used. /// </param> /// <returns>The zipped path.</returns> public static Path Zip(this Path path, Path target) { var files = path.AllFiles() .ToDictionary( p => p.MakeRelativeTo(path), p => p); Zip(target, new Path(files.Keys), p => files[p].ReadBytes()); return(target); }