|
2 | 2 | using ICSharpCode.SharpZipLib.Tests.TestSupport; |
3 | 3 | using ICSharpCode.SharpZipLib.Zip; |
4 | 4 | using NUnit.Framework; |
| 5 | +using System; |
5 | 6 | using System.IO; |
6 | 7 |
|
7 | 8 | namespace ICSharpCode.SharpZipLib.Tests.Zip |
@@ -191,6 +192,49 @@ public void EmptyZipEntries() |
191 | 192 | Assert.AreEqual(extractCount, 0, "No data should be read from empty entries"); |
192 | 193 | } |
193 | 194 |
|
| 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 | + |
194 | 238 | [Test] |
195 | 239 | [Category("Zip")] |
196 | 240 | public void WriteZipStreamWithNoCompression([Values(0, 1, 256)] int contentLength) |
|
0 commit comments