finished tag implementation

This commit is contained in:
ston1th 2019-08-24 14:27:58 +02:00
commit c3076c328a
28 changed files with 396 additions and 296 deletions

View file

@ -3,10 +3,35 @@
package scan
import (
"net/http"
"os"
"path/filepath"
"strings"
)
const (
pdfContentType = "application/pdf"
maxSniffSize = 512
)
func isPDF(path string) bool {
return checkContentType(path) || checkExtension(path)
}
func checkContentType(path string) bool {
f, err := os.Open(path)
if err != nil {
return false
}
defer f.Close()
buf := make([]byte, maxSniffSize)
_, err = f.Read(buf)
if err != nil {
return false
}
return http.DetectContentType(buf) == pdfContentType
}
func checkExtension(path string) bool {
return strings.ToLower(filepath.Ext(path)) == pdfExt
}

View file

@ -76,6 +76,7 @@ func New(c core.Config) (s *Scanner, err error) {
langs := c.Langs
if langs == nil || llen == 0 {
langs = defaultLangs
llen = len(langs)
}
for i, l := range langs {
lang += l