[jit] Use MONO_INS_IS_PCONST_NULL () macro in more places.
[mono.git] / mcs / class / WindowsBase / ZipSharp / NativeZip.cs
1 // Native.cs created with MonoDevelop
2 // User: alan at 12:18 13/10/2008
3 //
4 // To change standard headers go to Edit->Preferences->Coding->Standard Headers
5 //
6
7
8 using System;
9 using System.Runtime.InteropServices;
10
11 namespace zipsharp
12 {
13         static class NativeZip
14         {
15                 const int DEFAULT_COMPRESSION = 0;
16                 const int Z_DEFLATED = 8;
17
18                 public static void CloseArchive (ZipHandle handle)
19                 {
20                         CloseArchive (handle, null);
21                 }
22
23                 public static void CloseArchive (ZipHandle handle, string comment)
24                 {
25                         zipClose (handle, comment);
26                         handle.SetHandleAsInvalid ();
27                 }
28
29                 public static void CloseFile (ZipHandle handle)
30                 {
31                         zipCloseFileInZip (handle);
32                 }
33
34                 public static ZipHandle OpenArchive (ZlibFileFuncDef funcDef, Append append)
35                 {
36                         ZipHandle h = zipOpen2 ("", (int) append, IntPtr.Zero, ref funcDef);
37                         if (h.IsInvalid)
38                                 throw new Exception ("Could not open the zip archive");
39                         return h;
40                 }
41                 
42                 public static int OpenFile (ZipHandle handle, string filename)
43                 {
44                         return OpenFile (handle, filename, DEFAULT_COMPRESSION);
45                 }
46
47                 public static int OpenFile (ZipHandle handle, string filename, int compressionLevel)
48                 {
49                         ZipFileInfo fileInfo = new ZipFileInfo (DateTime.Now);
50                         int method = compressionLevel == 0 ? 0 : Z_DEFLATED;
51                         return zipOpenNewFileInZip (handle, filename, ref fileInfo, IntPtr.Zero, 0, IntPtr.Zero, 0, "", method, compressionLevel);
52                 }
53
54                 public static unsafe void Write (ZipHandle handle, byte[] buffer, int offset, uint count)
55                 {
56                         fixed (byte* b = &buffer[offset])
57                                 zipWriteInFileInZip (handle, b, count);
58                 }
59
60                 [DllImport ("MonoPosixHelper")]
61                 static extern unsafe int zipWriteInFileInZip (ZipHandle handle,
62                                                                byte* buffer,
63                                                                uint len);
64
65                 [DllImport ("MonoPosixHelper")]
66                 static extern int zipCloseFileInZip (ZipHandle handle);
67
68                 [DllImport ("MonoPosixHelper")]
69                 static extern ZipHandle zipOpen2 (string pathname,
70                                                   int append,
71                                                   IntPtr globalcomment, // zipcharpc*
72                                                   ref ZlibFileFuncDef pzlib_filefunc_def); // zlib_filefunc_def*
73
74                 
75                 [DllImport ("MonoPosixHelper")]
76                 static extern int zipClose (ZipHandle handle, string globalComment);
77
78                 [DllImport ("MonoPosixHelper")]
79                 static extern int zipOpenNewFileInZip (ZipHandle handle,
80                                                        string filename,
81                                                        ref ZipFileInfo zipfi,
82                                                        IntPtr extrafield_local,
83                                                        uint size_extrafield_local,
84                                                        IntPtr extrafield_global,
85                                                        uint size_extrafield_global,
86                                                        string comment,
87                                                        int method,
88                                                        int level);
89         }
90 }