static Tuple<string, CompressionOption> GetCurrentFileNameAndCompression(UnzipHandle handle) { UnzipFileInfo info; string filename = String.Empty; int result = unzGetCurrentFileInfo (handle, out info, null, IntPtr.Zero, IntPtr.Zero, new IntPtr (0), null, IntPtr.Zero); if (result != 0) return null; StringBuilder sbName = new StringBuilder ((int)info.SizeFilename+1); // +1 to account for extra \0 at the end result = unzGetCurrentFileInfo (handle, out info, sbName, new IntPtr (sbName.Capacity), IntPtr.Zero, new IntPtr (0), null, IntPtr.Zero); if (result != 0) return null; else filename = sbName.ToString (); int method, compression; // '0' means do not open in raw mode (raw == do not decompress) if (unzOpenCurrentFile2 (handle, out method, out compression, 0) != 0) throw new Exception ("The file could not be opened"); CompressionOption level = ConvertCompression (method == 0 ? 0 : compression); return Tuple.Create (filename, level); }
public static long CurrentFileLength (UnzipHandle handle) { UnzipFileInfo info; int result = unzGetCurrentFileInfo (handle, out info, null, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, null, IntPtr.Zero); if (result != 0) return -1; else return (long)info.UncompressedSize; }
static string GetCurrentFileName32 (UnzipHandle handle) { UnzipFileInfo32 info; if (unzGetCurrentFileInfo_32 (handle, out info, null, 0, IntPtr.Zero, 0, null, 0) != 0) return null; var sbName = new StringBuilder ((int) info.size_filename + 1); // +1 to account for extra \0 at the end if (unzGetCurrentFileInfo_32 (handle, out info, sbName, (uint) sbName.Capacity, IntPtr.Zero, 0, null, 0) != 0) return null; return sbName.ToString (); }
static string GetCurrentFileName (UnzipHandle handle) { UnzipFileInfo info; StringBuilder sbName = new StringBuilder (128); int result = unzGetCurrentFileInfo (handle, out info, sbName, new IntPtr (sbName.Capacity), IntPtr.Zero, new IntPtr (0), null, IntPtr.Zero); if (result != 0) return null; else return sbName.ToString (); }
public static long CurrentFileLength (UnzipHandle handle) { UnzipFileInfo info; StringBuilder sbName = new StringBuilder (128); int result = unzGetCurrentFileInfo (handle, out info, sbName, new IntPtr (sbName.Capacity), IntPtr.Zero, IntPtr.Zero, null, IntPtr.Zero); if (result != 0) return -1; else return (long)info.UncompressedSize; }
static string GetCurrentFileName (UnzipHandle handle) { UnzipFileInfo info; int result = unzGetCurrentFileInfo (handle, out info, null, IntPtr.Zero, IntPtr.Zero, new IntPtr (0), null, IntPtr.Zero); if (result != 0) return null; StringBuilder sbName = new StringBuilder ((int)info.SizeFilename+1); // +1 to account for extra \0 at the end result = unzGetCurrentFileInfo (handle, out info, sbName, new IntPtr (sbName.Capacity), IntPtr.Zero, new IntPtr (0), null, IntPtr.Zero); if (result != 0) return null; else return sbName.ToString (); }
static bool GoToNextFile (UnzipHandle handle) { return unzGoToNextFile(handle) == 0; }
public static long CurrentFileLength64 (UnzipHandle handle) { UnzipFileInfo64 info; int result = unzGetCurrentFileInfo_64 (handle, out info, null, 0, IntPtr.Zero, 0, null, 0); return result != 0 ? -1 : (long) info.uncompressed_size; }
public static void CloseArchive (UnzipHandle handle) { unzClose (handle); handle.SetHandleAsInvalid (); }
static unsafe extern int unzReadCurrentFile (UnzipHandle handle, byte* buf, // voidp uint len);
static extern int unzOpenCurrentFile2 (UnzipHandle handle, out int method, out int level, int raw);
static extern int unzGoToNextFile (UnzipHandle handle);
static extern int unzCloseCurrentFile (UnzipHandle handle);
static extern int unzOpenCurrentFile2(UnzipHandle handle, out int method, out int level, int raw);
static extern int unzLocateFile(UnzipHandle handle, string szFileName, int iCaseSensitivity);
static extern int unzGoToNextFile(UnzipHandle handle);
static extern IntPtr unztell(UnzipHandle handle);
static extern int unzCloseCurrentFile(UnzipHandle handle);
static bool GoToNextFile(UnzipHandle handle) { return(unzGoToNextFile(handle) == 0); }
public static string[] GetFiles64 (UnzipHandle handle) { return GetFiles (handle, GetCurrentFileName64); }
public static void OpenFile (UnzipHandle handle, string name, out CompressionOption level) { if (unzLocateFile (handle, name, (int) ZipStringComparison.CaseInsensitive) != 0) throw new Exception ("The file doesn't exist"); int method, compression; // '0' means do not open in raw mode (raw == do not decompress) if (unzOpenCurrentFile2 (handle, out method, out compression, 0) != 0) throw new Exception ("The file could not be opened"); level = ConvertCompression (method == 0 ? 0 : compression); }
public static unsafe int Read (UnzipHandle handle, byte[] buffer, int offset, int count) { if ((buffer.Length - offset) > count) throw new ArgumentOutOfRangeException ("count", "Buffer is too small to read that amount of data"); fixed (byte * b = &buffer[offset]) return unzReadCurrentFile (handle, b, (uint)count); }
static unsafe extern int unzReadCurrentFile(UnzipHandle handle, byte *buf, // voidp uint len);
static extern IntPtr unztell (UnzipHandle handle);
static extern int unzClose(UnzipHandle handle);
static extern int unzLocateFile (UnzipHandle handle, string szFileName, int iCaseSensitivity);
public static Dictionary<string, CompressionOption> GetFiles (UnzipHandle handle) { var result = new Dictionary<string, CompressionOption> (); GoToFirstFile (handle); Tuple<string, CompressionOption> info; while ((info = GetCurrentFileNameAndCompression(handle)) != null) { result.Add (info.Item1, info.Item2); if (!NativeUnzip.GoToNextFile (handle)) break; } return result; }
static extern int unzGetCurrentFileInfo (UnzipHandle handle, out UnzipFileInfo pfile_info, StringBuilder szFileName, IntPtr fileNameBufferSize, // uLong IntPtr extraField, // void * IntPtr extraFieldBufferSize, // uLong StringBuilder szComment, IntPtr commentBufferSize); // uLong
public static long CurrentFilePosition (UnzipHandle handle) { return unztell(handle).ToInt64 (); }
static extern int unzClose (UnzipHandle handle);
static void GoToFirstFile (UnzipHandle handle) { if (NativeUnzip.unzGoToFirstFile (handle) != 0) throw new Exception ("Zip file is invalid"); }
public static void CloseCurrentFile (UnzipHandle handle) { if (unzCloseCurrentFile (handle) != 0) throw new Exception ("Could not close the active file"); }
private static string[] GetFiles (UnzipHandle handle, Func<UnzipHandle, string> getCurrentFileName) { GoToFirstFile (handle); var files = new List<string> (); string name; while ((name = getCurrentFileName (handle)) != null) { files.Add (name); if (!NativeUnzip.GoToNextFile (handle)) break; } return files.ToArray (); }
public static void CloseArchive(UnzipHandle handle) { unzClose(handle); handle.SetHandleAsInvalid(); }
public static long CurrentFilePosition(UnzipHandle handle) { return(unztell(handle).ToInt64()); }
public static string[] GetFiles (UnzipHandle handle) { List<string> files = new List<string> (); GoToFirstFile (handle); string name; while ((name = GetCurrentFileName(handle)) != null) { files.Add (name); if (!NativeUnzip.GoToNextFile (handle)) break; } return files.ToArray (); }
public static string[] GetFiles64(UnzipHandle handle) { return(GetFiles(handle, GetCurrentFileName64)); }