protected BaseOperation(OperationParameters parameters, int threadsLimit) { this.threadsLimit = threadsLimit; br = new BinaryReader(new FileStream(parameters.SourceFile, FileMode.Open, FileAccess.Read, FileShare.None)); bw = new BinaryWriter(new FileStream(parameters.DestinationFile, FileMode.Create, FileAccess.Write, FileShare.None)); }
public Compression(OperationParameters parameters, int threadsLimit) : base(parameters, threadsLimit) { FileInformation = new FileInformation(parameters.SourceFile); bw.Write(BitConverter.GetBytes(FileInformation.InitialLength)); bw.Write(BitConverter.GetBytes(FileInformation.BlockCount)); }
public Decompression(OperationParameters parameters, int threadsLimit) : base(parameters, threadsLimit) { long initialLength = br.ReadInt64(); long blockCount = br.ReadInt64(); FileInformation = new FileInformation(initialLength, blockCount); CheckDiskSpace(parameters.DestinationFile); }
private static int Main(string[] args) { ShowInfo(); AddUnhandledExceptionHandler(); #if DEBUG args = new[] { "decompress", "D:/Downloads/TorrentDownloads/234.gz", "D:/Downloads/TorrentDownloads/234.zip" }; #endif IReadOnlyList <string> errors = ValidationInput.ValidateInput(args); if (errors.Any()) { string errorOutput = string.Join("\n", errors); Console.WriteLine(errorOutput); return(Constants.ErrorExitCode); } string stringOperationType = args[0]; string sourceFile = args[1]; string destinationFile = args[2]; var operationParameters = new OperationParameters(sourceFile, destinationFile, stringOperationType); try { OperationType operationType = new StringToOperationTypeConverter().GetOperationType(operationParameters.Type.ToLower()); int threadsLimit = Environment.ProcessorCount; BaseOperation operation; switch (operationType) { case OperationType.Compress: operation = new Compression(operationParameters, threadsLimit); break; case OperationType.Decompress: operation = new Decompression(operationParameters, threadsLimit); break; default: throw new ArgumentOutOfRangeException(nameof(operationType)); } return(operation.Start()); } catch (System.Exception ex) { Console.Error.WriteLine(ex.Message); return(Constants.ErrorExitCode); } }