summaryrefslogtreecommitdiff
path: root/gopher/response.go
diff options
context:
space:
mode:
authortjp <tjp@ctrl-c.club>2023-11-13 07:25:39 -0700
committertjp <tjp@ctrl-c.club>2023-11-13 07:27:16 -0700
commit1e0f8e0aaeaf1bd2ee39c02e922238b641bcf88b (patch)
tree020e5de91f2343119fed10dede9d2c8262a3cd83 /gopher/response.go
parenta808b4692656c10bb43e2d54a2f5ef2746d231d5 (diff)
refactor contribs to work with a Protocol interface
Diffstat (limited to 'gopher/response.go')
-rw-r--r--gopher/response.go30
1 files changed, 2 insertions, 28 deletions
diff --git a/gopher/response.go b/gopher/response.go
index 269176f..3651e07 100644
--- a/gopher/response.go
+++ b/gopher/response.go
@@ -5,12 +5,11 @@ import (
"fmt"
"io"
"mime"
- "os"
"path"
"strings"
"sync"
- "unicode/utf8"
+ "tildegit.org/tjp/sliderule/internal"
"tildegit.org/tjp/sliderule/internal/types"
)
@@ -207,34 +206,9 @@ func GuessItemType(filepath string) types.Status {
return TextFileType
}
- if contentsAreText(filepath) {
+ if internal.ContentsAreText(filepath) {
return TextFileType
}
return BinaryFileType
}
-
-func contentsAreText(filepath string) bool {
- f, err := os.Open(filepath)
- if err != nil {
- return false
- }
- defer func() { _ = f.Close() }()
-
- var buf [1024]byte
- n, err := f.Read(buf[:])
- if err != nil {
- return false
- }
-
- for i, c := range string(buf[:n]) {
- if i+utf8.UTFMax > n {
- // incomplete last char
- break
- }
- if c == 0xFFFD || c < ' ' && c != '\n' && c != '\t' && c != '\f' {
- return false
- }
- }
- return true
-}