<commit_before>package main

import (
	"bufio"
	"flag"
	"fmt"
	"log"
	"os"
	"path/filepath"
)

var (
	aflag = flag.Bool("a", false, "Print entries for all files.")
	sflag = flag.Bool("s", false, "Print only a final summary.")
)

var (
	elog *log.Logger
	out  *bufio.Writer
)

func init() {
	elog = log.New(os.Stderr, "du: ", 0)
	flag.Usage = func() {
		fmt.Fprintln(os.Stderr, "Usage: du [options] [path ...]")
		flag.PrintDefaults()
	}
	flag.Parse()
	out = bufio.NewWriter(os.Stdout)
}

func main() {
	args := flag.Args()
	if len(args) == 0 {
		args = []string{"."}
	}
	for _, path := range args {
		du(path)
	}
	out.Flush()
}

func du(path string) {
	total := walk(path)
	if *sflag {
		fmt.Println(total)
	}
}

func walk(path string) int64 {
	fi, err := os.Lstat(path)
	if err != nil {
		elog.Print(err)
		return 0
	}
	var size int64
	if fi.IsDir() {
		f, err := os.Open(path)
		if err != nil {
			elog.Print(err)
			return 0
		}
		entries, err := f.Readdirnames(0)
		if err != nil {
			elog.Print(err)
			return 0
		}
		f.Close()
		for _, entry := range entries {
			size += walk(path + "/" + entry)
		}
	} else {
		size = (fi.Size() + 1023) / 1024
	}
	if !*sflag && (fi.IsDir() || *aflag) {
		print(path, size)
	}
	return size
}

func print(path string, size int64) {
	_, err := fmt.Fprintf(out, "%d\t%s\n", size, filepath.Clean(path))
	if err != nil {
		elog.Print(err)
	}
}<commit_msg>du: fix -s output; remove bufio<commit_after>package main

import (
	"flag"
	"fmt"
	"log"
	"os"
	"path/filepath"
)

var (
	aflag = flag.Bool("a", false, "Print entries for all files.")
	sflag = flag.Bool("s", false, "Print only a final summary.")
)

func init() {
	log.SetPrefix("du: ")
	log.SetFlags(0)
	flag.Usage = func() {
		fmt.Fprintln(os.Stderr, "Usage: du [options] [path ...]")
		flag.PrintDefaults()
	}
	flag.Parse()
}

func main() {
	args := flag.Args()
	if len(args) == 0 {
		args = []string{"."}
	}
	for _, path := range args {
		du(path)
	}
}

func du(path string) {
	total := walk(path)
	if *sflag {
		print(path, total)
	}
}

func walk(path string) int64 {
	fi, err := os.Lstat(path)
	if err != nil {
		log.Print(err)
		return 0
	}
	var size int64
	if fi.IsDir() {
		f, err := os.Open(path)
		if err != nil {
			log.Print(err)
			return 0
		}
		entries, err := f.Readdirnames(0)
		if err != nil {
			log.Print(err)
			return 0
		}
		f.Close()
		for _, entry := range entries {
			size += walk(path + "/" + entry)
		}
	} else {
		size = (fi.Size() + 1023) / 1024
	}
	if !*sflag && (fi.IsDir() || *aflag) {
		print(path, size)
	}
	return size
}

func print(path string, size int64) {
	fmt.Fprintf(os.Stdout, "%d\t%s\n", size, filepath.Clean(path))
}
{'fraction_non_alphanumeric': 0.18952524491333836, 'fraction_numerical': 0.015071590052750565, 'mean_word_length': 2.945022288261516, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3332148', 'n_tokens_mistral': 1227, 'n_tokens_neox': 1135, 'n_words': 274}