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));
        }
Exemplo n.º 2
0
        public void SetFlags(MagicOpenFlags flags)
        {
            ThrowIfDisposed();

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