Fix whatever ther fuck cursor cooked up
IDIOT
This commit is contained in:
66
main.go
66
main.go
@@ -7,7 +7,6 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
@@ -29,6 +28,12 @@ func init() {
|
|||||||
log.Lmicroseconds|log.Lshortfile)
|
log.Lmicroseconds|log.Lshortfile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ExtData struct {
|
||||||
|
ext string
|
||||||
|
binaryCount int
|
||||||
|
textCount int
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
dir := flag.Arg(0)
|
dir := flag.Arg(0)
|
||||||
@@ -58,16 +63,12 @@ func main() {
|
|||||||
scanner := bufio.NewScanner(f)
|
scanner := bufio.NewScanner(f)
|
||||||
if scanner.Scan() {
|
if scanner.Scan() {
|
||||||
ext := filepath.Ext(file)
|
ext := filepath.Ext(file)
|
||||||
key := ext
|
extData, _ := extensionTypeCount.LoadOrStore(ext, &ExtData{ext: ext, binaryCount: 0, textCount: 0})
|
||||||
if IsStringBinary(scanner.Text()) {
|
if IsStringBinary(scanner.Text()) {
|
||||||
key += " (binary)"
|
extData.(*ExtData).binaryCount++
|
||||||
count, _ := extensionTypeCount.LoadOrStore(key, 0)
|
|
||||||
extensionTypeCount.Store(key, count.(int)+1)
|
|
||||||
//log.Printf("Binary file: %s (%s)", file, ext)
|
//log.Printf("Binary file: %s (%s)", file, ext)
|
||||||
} else {
|
} else {
|
||||||
key += " (text)"
|
extData.(*ExtData).textCount++
|
||||||
count, _ := extensionTypeCount.LoadOrStore(key, 0)
|
|
||||||
extensionTypeCount.Store(key, count.(int)+1)
|
|
||||||
//log.Printf("Text file: %s (%s)", file, ext)
|
//log.Printf("Text file: %s (%s)", file, ext)
|
||||||
}
|
}
|
||||||
} else if err := scanner.Err(); err != nil {
|
} else if err := scanner.Err(); err != nil {
|
||||||
@@ -79,56 +80,13 @@ func main() {
|
|||||||
}
|
}
|
||||||
wg.Wait()
|
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 {
|
extensionTypeCount.Range(func(key, value any) bool {
|
||||||
keyStr := key.(string)
|
extData := value.(*ExtData)
|
||||||
count := value.(int)
|
if extData.binaryCount > extData.textCount*2 {
|
||||||
|
log.Printf("Extension: %s, Binary Count: %d, Text Count: %d", extData.ext, extData.binaryCount, extData.textCount)
|
||||||
// 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
|
|
||||||
}
|
}
|
||||||
return true
|
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 {
|
func IsStringBinary(s string) bool {
|
||||||
|
Reference in New Issue
Block a user