Replacement for KMimeType::isBinaryData?

David Faure faure at kde.org
Sun Jan 4 11:12:24 UTC 2015


On Wednesday 29 October 2014 00:30:04 Kevin Funk wrote:
> Heya,
> 
> I didn't find a suitable replacement for KMimeType::isBinaryData in KF5. Is
> there some?
> 
> http://lxr.kde.org/ident?v=kf5-qt5&_i=isBinaryData&_remember=1 shows exactly
> two users of this function.
> 
> Worth considering upstreaming to Qt?

Well, you tell me :)
Upstreaming requires providing use cases for it, so tell me what your use case 
is.

Looking at the implementation of the function, I fear that it is hard to prove 
that it's correct and useful.

It only checks the first 32 bytes of the file, so it's not like this could 
become a QByteArray method as I first thought when you talked about 
upstreaming it (e.g. QByteArray::isText(), isPrintable() or isBinaryData())

It would have to stay file-specific, i.e. in QMimeType.

Then, there are non-printable characters outside of the 0-31 range, so this 
method is rather "isBinaryData -> true means it is, false means we don't know, 
maybe it is". That makes me uneasy about the usefulness of the method.
It is there because XDG shared-mime-info specifies this is what we should 
fallback to, in the absence of a known extension or a known file content, to 
choose between a fallback to text/plain and a fallback to application/octet-
stream, but it's really an imperfect heuristic. I'm not sure we want more code 
depending on that imperfect heuristic, by making it public API again.

Which goes back to -- what's your use case for it :-)

-- 
David Faure, faure at kde.org, http://www.davidfaure.fr
Working on KDE Frameworks 5



More information about the Kde-frameworks-devel mailing list