Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace SplitFile
- {
- class SplitInFiles
- {
- static void Slice(string sourceFile, string destinationDir, int parts)
- {
- int bufferSize = 4096 * 4;
- byte[] buffer = new byte[bufferSize];
- FileStream inputStream = new FileStream(sourceFile, FileMode.Open);
- using (inputStream)
- {
- int index = 1;
- int partSize = (int)Math.Ceiling( (double)inputStream.Length / parts);
- while (inputStream.Position < inputStream.Length)
- {
- using (var outputStream = new FileStream(string.Format("{0}part{1}.mp4", destinationDir, index), FileMode.Create))
- {
- int bytesRead = 0;
- while (bytesRead < partSize)
- {
- int bytes = inputStream.Read(buffer, 0, (int)Math.Min(partSize - bytesRead, buffer.Length));
- if (bytes == 0)
- {
- break;
- }
- outputStream.Write(buffer, 0, bytes);
- bytesRead += bytes;
- }
- }
- index++;
- }
- }
- }
- static void Main()
- {
- string sourceFile = @"../../Video.mp4";
- string resultDirectory = @"../../Result/";
- Slice(sourceFile, resultDirectory, 4);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement