|
4 | 4 | using System.IO;
|
5 | 5 | using System.Text;
|
6 | 6 | using ICSharpCode.SharpZipLib.Tests.TestSupport;
|
| 7 | +using System.Threading.Tasks; |
7 | 8 |
|
8 | 9 | namespace ICSharpCode.SharpZipLib.Tests.Zip
|
9 | 10 | {
|
@@ -180,6 +181,53 @@ public void ZipFileStoreAes()
|
180 | 181 | }
|
181 | 182 | }
|
182 | 183 |
|
| 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 | + |
183 | 231 | /// <summary>
|
184 | 232 | /// Test using AES encryption on a file whose contents are Stored rather than deflated
|
185 | 233 | /// </summary>
|
|
0 commit comments