finished tag implementation
This commit is contained in:
parent
b3b62af3a4
commit
c3076c328a
28 changed files with 396 additions and 296 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue