from . import ffi
from . import flags

__version__ = "0.2.0"


class Magic(object):

  def __init__(self, mime=False, debug=False, database=None):
    initial_flags = flags.MAGIC_NONE
    if mime:
      initial_flags |= flags.MAGIC_MIME_TYPE
    if debug:
      initial_flags |= flags.MAGIC_DEBUG
    cookie = ffi.open(initial_flags)
    if database:
      ffi.load(cookie, database)
    else:
      ffi.load(cookie)
    self.cookie = cookie

  def __del__(self):
    try:
      ffi.close(self.cookie)
    except Exception as exception:
      raise

  @property
  def version(self):
    return ffi.version()

  def set_flags(self):
    return ffi.set_flags(self.cookie, flags)

  def handle_bytes(function):
    def wrapper(self, value):
      if not isinstance(value, bytes):
        value = value.encode("utf-8")
      response = function(self, value)
      return response.decode("utf-8")
    return wrapper

  @handle_bytes
  def from_file(self, filepath):
    return ffi.file(self.cookie, filepath)

  @handle_bytes
  def from_buffer(self, value):
    return ffi.buffer(self.cookie, value)

@@ -99,19 +99,51 @@
 _(self, 
-mim
+database=None, debug=False, mimetyp
 e=False,
@@ -143,28 +143,31 @@
 =False, 
-debu
+encodin
 g=False,
  databas
@@ -158,29 +158,74 @@
 g=False,
- database=Non
+%0A                     compress=False, follow_symlinks=Fals
 e):%0A    
@@ -231,23 +231,65 @@
  initial
-_
+ = 
 flags
- 
+.MAGIC_NONE%0A    if debug:%0A      initial %7C
 = flags.
@@ -286,36 +286,37 @@
  %7C= flags.MAGIC_
-NONE
+DEBUG
 %0A    if mime:%0A  
@@ -311,18 +311,43 @@
  if mime
+type
 :%0A
+      if encoding:%0A  
       in
@@ -343,38 +343,80 @@
 %0A        initial
-_
+ %7C= 
 flags
+.MAGIC_MIME%0A      else:%0A        initial
  %7C= flags.MAGIC_
@@ -424,37 +424,40 @@
 IME_TYPE%0A    if 
-debug
+compress
 :%0A      initial_
@@ -455,22 +455,78 @@
  initial
-_
+ %7C= 
 flags
+.MAGIC_COMPRESS%0A    if follow_symlinks:%0A      initial
  %7C= flag
@@ -529,29 +529,31 @@
 flags.MAGIC_
-DEBUG
+SYMLINK
 %0A    cookie 
@@ -570,22 +570,16 @@
 (initial
-_flags
 )%0A    if
@@ -863,24 +863,31 @@
 t_flags(self
+, flags
 ):%0A    retur

Add some love