public virtual string Gzip(IAbsoluteFilePath file, IAbsoluteFilePath dest = null, bool preserveFileNameAndModificationTime = true, ITProgress status = null) { if (file == null) { throw new ArgumentNullException(nameof(file)); } if (!(file.Exists)) { throw new ArgumentException("file.Exists"); } var defDest = (file + ".gz").ToAbsoluteFilePath(); if (dest == null) { dest = defDest; } var cmd = $"-f --best --rsyncable --keep \"{file}\""; if (!preserveFileNameAndModificationTime) { cmd = "-n " + cmd; } dest.RemoveReadonlyWhenExists(); var startInfo = new ProcessStartInfoBuilder(Common.Paths.ToolPath.GetChildFileWithName("gzip.exe"), cmd) { WorkingDirectory = file.ParentDirectoryPath }.Build(); var srcSize = file.FileInfo.Length; ProcessExitResultWithOutput ret; var predictedSize = srcSize * DefaultPredictedCompressionRatio; using (StatusProcessor.Conditional(defDest, status, (long)predictedSize)) ret = ProcessManager.LaunchAndGrabTool(startInfo, "Gzip pack"); if (Path.GetFullPath(dest.ToString()) != Path.GetFullPath(defDest.ToString())) { FileUtil.Ops.MoveWithRetry(defDest, dest); } return(ret.StandardOutput + ret.StandardError); }
public virtual string GzipStdOut(IAbsoluteFilePath inputFile, IAbsoluteFilePath outputFile = null, bool preserveFileNameAndModificationTime = true, ITProgress status = null) { if (!(inputFile != null)) { throw new ArgumentException("inputFile != null"); } if (!(inputFile.Exists)) { throw new ArgumentException("inputFile.Exists"); } if (outputFile == null) { outputFile = (inputFile + ".gz").ToAbsoluteFilePath(); } var cmd = $"-f --best --rsyncable --keep --stdout \"{inputFile}\" > \"{outputFile}\""; if (!preserveFileNameAndModificationTime) { cmd = "-n " + cmd; } outputFile.RemoveReadonlyWhenExists(); var startInfo = new ProcessStartInfoBuilder(Common.Paths.ToolPath.GetChildFileWithName("gzip.exe"), cmd) { WorkingDirectory = Common.Paths.LocalDataPath }.Build(); var srcSize = inputFile.FileInfo.Length; ProcessExitResultWithOutput ret; var predictedSize = srcSize * DefaultPredictedCompressionRatio; using (StatusProcessor.Conditional(outputFile, status, (long)predictedSize)) ret = ProcessManager.LaunchAndGrabToolCmd(startInfo, "Gzip pack"); return(ret.StandardOutput + ret.StandardError); }