-
Notifications
You must be signed in to change notification settings - Fork 989
/
Copy pathZipInputStream.cs
814 lines (712 loc) · 22.3 KB
/
ZipInputStream.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
using ICSharpCode.SharpZipLib.Checksum;
using ICSharpCode.SharpZipLib.Encryption;
using ICSharpCode.SharpZipLib.Zip.Compression;
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
using System;
using System.Diagnostics;
using System.IO;
using ICSharpCode.SharpZipLib.Zip.Deflate64;
namespace ICSharpCode.SharpZipLib.Zip
{
/// <summary>
/// This is an InflaterInputStream that reads the files baseInputStream an zip archive
/// one after another. It has a special method to get the zip entry of
/// the next file. The zip entry contains information about the file name
/// size, compressed size, Crc, etc.
/// It includes support for Stored and Deflated entries.
/// <br/>
/// <br/>Author of the original java version : Jochen Hoenicke
/// </summary>
///
/// <example> This sample shows how to read a zip file
/// <code lang="C#">
/// using System;
/// using System.Text;
/// using System.IO;
///
/// using ICSharpCode.SharpZipLib.Zip;
///
/// class MainClass
/// {
/// public static void Main(string[] args)
/// {
/// using ( ZipInputStream s = new ZipInputStream(File.OpenRead(args[0]))) {
///
/// ZipEntry theEntry;
/// const int size = 2048;
/// byte[] data = new byte[2048];
///
/// while ((theEntry = s.GetNextEntry()) != null) {
/// if ( entry.IsFile ) {
/// Console.Write("Show contents (y/n) ?");
/// if (Console.ReadLine() == "y") {
/// while (true) {
/// size = s.Read(data, 0, data.Length);
/// if (size > 0) {
/// Console.Write(new ASCIIEncoding().GetString(data, 0, size));
/// } else {
/// break;
/// }
/// }
/// }
/// }
/// }
/// }
/// }
/// }
/// </code>
/// </example>
public class ZipInputStream : InflaterInputStream
{
#region Instance Fields
/// <summary>
/// Delegate for reading bytes from a stream.
/// </summary>
private delegate int ReadDataHandler(byte[] b, int offset, int length);
/// <summary>
/// The current reader this instance.
/// </summary>
private ReadDataHandler internalReader;
private Crc32 crc = new Crc32();
private ZipEntry entry;
Deflate64Stream inputDeflate64Stream;
byte[] buffer;
private long size;
private CompressionMethod method;
private int flags;
private string password;
private readonly StringCodec _stringCodec = ZipStrings.GetStringCodec();
#endregion Instance Fields
#region Constructors
/// <summary>
/// Creates a new Zip input stream, for reading a zip archive.
/// </summary>
/// <param name="baseInputStream">The underlying <see cref="Stream"/> providing data.</param>
public ZipInputStream(Stream baseInputStream)
: base(baseInputStream, new Inflater(true))
{
internalReader = new ReadDataHandler(ReadingNotAvailable);
}
/// <summary>
/// Creates a new Zip input stream, for reading a zip archive.
/// </summary>
/// <param name="baseInputStream">The underlying <see cref="Stream"/> providing data.</param>
/// <param name="bufferSize">Size of the buffer.</param>
public ZipInputStream(Stream baseInputStream, int bufferSize)
: base(baseInputStream, new Inflater(true), bufferSize)
{
internalReader = new ReadDataHandler(ReadingNotAvailable);
}
/// <summary>
/// Creates a new Zip input stream, for reading a zip archive.
/// </summary>
/// <param name="baseInputStream">The underlying <see cref="Stream"/> providing data.</param>
/// <param name="stringCodec"></param>
public ZipInputStream(Stream baseInputStream, StringCodec stringCodec)
: base(baseInputStream, new Inflater(true))
{
internalReader = new ReadDataHandler(ReadingNotAvailable);
if (stringCodec != null)
{
_stringCodec = stringCodec;
}
}
#endregion Constructors
/// <summary>
/// Optional password used for encryption when non-null
/// </summary>
/// <value>A password for all encrypted <see cref="ZipEntry">entries </see> in this <see cref="ZipInputStream"/></value>
public string Password
{
get
{
return password;
}
set
{
password = value;
}
}
/// <summary>
/// Gets a value indicating if there is a current entry and it can be decompressed
/// </summary>
/// <remarks>
/// The entry can only be decompressed if the library supports the zip features required to extract it.
/// See the <see cref="ZipEntry.Version">ZipEntry Version</see> property for more details.
///
/// Since <see cref="ZipInputStream"/> uses the local headers for extraction, entries with no compression combined with the
/// <see cref="GeneralBitFlags.Descriptor"/> flag set, cannot be extracted as the end of the entry data cannot be deduced.
/// </remarks>
public bool CanDecompressEntry
=> entry != null
&& IsEntryCompressionMethodSupported(entry)
&& entry.CanDecompress
&& (!entry.HasFlag(GeneralBitFlags.Descriptor) || entry.CompressionMethod != CompressionMethod.Stored || entry.IsCrypted);
/// <summary>
/// Is the compression method for the specified entry supported?
/// </summary>
/// <remarks>
/// Uses entry.CompressionMethodForHeader so that entries of type WinZipAES will be rejected.
/// </remarks>
/// <param name="entry">the entry to check.</param>
/// <returns>true if the compression method is supported, false if not.</returns>
private static bool IsEntryCompressionMethodSupported(ZipEntry entry)
{
var entryCompressionMethod = entry.CompressionMethodForHeader;
return entryCompressionMethod == CompressionMethod.Deflated ||
entryCompressionMethod == CompressionMethod.Stored;
}
/// <summary>
/// Advances to the next entry in the archive
/// </summary>
/// <returns>
/// The next <see cref="ZipEntry">entry</see> in the archive or null if there are no more entries.
/// </returns>
/// <remarks>
/// If the previous entry is still open <see cref="CloseEntry">CloseEntry</see> is called.
/// </remarks>
/// <exception cref="InvalidOperationException">
/// Input stream is closed
/// </exception>
/// <exception cref="ZipException">
/// Password is not set, password is invalid, compression method is invalid,
/// version required to extract is not supported
/// </exception>
public ZipEntry GetNextEntry()
{
if (crc == null)
{
throw new InvalidOperationException("Closed.");
}
if (entry != null)
{
CloseEntry();
}
int bufferSize = inputBuffer.RawData.Length;
//Resize the input buffer in order to read file information only and keep the correct position in the stream
//needed for forward-only stream support
//At first step is needed to read the header and after that the file info
inputBuffer.ResizeBuffer(ZipConstants.LocalHeaderBaseSize);
if (!SkipUntilNextEntry())
{
Dispose();
return null;
}
var versionRequiredToExtract = (short)inputBuffer.ReadLeShort();
flags = inputBuffer.ReadLeShort();
method = (CompressionMethod)inputBuffer.ReadLeShort();
var dostime = (uint)inputBuffer.ReadLeInt();
int crc2 = inputBuffer.ReadLeInt();
csize = inputBuffer.ReadLeInt();
size = inputBuffer.ReadLeInt();
int nameLen = inputBuffer.ReadLeShort();
int extraLen = inputBuffer.ReadLeShort();
bool isCrypted = (flags & 1) == 1;
//Resize to read the file name and extra data if available
inputBuffer.ResizeBuffer(nameLen + extraLen);
byte[] buffer = new byte[nameLen];
inputBuffer.ReadRawBuffer(buffer);
var entryEncoding = _stringCodec.ZipInputEncoding(flags);
string name = entryEncoding.GetString(buffer);
var unicode = entryEncoding.IsZipUnicode();
//Back to the original size
inputBuffer.ResizeBuffer(bufferSize);
entry = new ZipEntry(name, versionRequiredToExtract, ZipConstants.VersionMadeBy, method, unicode)
{
Flags = flags,
};
if ((flags & 8) == 0)
{
entry.Crc = crc2 & 0xFFFFFFFFL;
entry.Size = size & 0xFFFFFFFFL;
entry.CompressedSize = csize & 0xFFFFFFFFL;
entry.CryptoCheckValue = (byte)((crc2 >> 24) & 0xff);
}
else
{
// This allows for GNU, WinZip and possibly other archives, the PKZIP spec
// says these values are zero under these circumstances.
if (crc2 != 0)
{
entry.Crc = crc2 & 0xFFFFFFFFL;
}
if (size != 0)
{
entry.Size = size & 0xFFFFFFFFL;
}
if (csize != 0)
{
entry.CompressedSize = csize & 0xFFFFFFFFL;
}
entry.CryptoCheckValue = (byte)((dostime >> 8) & 0xff);
}
entry.DosTime = dostime;
// If local header requires Zip64 is true then the extended header should contain
// both values.
// Handle extra data if present. This can set/alter some fields of the entry.
if (extraLen > 0)
{
byte[] extra = new byte[extraLen];
inputBuffer.ReadRawBuffer(extra);
entry.ExtraData = extra;
}
entry.ProcessExtraData(true);
if (entry.CompressedSize >= 0)
{
csize = entry.CompressedSize;
}
if (entry.Size >= 0)
{
size = entry.Size;
}
if (method == CompressionMethod.Stored && (!isCrypted && csize != size || (isCrypted && csize - ZipConstants.CryptoHeaderSize != size)))
{
throw new ZipException("Stored, but compressed != uncompressed");
}
else if (method == CompressionMethod.Deflate64)
{
//All the needed information for decompression is gathered, no need to proceed
this.inputDeflate64Stream = null;
return entry;
}
// Determine how to handle reading of data if this is attempted.
if (IsEntryCompressionMethodSupported(entry))
{
internalReader = new ReadDataHandler(InitialRead);
}
else
{
internalReader = new ReadDataHandler(ReadingNotSupported);
}
return entry;
}
/// <summary>
/// Reads bytes from the input stream until either a local file header signature, or another signature
/// indicating that no more entries should be present, is found.
/// </summary>
/// <exception cref="ZipException">Thrown if the end of the input stream is reached without any signatures found</exception>
/// <returns>Returns whether the found signature is for a local entry header</returns>
private bool SkipUntilNextEntry()
{
// First let's skip all null bytes since it's the sane padding to add when updating an entry with smaller size
var paddingSkipped = 0;
while(inputBuffer.ReadLeByte() == 0) {
paddingSkipped++;
}
// Last byte read was not actually consumed, restore the offset
inputBuffer.Available += 1;
if(paddingSkipped > 0) {
Debug.WriteLine("Skipped {0} null byte(s) before reading signature", paddingSkipped);
}
var offset = 0;
// Read initial header quad directly after the last entry
var header = (uint)inputBuffer.ReadLeInt();
do
{
switch (header)
{
case ZipConstants.CentralHeaderSignature:
case ZipConstants.EndOfCentralDirectorySignature:
case ZipConstants.CentralHeaderDigitalSignature:
case ZipConstants.ArchiveExtraDataSignature:
case ZipConstants.Zip64CentralFileHeaderSignature:
Debug.WriteLine("Non-entry signature found at offset {0,2}: 0x{1:x8}", offset, header);
// No more individual entries exist
return false;
case ZipConstants.LocalHeaderSignature:
Debug.WriteLine("Entry local header signature found at offset {0,2}: 0x{1:x8}", offset, header);
return true;
default:
// Current header quad did not match any signature, shift in another byte
header = (uint) (inputBuffer.ReadLeByte() << 24) | (header >> 8);
offset++;
break;
}
} while (true); // Loop until we either get an EOF exception or we find the next signature
}
/// <summary>
/// Read data descriptor at the end of compressed data.
/// </summary>
private void ReadDataDescriptor()
{
if (inputBuffer.ReadLeInt() != ZipConstants.DataDescriptorSignature)
{
throw new ZipException("Data descriptor signature not found");
}
entry.Crc = inputBuffer.ReadLeInt() & 0xFFFFFFFFL;
if (entry.LocalHeaderRequiresZip64)
{
csize = inputBuffer.ReadLeLong();
size = inputBuffer.ReadLeLong();
}
else
{
csize = inputBuffer.ReadLeInt();
size = inputBuffer.ReadLeInt();
}
entry.CompressedSize = csize;
entry.Size = size;
}
/// <summary>
/// Complete cleanup as the final part of closing.
/// </summary>
/// <param name="testCrc">True if the crc value should be tested</param>
private void CompleteCloseEntry(bool testCrc)
{
StopDecrypting();
if ((flags & 8) != 0)
{
ReadDataDescriptor();
}
size = 0;
if (testCrc &&
((crc.Value & 0xFFFFFFFFL) != entry.Crc) && (entry.Crc != -1))
{
throw new ZipException("CRC mismatch");
}
crc.Reset();
if (method == CompressionMethod.Deflated)
{
inf.Reset();
}
entry = null;
}
/// <summary>
/// Closes the current zip entry and moves to the next one.
/// </summary>
/// <exception cref="InvalidOperationException">
/// The stream is closed
/// </exception>
/// <exception cref="ZipException">
/// The Zip stream ends early
/// </exception>
public void CloseEntry()
{
if (crc == null)
{
throw new InvalidOperationException("Closed");
}
if (entry == null)
{
return;
}
if (entry.CompressionMethod == CompressionMethod.Deflate64)
{
//There is no need of inputBuffer processing, all information is available; this would move the stream position
return;
}
if (method == CompressionMethod.Deflated)
{
if ((flags & 8) != 0)
{
// We don't know how much we must skip, read until end.
byte[] tmp = new byte[4096];
// Read will close this entry
while (Read(tmp, 0, tmp.Length) > 0)
{
}
return;
}
csize -= inf.TotalIn;
inputBuffer.Available += inf.RemainingInput;
}
if ((inputBuffer.Available > csize) && (csize >= 0))
{
// Buffer can contain entire entry data. Internally offsetting position inside buffer
inputBuffer.Available = (int)((long)inputBuffer.Available - csize);
}
else
{
csize -= inputBuffer.Available;
inputBuffer.Available = 0;
while (csize != 0)
{
long skipped = Skip(csize);
if (skipped <= 0)
{
throw new ZipException("Zip archive ends early.");
}
csize -= skipped;
}
}
CompleteCloseEntry(false);
}
/// <summary>
/// Returns 1 if there is an entry available
/// Otherwise returns 0.
/// </summary>
public override int Available
{
get
{
return entry != null ? 1 : 0;
}
}
/// <summary>
/// Returns the current size that can be read from the current entry if available
/// </summary>
/// <exception cref="ZipException">Thrown if the entry size is not known.</exception>
/// <exception cref="InvalidOperationException">Thrown if no entry is currently available.</exception>
public override long Length
{
get
{
if (entry != null)
{
if (entry.Size >= 0)
{
return entry.Size;
}
else
{
throw new ZipException("Length not available for the current entry");
}
}
else
{
throw new InvalidOperationException("No current entry");
}
}
}
/// <summary>
/// Reads a byte from the current zip entry.
/// </summary>
/// <returns>
/// The byte or -1 if end of stream is reached.
/// </returns>
public override int ReadByte()
{
byte[] b = new byte[1];
if (Read(b, 0, 1) <= 0)
{
return -1;
}
return b[0] & 0xff;
}
/// <summary>
/// Handle attempts to read by throwing an <see cref="InvalidOperationException"/>.
/// </summary>
/// <param name="destination">The destination array to store data in.</param>
/// <param name="offset">The offset at which data read should be stored.</param>
/// <param name="count">The maximum number of bytes to read.</param>
/// <returns>Returns the number of bytes actually read.</returns>
private int ReadingNotAvailable(byte[] destination, int offset, int count)
{
throw new InvalidOperationException("Unable to read from this stream");
}
/// <summary>
/// Handle attempts to read from this entry by throwing an exception
/// </summary>
private int ReadingNotSupported(byte[] destination, int offset, int count)
{
throw new ZipException("The compression method for this entry is not supported");
}
/// <summary>
/// Handle attempts to read from this entry by throwing an exception
/// </summary>
private int StoredDescriptorEntry(byte[] destination, int offset, int count) =>
throw new StreamUnsupportedException(
"The combination of Stored compression method and Descriptor flag is not possible to read using ZipInputStream");
/// <summary>
/// Perform the initial read on an entry which may include
/// reading encryption headers and setting up inflation.
/// </summary>
/// <param name="destination">The destination to fill with data read.</param>
/// <param name="offset">The offset to start reading at.</param>
/// <param name="count">The maximum number of bytes to read.</param>
/// <returns>The actual number of bytes read.</returns>
private int InitialRead(byte[] destination, int offset, int count)
{
var usesDescriptor = (entry.Flags & (int)GeneralBitFlags.Descriptor) != 0;
// Handle encryption if required.
if (entry.IsCrypted)
{
if (password == null)
{
throw new ZipException("No password set.");
}
// Generate and set crypto transform...
var managed = new PkzipClassicManaged();
byte[] key = PkzipClassic.GenerateKeys(_stringCodec.ZipCryptoEncoding.GetBytes(password));
inputBuffer.CryptoTransform = managed.CreateDecryptor(key, null);
byte[] cryptbuffer = new byte[ZipConstants.CryptoHeaderSize];
inputBuffer.ReadClearTextBuffer(cryptbuffer, 0, ZipConstants.CryptoHeaderSize);
if (cryptbuffer[ZipConstants.CryptoHeaderSize - 1] != entry.CryptoCheckValue)
{
throw new ZipException("Invalid password");
}
if (csize >= ZipConstants.CryptoHeaderSize)
{
csize -= ZipConstants.CryptoHeaderSize;
}
else if (!usesDescriptor)
{
throw new ZipException($"Entry compressed size {csize} too small for encryption");
}
}
else
{
inputBuffer.CryptoTransform = null;
}
if (csize > 0 || usesDescriptor)
{
if (method == CompressionMethod.Deflated && inputBuffer.Available > 0)
{
inputBuffer.SetInflaterInput(inf);
}
// It's not possible to know how many bytes to read when using "Stored" compression (unless using encryption)
if (!entry.IsCrypted && method == CompressionMethod.Stored && usesDescriptor)
{
internalReader = StoredDescriptorEntry;
return StoredDescriptorEntry(destination, offset, count);
}
if (!CanDecompressEntry)
{
internalReader = ReadingNotSupported;
return ReadingNotSupported(destination, offset, count);
}
internalReader = BodyRead;
return BodyRead(destination, offset, count);
}
internalReader = ReadingNotAvailable;
return 0;
}
/// <summary>
/// Read a block of bytes from the stream.
/// </summary>
/// <param name="buffer">The destination for the bytes.</param>
/// <param name="offset">The index to start storing data.</param>
/// <param name="count">The number of bytes to attempt to read.</param>
/// <returns>Returns the number of bytes read.</returns>
/// <remarks>Zero bytes read means end of stream.</remarks>
public override int Read(byte[] buffer, int offset, int count)
{
if (buffer == null)
{
throw new ArgumentNullException(nameof(buffer));
}
if (offset < 0)
{
throw new ArgumentOutOfRangeException(nameof(offset), "Cannot be negative");
}
if (count < 0)
{
throw new ArgumentOutOfRangeException(nameof(count), "Cannot be negative");
}
if ((buffer.Length - offset) < count)
{
throw new ArgumentException("Invalid offset/count combination");
}
if (entry.CompressionMethod == CompressionMethod.Deflate64)
{
if (inputDeflate64Stream == null)
{
inputDeflate64Stream = new Deflate64Stream(base.baseInputStream, entry.CompressedSize);
}
return inputDeflate64Stream.Read(buffer, 0, count);
}
else
{
return internalReader(buffer, offset, count);
}
}
/// <summary>
/// Reads a block of bytes from the current zip entry.
/// </summary>
/// <returns>
/// The number of bytes read (this may be less than the length requested, even before the end of stream), or 0 on end of stream.
/// </returns>
/// <exception cref="IOException">
/// An i/o error occurred.
/// </exception>
/// <exception cref="ZipException">
/// The deflated stream is corrupted.
/// </exception>
/// <exception cref="InvalidOperationException">
/// The stream is not open.
/// </exception>
private int BodyRead(byte[] buffer, int offset, int count)
{
if (crc == null)
{
throw new InvalidOperationException("Closed");
}
if ((entry == null) || (count <= 0))
{
return 0;
}
if (offset + count > buffer.Length)
{
throw new ArgumentException("Offset + count exceeds buffer size");
}
bool finished = false;
switch (method)
{
case CompressionMethod.Deflated:
count = base.Read(buffer, offset, count);
if (count <= 0)
{
if (!inf.IsFinished)
{
throw new ZipException("Inflater not finished!");
}
inputBuffer.Available = inf.RemainingInput;
// A csize of -1 is from an unpatched local header
if ((flags & 8) == 0 &&
(inf.TotalIn != csize && csize != 0xFFFFFFFF && csize != -1 || inf.TotalOut != size))
{
throw new ZipException("Size mismatch: " + csize + ";" + size + " <-> " + inf.TotalIn + ";" + inf.TotalOut);
}
inf.Reset();
finished = true;
}
break;
case CompressionMethod.Stored:
if ((count > csize) && (csize >= 0))
{
count = (int)csize;
}
if (count > 0)
{
count = inputBuffer.ReadClearTextBuffer(buffer, offset, count);
if (count > 0)
{
csize -= count;
size -= count;
}
}
if (csize == 0)
{
finished = true;
}
else
{
if (count < 0)
{
throw new ZipException("EOF in stored block");
}
}
break;
}
if (count > 0)
{
crc.Update(new ArraySegment<byte>(buffer, offset, count));
}
if (finished)
{
CompleteCloseEntry(true);
}
return count;
}
/// <summary>
/// Closes the zip input stream
/// </summary>
protected override void Dispose(bool disposing)
{
internalReader = new ReadDataHandler(ReadingNotAvailable);
crc = null;
entry = null;
base.Dispose(disposing);
}
}
}