Skip to content

Commit 78bc308

Browse files
committed
add an extra unit test for doing an async read on a ZipFile InputStream
1 parent c814877 commit 78bc308

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.IO;
55
using System.Text;
66
using ICSharpCode.SharpZipLib.Tests.TestSupport;
7+
using System.Threading.Tasks;
78

89
namespace ICSharpCode.SharpZipLib.Tests.Zip
910
{
@@ -180,6 +181,53 @@ public void ZipFileStoreAes()
180181
}
181182
}
182183

184+
/// <summary>
185+
/// As <see cref="ZipFileStoreAes"/>, but with Async reads
186+
/// </summary>
187+
[Test]
188+
[Category("Encryption")]
189+
[Category("Zip")]
190+
public async Task ZipFileStoreAesAsync()
191+
{
192+
string password = "password";
193+
194+
using (var memoryStream = new MemoryStream())
195+
{
196+
// Try to create a zip stream
197+
WriteEncryptedZipToStream(memoryStream, password, 256, CompressionMethod.Stored);
198+
199+
// reset
200+
memoryStream.Seek(0, SeekOrigin.Begin);
201+
202+
// try to read it
203+
var zipFile = new ZipFile(memoryStream, leaveOpen: true)
204+
{
205+
Password = password
206+
};
207+
208+
foreach (ZipEntry entry in zipFile)
209+
{
210+
if (!entry.IsFile) continue;
211+
212+
// Should be stored rather than deflated
213+
Assert.That(entry.CompressionMethod, Is.EqualTo(CompressionMethod.Stored), "Entry should be stored");
214+
215+
using (var zis = zipFile.GetInputStream(entry))
216+
{
217+
var buffer = new byte[entry.Size];
218+
219+
using (var inputStream = zipFile.GetInputStream(entry))
220+
{
221+
await zis.ReadAsync(buffer, 0, buffer.Length);
222+
}
223+
224+
var content = Encoding.UTF8.GetString(buffer);
225+
Assert.That(content, Is.EqualTo(DummyDataString), "Decompressed content does not match input data");
226+
}
227+
}
228+
}
229+
}
230+
183231
/// <summary>
184232
/// Test using AES encryption on a file whose contents are Stored rather than deflated
185233
/// </summary>

0 commit comments

Comments
 (0)