|
1 | | -using ICSharpCode.SharpZipLib.Tests.TestSupport; |
| 1 | +using ICSharpCode.SharpZipLib.Core; |
| 2 | +using ICSharpCode.SharpZipLib.Tests.TestSupport; |
2 | 3 | using ICSharpCode.SharpZipLib.Zip; |
3 | 4 | using NUnit.Framework; |
4 | 5 | using System.IO; |
@@ -190,6 +191,53 @@ public void EmptyZipEntries() |
190 | 191 | Assert.AreEqual(extractCount, 0, "No data should be read from empty entries"); |
191 | 192 | } |
192 | 193 |
|
| 194 | + [Test] |
| 195 | + [Category("Zip")] |
| 196 | + public void WriteZipStreamWithNoCompression([Values(0, 1, 256)] int contentLength) |
| 197 | + { |
| 198 | + var buffer = new byte[255]; |
| 199 | + |
| 200 | + using (var dummyZip = Utils.GetDummyFile(0)) |
| 201 | + using (var inputFile = Utils.GetDummyFile(contentLength)) |
| 202 | + { |
| 203 | + using (var zipFileStream = File.OpenWrite(dummyZip.Filename)) |
| 204 | + using (var zipOutputStream = new ZipOutputStream(zipFileStream)) |
| 205 | + using (var inputFileStream = File.OpenRead(inputFile.Filename)) |
| 206 | + { |
| 207 | + zipOutputStream.PutNextEntry(new ZipEntry(inputFile.Filename) |
| 208 | + { |
| 209 | + CompressionMethod = CompressionMethod.Stored, |
| 210 | + }); |
| 211 | + |
| 212 | + StreamUtils.Copy(inputFileStream, zipOutputStream, buffer); |
| 213 | + } |
| 214 | + |
| 215 | + using (var zf = new ZipFile(dummyZip.Filename)) |
| 216 | + { |
| 217 | + var inputBytes = File.ReadAllBytes(inputFile.Filename); |
| 218 | + |
| 219 | + var inputFileName = ZipEntry.CleanName(inputFile.Filename); |
| 220 | + var entry = zf.GetEntry(inputFileName); |
| 221 | + Assert.IsNotNull(entry, "No entry matching source file \"{0}\" found in archive, found \"{1}\"", inputFileName, zf[0].Name); |
| 222 | + |
| 223 | + Assert.DoesNotThrow(() => |
| 224 | + { |
| 225 | + using (var entryStream = zf.GetInputStream(entry)) |
| 226 | + { |
| 227 | + var outputBytes = new byte[entryStream.Length]; |
| 228 | + entryStream.Read(outputBytes, 0, outputBytes.Length); |
| 229 | + |
| 230 | + Assert.AreEqual(inputBytes, outputBytes, "Archive content does not match the source content"); |
| 231 | + } |
| 232 | + }, "Failed to locate entry stream in archive"); |
| 233 | + |
| 234 | + Assert.IsTrue(zf.TestArchive(testData: true), "Archive did not pass TestArchive"); |
| 235 | + } |
| 236 | + |
| 237 | + |
| 238 | + } |
| 239 | + } |
| 240 | + |
193 | 241 | /// <summary> |
194 | 242 | /// Empty zips can be created and read? |
195 | 243 | /// </summary> |
|
0 commit comments