Skip to content

Commit 195b4e2

Browse files
authored
Merge PR#469: Add test for writing using a zero byte buffer
1 parent f36ca37 commit 195b4e2

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

test/ICSharpCode.SharpZipLib.Tests/Zip/StreamHandling.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using ICSharpCode.SharpZipLib.Tests.TestSupport;
33
using ICSharpCode.SharpZipLib.Zip;
44
using NUnit.Framework;
5+
using System;
56
using System.IO;
67

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

195+
/// <summary>
196+
/// Test that calling Write with 0 bytes behaves.
197+
/// See issue @ https://github.com/icsharpcode/SharpZipLib/issues/123.
198+
/// </summary>
199+
[Test]
200+
[Category("Zip")]
201+
public void TestZeroByteWrite()
202+
{
203+
using (var ms = new MemoryStreamWithoutSeek())
204+
{
205+
using (var outStream = new ZipOutputStream(ms) { IsStreamOwner = false })
206+
{
207+
var ze = new ZipEntry("Striped Marlin");
208+
outStream.PutNextEntry(ze);
209+
210+
var buffer = Array.Empty<byte>();
211+
outStream.Write(buffer, 0, 0);
212+
}
213+
214+
ms.Seek(0, SeekOrigin.Begin);
215+
216+
using (var inStream = new ZipInputStream(ms) { IsStreamOwner = false })
217+
{
218+
int extractCount = 0;
219+
byte[] decompressedData = new byte[100];
220+
221+
while (inStream.GetNextEntry() != null)
222+
{
223+
while (true)
224+
{
225+
int numRead = inStream.Read(decompressedData, extractCount, decompressedData.Length);
226+
if (numRead <= 0)
227+
{
228+
break;
229+
}
230+
extractCount += numRead;
231+
}
232+
}
233+
Assert.Zero(extractCount, "No data should be read from empty entries");
234+
}
235+
}
236+
}
237+
194238
[Test]
195239
[Category("Zip")]
196240
public void WriteZipStreamWithNoCompression([Values(0, 1, 256)] int contentLength)

0 commit comments

Comments
 (0)