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);