1 // Native.cs created with MonoDevelop
2 // User: alan at 12:18 13/10/2008
4 // To change standard headers go to Edit->Preferences->Coding->Standard Headers
9 using System
.Runtime
.InteropServices
;
13 static class NativeZip
15 const int DEFAULT_COMPRESSION
= 0;
16 const int Z_DEFLATED
= 8;
18 public static void CloseArchive (ZipHandle handle
)
20 CloseArchive (handle
, null);
23 public static void CloseArchive (ZipHandle handle
, string comment
)
25 zipClose (handle
, comment
);
26 handle
.SetHandleAsInvalid ();
29 public static void CloseFile (ZipHandle handle
)
31 zipCloseFileInZip (handle
);
34 public static ZipHandle
OpenArchive (ZlibFileFuncDef funcDef
, Append append
)
36 ZipHandle h
= zipOpen2 ("", (int) append
, IntPtr
.Zero
, ref funcDef
);
38 throw new Exception ("Could not open the zip archive");
42 public static int OpenFile (ZipHandle handle
, string filename
)
44 return OpenFile (handle
, filename
, DEFAULT_COMPRESSION
);
47 public static int OpenFile (ZipHandle handle
, string filename
, int compressionLevel
)
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
);
54 public static unsafe void Write (ZipHandle handle
, byte[] buffer
, int offset
, uint count
)
56 fixed (byte* b
= &buffer
[offset
])
57 zipWriteInFileInZip (handle
, b
, count
);
60 [DllImport ("MonoPosixHelper")]
61 static extern unsafe int zipWriteInFileInZip (ZipHandle handle
,
65 [DllImport ("MonoPosixHelper")]
66 static extern int zipCloseFileInZip (ZipHandle handle
);
68 [DllImport ("MonoPosixHelper")]
69 static extern ZipHandle
zipOpen2 (string pathname
,
71 IntPtr globalcomment
, // zipcharpc*
72 ref ZlibFileFuncDef pzlib_filefunc_def
); // zlib_filefunc_def*
75 [DllImport ("MonoPosixHelper")]
76 static extern int zipClose (ZipHandle handle
, string globalComment
);
78 [DllImport ("MonoPosixHelper")]
79 static extern int zipOpenNewFileInZip (ZipHandle handle
,
81 ref ZipFileInfo zipfi
,
82 IntPtr extrafield_local
,
83 uint size_extrafield_local
,
84 IntPtr extrafield_global
,
85 uint size_extrafield_global
,