Hi thank you for everybody’s input. It turns out the error was caused by a mistake in encoding method. The method was
/// <summary>
/// Compress file data and then base64s the compressed data for safe transportation in XML.
/// </summary>
/// <returns>Base64 string of file chunk</returns>
private string GetFileChunk()
{
// MemoryStream for compression output
using (MemoryStream compressed = new MemoryStream())
{
using (GZipStream zip = new GZipStream(compressed, CompressionMode.Compress))
{
// read chunk from file
byte[] plaintext = new byte[this.readSize];
int read = this.file.Read(plaintext, 0, plaintext.Length);
// write chunk to compreesion
zip.Write(plaintext, 0, read);
plaintext = null;
// Base64 compressed data
return Convert.ToBase64String(compressed.ToArray());
}
}
}
The return line should be below the using allowing the compression stream to close and flush, this caused the inconsistent behaviour when decompressing the stream.
/// <summary>
/// Compress file data and then base64s the compressed data for safe transportation in XML.
/// </summary>
/// <returns>Base64 string of file chunk</returns>
private string GetFileChunk()
{
// MemoryStream for compression output
using (MemoryStream compressed = new MemoryStream())
{
using (GZipStream zip = new GZipStream(compressed, CompressionMode.Compress))
{
// read chunk from file
byte[] plaintext = new byte[this.readSize];
int read = this.file.Read(plaintext, 0, plaintext.Length);
// write chunk to compreesion
zip.Write(plaintext, 0, read);
plaintext = null;
}
// Base64 compressed data
return Convert.ToBase64String(compressed.ToArray());
}
}
Thank you for everybody's help.