public function bufferGetType($buf, $filename = NULL)
{
if ($filename) {
$filename = basename($filename);
}
if ($filename) {
$r = $this->bufMagic($buf, 80);
if ($r) {
return $r;
}
$r = $this->literal($filename);
if ($r) {
return $r;
}
$r = $this->suffix($filename);
if ($r) {
return $r;
}
$r = $this->glob($filename);
if ($r) {
return $r;
}
$is_binary = $this->bufGuessBinary($buf);
/*
* Checking all magic signatures is a very expensive operation.
* We trade off some accuracy for faster text/plain recognition.
*/
if ($is_binary) {
$r = $this->bufMagic($buf, 0, 79);
if ($r) {
return $r;
}
}
} else {
$is_binary = $this->bufGuessBinary($buf);
if ($is_binary) {
$r = $this->bufMagic($buf);
} else {
$r = $this->bufMagic($buf, 80);
}
if ($r) {
return $r;
}
}
return $is_binary ? 'application/octet-stream' : 'text/plain';
}