Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2015
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Text;
  5.  
  6. class Program
  7. {
  8. static void Main()
  9. {
  10. string source = "../../SOLID - Logger.avi";
  11. string destination;
  12. int n = int.Parse(Console.ReadLine());
  13.  
  14. List<string> collectedDestinations = new List<string>(n);
  15.  
  16. for (int i = 0; i < n; i++)
  17. {
  18. destination = "Part-" + i + ".avi";
  19. collectedDestinations.Add(destination);
  20. Slice(source, destination, n);
  21. }
  22.  
  23.  
  24. string newSource = "../../assembled.avi";
  25. Assemble(collectedDestinations, newSource);
  26. }
  27.  
  28. static void Slice(string sourceFile, string destinationDirectory, int parts)
  29. {
  30. using (var source = new FileStream(sourceFile, FileMode.Open))
  31. {
  32. for (int i = 0; i < parts; i++)
  33. {
  34. using (var destination = new FileStream(destinationDirectory, FileMode.Create))
  35. {
  36. double fileLength = source.Length;
  37. byte[] buffer = new byte[4096];
  38. while (true)
  39. {
  40. int readBytes = source.Read(buffer, 0, buffer.Length);
  41. if (readBytes == 0)
  42. {
  43. break;
  44. }
  45. destination.Write(buffer, 0, readBytes);
  46. }
  47. }
  48. }
  49. }
  50. }
  51. static void Assemble(List<string> files, string destinationDirectory)
  52. {
  53. var create = new FileStream(destinationDirectory, FileMode.Create);
  54. try
  55. {
  56. for (int i = 0; i < files.Count; i++)
  57. {
  58. var opener = new FileStream(files[i], FileMode.Open);
  59. byte[] bytes = Encoding.ASCII.GetBytes(files[i]);
  60. create.Write(bytes, 0, bytes.Length);
  61. }
  62.  
  63. }
  64. finally
  65. {
  66. create.Close();
  67. }
  68.  
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement