[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Fake PDF
[Thread Prev] | [Thread Next]
- Subject: Re: Fake PDF
- From: Benoît Minisini <benoit.minisini@xxxxxxxxxxxxxxxx>
- Date: Tue, 24 Feb 2026 21:21:18 +0100
- To: user@xxxxxxxxxxxxxxxxxxxxxx
Le 24/02/2026 à 21:03, gbWilly a écrit :
On Tuesday, February 24th, 2026 at 18:59, Lee <t.lee.davidson@xxxxxxxxx> wrote:That method queries the system mime type file at "/usr/share/mime/globs2" basically using it as a look-up table. On my system, line 139 in that file is "50:application/pdf:*.pdf". So according to that file, all files with a ".pdf" extension are of type "application/pdf". It is really stupid as it relies on the file extension as opposed to the file contents.Exactly, I'm glad you find it stupid as well. One of the first things I loved about coming to Linux was that file extensions didn't matter. The DesktopMime class is not reliable to return the TRUE MIME type of a file, but the FAKE one (that is true most of the time bit not always). The 'xdg-mime query file' equals the DesktopMine.FromFile output but on the command line level. Hence the screenshot to show the difference.Simplified, DesktopMime.FromFile() looks up the file extension in "/usr/share/mime/globs2", finds that it is of type "application/pdf", and returns that text. BTW, the Stat object created by the Stat() function will also falsely return "application/pdf" for that fake PDF file.
What are you talking about? The 'Stat' class never returns a file type.
The `file` command, on the other hand, will actually look at the header content of the file to determine its actual type.Yes, that is why I'm going back to my old function based on a simple EXEC of the file command, giving me the TRUE MIME type as demonstrated in my previous post screenshot. Maybe the core Gambas should have a function to return the TRUE MIME type of a file instead of relying on the gb.desktop component I wonder what Benoit has to say about this matter on 'TRUE' and 'FAKE' MIME type and a proper MIME type function?
What's the problem with using the 'file' command? I don't see the need of reimplementing the wheel if that command exists, unless there is a library that implements the same algorithm than 'file'. In that case it could be used through a Gambas API. Otherwise, just use the 'file' command directly.
Regards, -- Benoît Minisini.
| Re: Fake PDF | Lee <t.lee.davidson@xxxxxxxxx> |
| Fake PDF | Gianluigi <gradobag@xxxxxxxxxxx> |
| Re: Fake PDF | Lee <t.lee.davidson@xxxxxxxxx> |
| Re: Fake PDF | Gianluigi <gradobag@xxxxxxxxxxx> |
| Re: Fake PDF | Lee <t.lee.davidson@xxxxxxxxx> |
| Re: Fake PDF | gbWilly <gbWilly@xxxxxxxxxxxxxx> |