3 // Copyright (c) 2008 [copyright holders]
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
30 class UnzipArchive : IDisposable
34 internal bool FileActive {
41 files = NativeUnzip.GetFiles (Handle);
46 internal UnzipHandle Handle {
54 public UnzipArchive (string filename)
55 : this (File.Open (filename, FileMode.Open), true)
60 public UnzipArchive (Stream stream)
61 : this (stream, false)
66 public UnzipArchive (Stream stream, bool ownsStream)
68 Stream = new ZipStream (stream, ownsStream);
69 Handle = NativeUnzip.OpenArchive (Stream.IOFunctions);
72 public void Dispose ()
74 NativeUnzip.CloseArchive (Handle);
78 public System.IO.Packaging.CompressionOption GetCompressionLevel (string file)
80 using (UnzipReadStream stream = (UnzipReadStream) GetStream (file))
81 return stream.CompressionLevel;
84 public string[] GetFiles ()
86 return (string []) Files.Clone ();
89 public Stream GetStream (string name)
91 foreach (string file in Files)
93 if (name.Equals(file, StringComparison.OrdinalIgnoreCase))
95 System.IO.Packaging.CompressionOption option;
96 NativeUnzip.OpenFile (Handle, name, out option);
97 return new UnzipReadStream (this, option);
101 throw new Exception ("The file doesn't exist in the zip archive");