[corlib] RemotingConfiguration now try to use the bundled machine.config first.
[mono.git] / mcs / class / WindowsBase / ZipSharp / ZipArchive.cs
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 //
6
7 using System;
8 using System.IO;
9 using System.IO.Packaging;
10
11 namespace zipsharp
12 {
13         class ZipArchive : IDisposable
14         {
15                 internal bool FileActive { get; set; }
16                 internal ZipHandle Handle { get; private set; }
17                 ZipStream Stream { get; set; }
18         
19                 public ZipArchive (string filename, Append append)
20                         : this (File.Open (filename, FileMode.OpenOrCreate), append)
21                 {
22
23                 }
24
25                 public ZipArchive (Stream stream, Append append)
26                         : this (stream, append, false)
27                 {
28                         
29                 }
30
31                 public ZipArchive (Stream stream, Append append, bool ownsStream)
32                 {
33                         Stream = new ZipStream (stream, ownsStream);
34                         Handle = NativeZip.OpenArchive (Stream.IOFunctions, append);
35                 }
36
37                 
38                 static int ConvertCompression (System.IO.Packaging.CompressionOption option)
39                 {
40                         switch (option)
41                         {
42                         case CompressionOption.SuperFast:
43                                 return 2;
44                                 
45                         case CompressionOption.Fast:
46                                 return 4;
47                                 
48                         case CompressionOption.Normal:
49                                 return 6;
50                                 
51                         case CompressionOption.Maximum:
52                                 return 9;
53
54                         default:
55                                 return 0;
56                         }
57                 }
58
59
60                 public Stream GetStream (string filename, System.IO.Packaging.CompressionOption option)
61                 {
62                         if (FileActive)
63                                 throw new InvalidOperationException ("A file is already open");
64                         
65                         NativeZip.OpenFile (Handle, filename, ConvertCompression (option));
66                         return new ZipWriteStream (this);
67                 }
68
69                 public void Dispose ()
70                 {
71                         NativeZip.CloseArchive (Handle);
72                         Stream.Close ();
73                 }
74         }
75 }