Replacement for KMimeType::isBinaryData?

Milian Wolff mail at
Mon Jan 5 11:39:36 UTC 2015

On Sunday 04 January 2015 12:12:24 David Faure wrote:
> 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?
> > 
> > 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 :-)

In KDevelop, we support file/project templates. These are archives of files 
that may contain placeholders that will get replaced with user input when a 
file/project is created from a template. This replacement can only work on 
non-binary data, which is what the code checked in KDE4 times. In slightly 
abbreviated code:

AppWizardPlugin::copyFileAndExpandMacros(sourceFile, destFile)
  if (isBinaryData(source)) {
    KIO::copy(source, dest);
  } else {
    destFile << expandMacros(sourceFile);

You have more knowledge about mimetypes than us. Can we maybe just check 
whether the mimetype of sourceFile inherits text/plain?

Milian Wolff
mail at

More information about the Kde-frameworks-devel mailing list