[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Extern libmagic output like command File?
[Thread Prev] | [Thread Next]
- Subject: Re: Extern libmagic output like command File?
- From: Bruce Steers <bsteers4@xxxxxxxxx>
- Date: Mon, 16 Sep 2024 14:43:08 +0100
- To: user@xxxxxxxxxxxxxxxxxxxxxx
Sorry i do not know the answer but is DesktopMime.FromFile not easier or usable in your case? Use "gb.desktop" Dim hMime As DesktopMime = DesktopMime.FromFile(sPath) Print hMime.Type If you need the "magic" properties then there is DesktopMime.Magic (i have no clue how to use it though) Respects BruceS On Mon, 16 Sept 2024 at 14:35, System64 Development <64xcode@xxxxxxxxx> wrote: > Hello > > Take the libmagic example from the Italian forum [1] to convert it into > a class that returns the file type. > > It works, more or less because it returns the file type [2] but not like > the file command does [3]. > > The question: Could someone tell me how to get the same output of the > file command but with libmagic? > > Regards. > > Martin. > > [1] > > https://www.gambas-it.org/wiki/index.php/Conoscere_il_mime-type_di_un_file_mediante_le_funzioni_esterne_del_API_di_libmagic > > [2] image/vnd.dwg; charset=binary > > [3] "DWG AutoDesk AutoCAD 2018/2019/2020" > > ' Gambas class file > > Export > > Library "libmagic:1" > > Private MAGIC_MIME_TYPE As Integer = &10 > Private MAGIC_MIME_ENCODING As Integer = &400 > Private MAGIC_MIME As Integer = MAGIC_MIME_TYPE Or MAGIC_MIME_ENCODING > > ' magic_t magic_open(int) > ' Creates a magic cookie pointer and returns it. > Private Extern magic_open(mg As Integer) As Pointer > > ' int magic_load(magic_t, const char *) > ' Loads the the colon separated list of database files passed in as file > name. > Private Extern magic_load(magic_t As Pointer, filename As String) As > Integer > > ' const char *magic_file(magic_t, const char *) > ' Returns a textual description of the contents of the file. > Private Extern magic_file(magic_t As Pointer, filename As String) As String > > ' void magic_close(magic_t) > ' Closes the magic database and deallocates any resources used. > Private Extern magic_close(magic_t As Pointer) > > Property Version As String > > Private $Version As String > > Private Function Version_Read() As String > > Return $Version > > End > > Private Sub Version_Write(Value As String) > > Dim magic As Pointer > Dim err As Integer > > If Exist(Value) Then > If Stat(Value).Type = gb.File Then > magic = magic_open(MAGIC_MIME) > If magic == 0 Then Error.Raise("Impossibile inizializzare la > libreria 'magic' !") > err = magic_load(magic, Null) > If err <> 0 Then > ChiudeMagic(magic) > Error.Raise("Impossibile caricare il database di 'magic' !") > Endif > $Version = magic_file(magic, Value) > ChiudeMagic(magic) > Endif > Endif > > End > > Private Procedure ChiudeMagic(mgc As Pointer) > > magic_close(mgc) > > End > > >
Re: Extern libmagic output like command File? | System64 Development <64xcode@xxxxxxxxx> |
Extern libmagic output like command File? | System64 Development <64xcode@xxxxxxxxx> |