7
7
using System . IO ;
8
8
using System . Security ;
9
9
using System . Text ;
10
+ using System . Threading . Tasks ;
10
11
11
12
namespace ICSharpCode . SharpZipLib . Tests . Zip
12
13
{
@@ -288,7 +289,7 @@ protected static byte ScatterValue(byte rhs)
288
289
return ( byte ) ( ( rhs * 253 + 7 ) & 0xff ) ;
289
290
}
290
291
291
- private static void AddKnownDataToEntry ( ZipOutputStream zipStream , int size )
292
+ private static void AddKnownDataToEntry ( Stream zipStream , int size )
292
293
{
293
294
if ( size > 0 )
294
295
{
@@ -387,6 +388,27 @@ protected void MakeZipFile(Stream storage, bool isOwner,
387
388
}
388
389
}
389
390
391
+ protected void MakeZipFile ( Stream storage , CompressionMethod compressionMethod , bool isOwner ,
392
+ string entryNamePrefix , int entries , int size , string comment )
393
+ {
394
+ using ( ZipFile f = new ZipFile ( storage , leaveOpen : ! isOwner ) )
395
+ {
396
+ f . BeginUpdate ( ) ;
397
+ f . SetComment ( comment ) ;
398
+
399
+ for ( int i = 0 ; i < entries ; ++ i )
400
+ {
401
+ var data = new MemoryStream ( ) ;
402
+ AddKnownDataToEntry ( data , size ) ;
403
+
404
+ var m = new MemoryDataSource ( data . ToArray ( ) ) ;
405
+ f . Add ( m , entryNamePrefix + ( i + 1 ) , compressionMethod ) ;
406
+ }
407
+
408
+ f . CommitUpdate ( ) ;
409
+ }
410
+ }
411
+
390
412
#endregion MakeZipFile Entries
391
413
392
414
protected static void CheckKnownEntry ( Stream inStream , int expectedCount )
@@ -408,6 +430,25 @@ protected static void CheckKnownEntry(Stream inStream, int expectedCount)
408
430
Assert . AreEqual ( expectedCount , total , "Wrong number of bytes read from entry" ) ;
409
431
}
410
432
433
+ protected static async Task CheckKnownEntryAsync ( Stream inStream , int expectedCount )
434
+ {
435
+ byte [ ] buffer = new byte [ 1024 ] ;
436
+
437
+ int bytesRead ;
438
+ int total = 0 ;
439
+ byte nextValue = 0 ;
440
+ while ( ( bytesRead = await inStream . ReadAsync ( buffer , 0 , buffer . Length ) ) > 0 )
441
+ {
442
+ total += bytesRead ;
443
+ for ( int i = 0 ; i < bytesRead ; ++ i )
444
+ {
445
+ Assert . AreEqual ( nextValue , buffer [ i ] , "Wrong value read from entry" ) ;
446
+ nextValue = ScatterValue ( nextValue ) ;
447
+ }
448
+ }
449
+ Assert . AreEqual ( expectedCount , total , "Wrong number of bytes read from entry" ) ;
450
+ }
451
+
411
452
protected byte ReadByteChecked ( Stream stream )
412
453
{
413
454
int rawValue = stream . ReadByte ( ) ;
0 commit comments