Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- using System.Collections.Generic;
- using System.IO.Compression;
- namespace SplitFileGzip
- {
- class SplitWithGzip
- {
- static void AssembleAndDecompress(List<string> files, string destinationDir, string extension)
- {
- int bufferSize = 4096 * 2;
- FileStream outputStream = new FileStream(string.Format("{0}assembled{1}", destinationDir, extension), FileMode.Append);
- using (outputStream)
- {
- int index = 0;
- while (index < files.Count)
- {
- using (var inputStreams = new FileStream(files[index], FileMode.Open))
- {
- using (var decompressionStream = new GZipStream(inputStreams, CompressionMode.Decompress, false))
- {
- byte[] buffer = new byte[bufferSize];
- while (true)
- {
- int bytes = decompressionStream.Read(buffer, 0, buffer.Length);
- if (bytes == 0)
- {
- break;
- }
- outputStream.Write(buffer, 0, bytes);
- }
- }
- }
- index++;
- }
- }
- }
- static void SliceAndCompress(string sourceFile, string destinationDir, int parts)
- {
- FileStream inputStream = new FileStream(sourceFile, FileMode.Open);
- using (inputStream)
- {
- int bufferSize = 4096 * 2;
- string extension = ".gz";
- int index = 1;
- long partSize = (long)Math.Ceiling((double)inputStream.Length / parts);
- while (inputStream.Position < inputStream.Length)
- {
- using (var outputStream = new FileStream(string.Format("{0}part{1}{2}", destinationDir, index, extension), FileMode.Create))
- {
- using (var compressionStream = new GZipStream(outputStream, CompressionMode.Compress, false))
- {
- byte[] buffer = new byte[bufferSize];
- long bytesRead = 0;
- while (bytesRead < partSize)
- {
- int bytes = inputStream.Read(buffer, 0, buffer.Length);
- if (bytes == 0)
- {
- break;
- }
- compressionStream.Write(buffer, 0, bytes);
- bytesRead += bytes;
- }
- }
- }
- index++;
- }
- }
- }
- static void Main()
- {
- string sourceFile = @"../../Video.mp4";
- string resultDirectory = @"../../Result/";
- string extension = Path.GetExtension(sourceFile);
- //Slice(sourceFile, resultDirectory, 3);
- List<string> compressedFiles = Directory.GetFiles(resultDirectory, "*.gz").ToList();
- AssembleAndDecompress(compressedFiles, resultDirectory, extension);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment