Fix build_init vcxproj to correctly detect changes in config.h.
[mono.git] / mcs / class / System.IO.Compression / SharpCompress / Reader / Zip / ZipReader.cs
1 using System.Collections.Generic;
2 using System.IO;
3 using SharpCompress.Common;
4 using SharpCompress.Common.Zip;
5 using SharpCompress.Common.Zip.Headers;
6
7 namespace SharpCompress.Reader.Zip
8 {
9     internal class ZipReader : AbstractReader<ZipEntry, ZipVolume>
10     {
11         private readonly StreamingZipHeaderFactory headerFactory;
12         private readonly ZipVolume volume;
13
14         internal ZipReader(Stream stream, Options options, string password)
15             : base(options, ArchiveType.Zip)
16         {
17             volume = new ZipVolume(stream, options);
18             headerFactory = new StreamingZipHeaderFactory(password);
19         }
20
21         public override ZipVolume Volume
22         {
23             get { return volume; }
24         }
25
26         #region Open
27
28         /// <summary>
29         /// Opens a ZipReader for Non-seeking usage with a single volume
30         /// </summary>
31         /// <param name="stream"></param>
32         /// <param name="options"></param>
33         /// <param name="password"></param>
34         /// <returns></returns>
35         public static ZipReader Open(Stream stream, string password = null,
36                                      Options options = Options.KeepStreamsOpen)
37         {
38             stream.CheckNotNull("stream");
39             return new ZipReader(stream, options, password);
40         }
41
42         #endregion
43
44         internal override IEnumerable<ZipEntry> GetEntries(Stream stream)
45         {
46             foreach (ZipHeader h in headerFactory.ReadStreamHeader(stream))
47             {
48                 if (h != null)
49                 {
50                     switch (h.ZipHeaderType)
51                     {
52                         case ZipHeaderType.LocalEntry:
53                             {
54                                 yield return new ZipEntry(new StreamingZipFilePart(h as LocalEntryHeader,
55                                                                                    stream));
56                             }
57                             break;
58                         case ZipHeaderType.DirectoryEnd:
59                             {
60                                 yield break;
61                             }
62                     }
63                 }
64             }
65         }
66     }
67 }