Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. public int Action(string typeJob,string fileInput, string fileOut)
  2. {
  3. if (FileExistCheck(fileInput, fileOut))
  4. {
  5. using (FileStream sourceStream = new FileStream(fileInput, FileMode.Open))
  6. {
  7. using (FileStream targetStream = File.Create(fileOut))
  8. {
  9. switch (typeJob)
  10. {
  11. case "compress":
  12. using (GZipStream compressionStream = new GZipStream(targetStream, CompressionMode.Compress))
  13. {
  14. sourceStream.CopyTo(compressionStream);
  15. return 0;
  16. }
  17. case "decompress":
  18. using (GZipStream decompressionStream = new GZipStream(sourceStream, CompressionMode.Decompress))
  19. {
  20. try
  21. {
  22. decompressionStream.CopyTo(targetStream);
  23. return 0;
  24. }
  25. catch (InvalidDataException)
  26. {
  27. Console.WriteLine("Возможно путь к архиву указывает на файл иного типа");
  28. File.Delete(fileOut);
  29. return 1;
  30. }
  31. }
  32. default:
  33. Console.WriteLine("Первый аргумент указан неверно");
  34. Console.WriteLine("Следует выбрать compress или decompress");
  35. File.Delete(fileOut);
  36. return 1;
  37. }
  38. }
  39. }
  40. }
  41. else return 1;
  42. }
  43.  
  44. public async Task<int> ActionAsync(
  45. string typeJob,
  46. string fileInput,
  47. string fileOut,
  48. CancellationToken token)
  49.  
  50. sourceStream.CopyTo(compressionStream);
  51.  
  52. await sourceStream.CopyToAsync(compressionStream, token).ConfigureAwait(false);
  53.  
  54. var cts = new CancellationTokenSource();
  55. ActionAsync(..., ..., ..., cts.Token);
  56.  
  57. cts.Cancel();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement