Skip to content

Commit

Permalink
Merge PR #371: Add test for GZip with small buffer
Browse files Browse the repository at this point in the history
Add test reproducing issue #360
  • Loading branch information
piksel authored Aug 6, 2019
1 parent 1435683 commit 34d7472
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions test/ICSharpCode.SharpZipLib.Tests/GZip/GZipTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,56 @@ public void FlushToUnderlyingStream()
}
}

[Test]
[Category("GZip")]
public void SmallBufferDecompression()
{
var outputBufferSize = 100000;
var inputBufferSize = outputBufferSize * 4;

var outputBuffer = new byte[outputBufferSize];
var inputBuffer = new byte[inputBufferSize];

using (var msGzip = new MemoryStream())
{
using (var gzos = new GZipOutputStream(msGzip))
{
gzos.IsStreamOwner = false;

var rnd = new Random(0);
rnd.NextBytes(inputBuffer);
gzos.Write(inputBuffer, 0, inputBuffer.Length);

gzos.Flush();
gzos.Finish();
}

msGzip.Seek(0, SeekOrigin.Begin);


using (var gzis = new GZipInputStream(msGzip))
using (var msRaw = new MemoryStream())
{

int readOut;
while ((readOut = gzis.Read(outputBuffer, 0, outputBuffer.Length)) > 0)
{
msRaw.Write(outputBuffer, 0, readOut);
}

var resultBuffer = msRaw.ToArray();

for (var i = 0; i < resultBuffer.Length; i++)
{
Assert.AreEqual(inputBuffer[i], resultBuffer[i]);
}


}
}

}

[Test]
[Category("GZip")]
[Category("Performance")]
Expand Down

0 comments on commit 34d7472

Please sign in to comment.