On 30 October 2012, Larry Clapp said:
>
> Well, for reference, here's what it means to Perl:
>
> The "-T" and "-B" switches work as follows. The first block or so of the
> > file is examined for odd characters such as strange control codes or
> > characters with the high bit set. If too many strange characters (>30%)
> > are found, it's a "-B" file; otherwise it's a "-T" file. Also, any file
> > containing null in the first block is considered a binary file. If "-T" or
> > "-B" is used on a filehandle, the current IO buffer is examined rather than
> > the first block. Both "-T" and "-B" return true on a null file, or a file
> > at EOF when testing a filehandle. Because you have to read a file to do
> > the "-T" test, on most occasions you want to use a "-f" against the file
> > first, as in "next unless -f $file && -T $file".
There's more than one way to do it. For example, Mercurial's
definition of "binary" (for deciding how to display a diff) is
"contains at least one NUL byte (\0)". This has the advantage of being
dead simple to explain and implement, but it requires having the whole
file in memory. But since Mercurial always does this anyways, no big
deal. (After all, who would put a file into source control that
doesn't fit in memory -- that would be madness!)
(Yes, that last sentence was *irony*.)
IOW: make your own rule and implement it. I can't imagine Go adding a
fuzzy, might-work-most-of-the-time heuristic like this to the library.
Greg