For some reason calling -B with an in-memory filehandle doesn't work.
In lieu of that functionality I used a shoddy heuristic to look for
a line or two of printable characters.
}
sub is_binary {
- my($str) = @_;
- open my $fh, '<', \$str or return;
- return -B $fh;
+ # Crappy heuristic - does the first line or so look printable?
+ return $_[0] !~ /^[[:print:]]+$ (?: \s ^[[:print:]]+$ )?/mx;
}
1;