Fix: drop dep + fix false pos with binary detection
This commit is contained in:
parent
f0cc0718ac
commit
7b90737eb7
3
putxt.go
3
putxt.go
|
@ -10,7 +10,6 @@ import (
|
|||
"time"
|
||||
|
||||
"git.tcp.direct/kayos/common/squish"
|
||||
"golang.org/x/tools/godoc/util"
|
||||
)
|
||||
|
||||
type Handler interface {
|
||||
|
@ -79,7 +78,7 @@ readLoop:
|
|||
return
|
||||
}
|
||||
}
|
||||
if !util.IsText(buf.Bytes()) {
|
||||
if !IsText(buf.Bytes()) {
|
||||
client.writeString(MessageBinaryData)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package putxt
|
||||
|
||||
import "unicode/utf8"
|
||||
|
||||
// slightly modified from golang.org/x/tools/godoc/util to include carriage return for dirty windows users
|
||||
func IsText(s []byte) bool {
|
||||
const max = 1024
|
||||
if len(s) > max {
|
||||
s = s[0:max]
|
||||
}
|
||||
for i, c := range string(s) {
|
||||
if i+utf8.UTFMax > len(s) {
|
||||
break
|
||||
}
|
||||
if c == 0xFFFD || c < ' ' && c != '\n' && c != '\t' && c != '\f' && c != '\r' {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
Loading…
Reference in New Issue