Here was my solution:
FileStream
sourceStream = File.OpenRead(file.FullName);
FileInfo destFile = newFileInfo(ArchiveLocation + nsyskey.ToString() + ".gz");
FileStream destStream = File.Create(destFile.FullName);
GZipStream compressedzipStream =
new GZipStream(destStream, CompressionMode.Compress, true);
bool isError = false;
byte[] buffer = newbyte[0];
FileStream infile;
try
{
constint MAX_BUFFER_SIZE = 100000;
// Read the file to ensure it is readable.
int start = 0;
int last = System.Convert.ToInt32(infile.Length);
int bufferSize = MAX_BUFFER_SIZE;
while (start < last)
{
if (start + MAX_BUFFER_SIZE > last)
{
bufferSize = last - start;
}
buffer =
newbyte[bufferSize];
int count = infile.Read(buffer, 0, bufferSize);
if (count != bufferSize)
{
infile.Close();
compressedzipStream.Close();
Console.WriteLine("Test Failed: Unable to read data from file");
return;
}
compressedzipStream.Write(buffer, 0, bufferSize);
start += bufferSize;
}
}
finally
{
infile.Close();
compressedzipStream.Close();
}
Decompression was very similar expect you convert the last 4 bytes to be your last and read from the gzipstream and write to the filestream