Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions test/ICSharpCode.SharpZipLib.Tests/Zip/StreamHandling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using ICSharpCode.SharpZipLib.Tests.TestSupport;
using ICSharpCode.SharpZipLib.Zip;
using NUnit.Framework;
using System;
using System.IO;

namespace ICSharpCode.SharpZipLib.Tests.Zip
Expand Down Expand Up @@ -191,6 +192,49 @@ public void EmptyZipEntries()
Assert.AreEqual(extractCount, 0, "No data should be read from empty entries");
}

/// <summary>
/// Test that calling Write with 0 bytes behaves.
/// See issue @ https://github.com/icsharpcode/SharpZipLib/issues/123.
/// </summary>
[Test]
[Category("Zip")]
public void TestZeroByteWrite()
{
using (var ms = new MemoryStreamWithoutSeek())
{
using (var outStream = new ZipOutputStream(ms) { IsStreamOwner = false })
{
var ze = new ZipEntry("Striped Marlin");
outStream.PutNextEntry(ze);

var buffer = Array.Empty<byte>();
outStream.Write(buffer, 0, 0);
}

ms.Seek(0, SeekOrigin.Begin);

using (var inStream = new ZipInputStream(ms) { IsStreamOwner = false })
{
int extractCount = 0;
byte[] decompressedData = new byte[100];

while (inStream.GetNextEntry() != null)
{
while (true)
{
int numRead = inStream.Read(decompressedData, extractCount, decompressedData.Length);
if (numRead <= 0)
{
break;
}
extractCount += numRead;
}
}
Assert.Zero(extractCount, "No data should be read from empty entries");
}
}
}

[Test]
[Category("Zip")]
public void WriteZipStreamWithNoCompression([Values(0, 1, 256)] int contentLength)
Expand Down