[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fake PDF


The gambas function just use the extension part of the mime to simplify and
accelerate the recognition of the type.
Using the magic string is more complicated as it need to read each file
content.

It can be done but need more work and might slow the recognition.


Fabien Bodard

Le mer. 25 févr. 2026, 00:55, Gianluigi <gradobag@xxxxxxxxxxx> a écrit :

> Il 24/02/26 22:22, Lee ha scritto:
> > On 2/24/26 3:21 PM, Benoît Minisini wrote:
> >> Le 24/02/2026 à 21:03, gbWilly a écrit :
> >>>
> >>> On Tuesday, February 24th, 2026 at 18:59, Lee
> >>> <t.lee.davidson@xxxxxxxxx> wrote:
> >>>>
> > [snip]
> >>>
> >>>> 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.
> >
> > I was talking rubbish. You are correct. I had added code to Gianluigi's
> > project to print the Stat.Type of the file but failed to distinguish his
> > output from mine.
> >
> >
> > [snip]
> >>> 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.
> >
> > The MicroHttpd project I created some time ago uses "libmagic" (see `man
> > 3 libmagic`) to get the real mime-type of a file. I extracted the
> > implementing code from that project and added it to Gianluigi's FakePDF
> > project. Demo attached.
> >
> >
>
> Hi everyone,
>
> Sorry for the delay in responding (Netflix night) :-)
> Thank you for all the feedback, and I've followed your suggestion and
> attached the results.
>
> @Lee, thanks, but your library doesn't seem to work here. This is the
> console output:
> Fake mime-type: application/pdf
> Real mime-type: Ïh^^
>
> Thanks again, I'm off to sleep now.
>
> Good night
> Gianluigi
>

Follow-Ups:
Re: Fake PDFBruce Steers <bsteers4@xxxxxxxxx>
Re: Fake PDFGianluigi <gradobag@xxxxxxxxxxx>
References:
Fake PDFGianluigi <gradobag@xxxxxxxxxxx>
Re: Fake PDFLee <t.lee.davidson@xxxxxxxxx>
Re: Fake PDFGianluigi <gradobag@xxxxxxxxxxx>
Re: Fake PDFLee <t.lee.davidson@xxxxxxxxx>
Re: Fake PDFgbWilly <gbWilly@xxxxxxxxxxxxxx>
Re: Fake PDFBenoît Minisini <benoit.minisini@xxxxxxxxxxxxxxxx>
Re: Fake PDFLee <t.lee.davidson@xxxxxxxxx>
Re: Fake PDFGianluigi <gradobag@xxxxxxxxxxx>