Fix whatever ther fuck cursor cooked up

IDIOT
This commit is contained in:
2025-03-08 11:09:31 +01:00
parent 3902b5dd0e
commit cc9b99b34c

66
main.go
View File

@@ -7,7 +7,6 @@ import (
"log"
"os"
"path/filepath"
"sort"
"strings"
"sync"
"sync/atomic"
@@ -29,6 +28,12 @@ func init() {
log.Lmicroseconds|log.Lshortfile)
}
type ExtData struct {
ext string
binaryCount int
textCount int
}
func main() {
flag.Parse()
dir := flag.Arg(0)
@@ -58,16 +63,12 @@ func main() {
scanner := bufio.NewScanner(f)
if scanner.Scan() {
ext := filepath.Ext(file)
key := ext
extData, _ := extensionTypeCount.LoadOrStore(ext, &ExtData{ext: ext, binaryCount: 0, textCount: 0})
if IsStringBinary(scanner.Text()) {
key += " (binary)"
count, _ := extensionTypeCount.LoadOrStore(key, 0)
extensionTypeCount.Store(key, count.(int)+1)
extData.(*ExtData).binaryCount++
//log.Printf("Binary file: %s (%s)", file, ext)
} else {
key += " (text)"
count, _ := extensionTypeCount.LoadOrStore(key, 0)
extensionTypeCount.Store(key, count.(int)+1)
extData.(*ExtData).textCount++
//log.Printf("Text file: %s (%s)", file, ext)
}
} else if err := scanner.Err(); err != nil {
@@ -79,56 +80,13 @@ func main() {
}
wg.Wait()
// Create a map to store raw extension names and their binary vs text counts
extensionBinaryTextCount := make(map[string][2]int)
// Collect all raw extensions and their counts
extensionTypeCount.Range(func(key, value any) bool {
keyStr := key.(string)
count := value.(int)
// Check if it's a text file (has " (text)" suffix)
if strings.HasSuffix(keyStr, " (text)") {
baseExt := strings.TrimSuffix(keyStr, " (text)")
counts, exists := extensionBinaryTextCount[baseExt]
if !exists {
counts = [2]int{0, 0}
}
counts[1] = count // index 1 for text count
extensionBinaryTextCount[baseExt] = counts
} else {
// Binary file
counts, exists := extensionBinaryTextCount[keyStr]
if !exists {
counts = [2]int{0, 0}
}
counts[0] = count // index 0 for binary count
extensionBinaryTextCount[keyStr] = counts
extData := value.(*ExtData)
if extData.binaryCount > extData.textCount*2 {
log.Printf("Extension: %s, Binary Count: %d, Text Count: %d", extData.ext, extData.binaryCount, extData.textCount)
}
return true
})
// Get all extensions that have more binary occurrences than text
var binaryDominantExts []string
for ext, counts := range extensionBinaryTextCount {
binaryCount := counts[0]
textCount := counts[1]
if binaryCount > textCount {
binaryDominantExts = append(binaryDominantExts, ext)
}
}
// Sort the extensions
sort.Strings(binaryDominantExts)
// Print only the extensions that are more likely to be binary
fmt.Println("Extensions that are predominantly binary:")
for _, ext := range binaryDominantExts {
counts := extensionBinaryTextCount[ext]
fmt.Printf("Extension: %s, Binary Count: %d, Text Count: %d\n",
ext, counts[0], counts[1])
}
}
func IsStringBinary(s string) bool {