private string GuessMagicInfo(Stream fileStream, MagicOpenFlags flag) { using var reader = new StreamReader(fileStream); var magic = new Magic(flag); var bufferSize = reader.BaseStream.Length >= 1024 ? 1024 : (int)reader.BaseStream.Length; return(magic.Read(reader.BaseStream, bufferSize)); }
public void SetFlags(MagicOpenFlags flags) { ThrowIfDisposed(); if (MagicNative.magic_setflags(_magic, flags) < 0) { throw new MagicException("Utime/Utimes not supported."); } }
public Magic(MagicOpenFlags flags, string dbPath = null) { _magic = MagicNative.magic_open(flags); if (_magic == IntPtr.Zero) { throw new MagicException("Cannot create magic cookie."); } if (MagicNative.magic_load(_magic, dbPath) != 0) { throw new MagicException(LastError); } }
public Magic(MagicOpenFlags flags, string dbPath = null) { _magic = MagicNative.magic_open(flags); if (_magic == IntPtr.Zero) { throw new Exception("Failed to initialize file type detection library: " + LastError); } if (MagicNative.magic_load(_magic, dbPath) != 0) { throw new Exception("File type detection database not found: " + LastError); } }
public Magic(MagicOpenFlags flags, string dbPath = null) { _magic = MagicNative.magic_open(flags); if (_magic == IntPtr.Zero) { throw new MagicException(LastError, "Cannot create magic cookie."); } if (dbPath == null) { dbPath = MagicUtils.GetDefaultMagicPath(); } if (MagicNative.magic_load(_magic, dbPath) != 0) { throw new MagicException(LastError, "Cannot load magic database file."); } }
public static extern IntPtr magic_open(MagicOpenFlags flags);
public static extern int magic_setflags(IntPtr magic_cookie, MagicOpenFlags flags);
internal static extern IntPtr magic_open(MagicOpenFlags flags);