2010-03-05 Rodrigo Kumpera <rkumpera@novell.com>
[mcs.git] / class / WindowsBase / ZipSharp / ZipArchive.cs
blob8f60aab4e9eedc97a8f48be7ffadc1e8e50e56b4
1 // ZipArchive.cs created with MonoDevelop
2 // User: alan at 16:31 20/10/2008
3 //
4 // To change standard headers go to Edit->Preferences->Coding->Standard Headers
5 //
7 using System;
8 using System.IO;
9 using System.IO.Packaging;
11 namespace zipsharp
13 class ZipArchive : IDisposable
15 internal bool FileActive { get; set; }
16 internal ZipHandle Handle { get; private set; }
17 ZipStream Stream { get; set; }
19 public ZipArchive (string filename, Append append)
20 : this (File.Open (filename, FileMode.OpenOrCreate), append)
25 public ZipArchive (Stream stream, Append append)
26 : this (stream, append, false)
31 public ZipArchive (Stream stream, Append append, bool ownsStream)
33 Stream = new ZipStream (stream, ownsStream);
34 Handle = NativeZip.OpenArchive (Stream.IOFunctions, append);
38 static int ConvertCompression (System.IO.Packaging.CompressionOption option)
40 switch (option)
42 case CompressionOption.SuperFast:
43 return 2;
45 case CompressionOption.Fast:
46 return 4;
48 case CompressionOption.Normal:
49 return 6;
51 case CompressionOption.Maximum:
52 return 9;
54 default:
55 return 0;
60 public Stream GetStream (string filename, System.IO.Packaging.CompressionOption option)
62 if (FileActive)
63 throw new InvalidOperationException ("A file is already open");
65 NativeZip.OpenFile (Handle, filename, ConvertCompression (option));
66 return new ZipWriteStream (this);
69 public void Dispose ()
71 NativeZip.CloseArchive (Handle);
72 Stream.Close ();