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));
        }
示例#2
0
        public void SetFlags(MagicOpenFlags flags)
        {
            ThrowIfDisposed();

            if (MagicNative.magic_setflags(_magic, flags) < 0)
            {
                throw new MagicException("Utime/Utimes not supported.");
            }
        }
示例#3
0
 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);
     }
 }
示例#4
0
 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);
     }
 }
示例#5
0
        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.");
            }
        }
示例#6
0
 public static extern IntPtr magic_open(MagicOpenFlags flags);
示例#7
0
 public static extern int magic_setflags(IntPtr magic_cookie, MagicOpenFlags flags);
示例#8
0
 internal static extern IntPtr magic_open(MagicOpenFlags flags);