I have a one big .bak
file - near 12gb.
I need to split it on into multiple 2gb .gz
archives in code.
And big problem is that I need to validate this archives later.
You know like when you split one file with winrar on 3 or 4 archives, and then you just push "unpack" and it will unpack them all into one file, or crash if there is not enough archives(you delete one).
I need something like this.
public void Compress(DirectoryInfo directorySelected)
{
int writeStat = 0;
foreach (FileInfo fileToCompress in directorySelected.GetFiles())
{
using (FileStream originalFileStream = fileToCompress.OpenRead())
{
if ((File.GetAttributes(fileToCompress.FullName) &
FileAttributes.Hidden) != FileAttributes.Hidden & fileToCompress.Extension != ".gz")
{
bytesToRead = new byte[originalFileStream.Length];
int numBytesRead = bytesToRead.Length;
while (_nowOffset < originalFileStream.Length)
{
writeStat = originalFileStream.Read(bytesToRead, 0, homMuchRead);
using (FileStream compressedFileStream = File.Create(fileToCompress.FullName + counter + ".gz"))
{
using (GZipStream compressionStream = new GZipStream(compressedFileStream,
CompressionMode.Compress))
{
compressionStream.Write(bytesToRead, 0, writeStat);
}
}
_nowOffset = _nowOffset + writeStat;
counter++;
}
FileInfo info = new FileInfo(directoryPath + Path.DirectorySeparatorChar + fileToCompress.Name + ".gz");
//Console.WriteLine($"Compressed {fileToCompress.Name} from {fileToCompress.Length.ToString()} to {info.Length.ToString()} bytes.");
}
}
}
}
It works well, but i don't know how to validate their count.
I have 7 archive on test object. But how to read them in one file, and validate that this file is full.