Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public int Action(string typeJob,string fileInput, string fileOut)
- {
- if (FileExistCheck(fileInput, fileOut))
- {
- using (FileStream sourceStream = new FileStream(fileInput, FileMode.Open))
- {
- using (FileStream targetStream = File.Create(fileOut))
- {
- switch (typeJob)
- {
- case "compress":
- using (GZipStream compressionStream = new GZipStream(targetStream, CompressionMode.Compress))
- {
- sourceStream.CopyTo(compressionStream);
- return 0;
- }
- case "decompress":
- using (GZipStream decompressionStream = new GZipStream(sourceStream, CompressionMode.Decompress))
- {
- try
- {
- decompressionStream.CopyTo(targetStream);
- return 0;
- }
- catch (InvalidDataException)
- {
- Console.WriteLine("Возможно путь к архиву указывает на файл иного типа");
- File.Delete(fileOut);
- return 1;
- }
- }
- default:
- Console.WriteLine("Первый аргумент указан неверно");
- Console.WriteLine("Следует выбрать compress или decompress");
- File.Delete(fileOut);
- return 1;
- }
- }
- }
- }
- else return 1;
- }
- public async Task<int> ActionAsync(
- string typeJob,
- string fileInput,
- string fileOut,
- CancellationToken token)
- sourceStream.CopyTo(compressionStream);
- await sourceStream.CopyToAsync(compressionStream, token).ConfigureAwait(false);
- var cts = new CancellationTokenSource();
- ActionAsync(..., ..., ..., cts.Token);
- cts.Cancel();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement