<commit_before>// Copyright 2012 <NAME>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

import (
	"fmt"
	"io/ioutil"
	"log"
	"os"

	flag "github.com/ogier/pflag"
)

var (
	inFile  *string = flag.StringP("input", "i", "", "name of the input file")
	outFile *string = flag.StringP("output", "o", "", "name of the output file; defaults to stdout")
)

func usage() {
	fmt.Fprintf(os.Stderr, "usage: catbyte [options]\n")
	flag.PrintDefaults()
	os.Exit(2)
}

func main() {
	flag.Usage = usage
	flag.Parse()

	if flag.NFlag() == 0 {
		usage()
	}

	if *inFile == "" {
		log.Fatal("Enter an input file name")
	}

	rbytes, err := ioutil.ReadFile(*inFile)
	if err != nil {
		log.Fatal(err)
	}

	strbytes := fmt.Sprintf("%X", rbytes)

	if *outFile == "" {
		fmt.Fprintf(os.Stdout, strbytes+"\n")
		return
	}

	err = ioutil.WriteFile(*outFile, []byte(strbytes), 0600)
	if err != nil {
		log.Fatal(err)
	}
}
<commit_msg>Add base64, octal, binary support<commit_after>// Copyright 2012 <NAME>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

import (
	"bytes"
	"encoding/base64"
	"flag"
	"fmt"
	"io/ioutil"
	"log"
	"os"
)

var (
	inFile  *string = flag.String("input", "", "name of the input file")
	outFile *string = flag.String("output", "", "name of the output file; defaults to stdout")

	bin   *bool = flag.Bool("binary", false, "binary output")
	octal *bool = flag.Bool("octal", false, "octal output")
	hex   *bool = flag.Bool("hex", false, "hexadecimal output")
	b64   *bool = flag.Bool("base64", false, "base64 output")
)

func main() {
	flag.Parse()

	if flag.NFlag() == 0 {
		flag.Usage()
	}

	if *inFile == "" {
		log.Fatal("Enter an input file name")
	}

	readBytes, err := ioutil.ReadFile(*inFile)
	if err != nil {
		log.Fatal(err)
	}

	var outputBytes []byte
	switch {
	case *bin:
		var buf bytes.Buffer
		for b := range readBytes {
			buf.Write([]byte(fmt.Sprintf("%b", b)))
		}
		outputBytes = buf.Bytes()

	case *octal:
		var buf bytes.Buffer
		for b := range readBytes {
			buf.Write([]byte(fmt.Sprintf("%o", b)))
		}
		outputBytes = buf.Bytes()

	case *hex:
		outputBytes = []byte(fmt.Sprintf("%X", readBytes))

	case *b64:
		outputBytes = []byte(base64.StdEncoding.EncodeToString(readBytes))

	default:
		log.Fatal("Select an output format")
	}

	if *outFile == "" {
		os.Stdout.Write(outputBytes)
		os.Stdout.Write([]byte("\n"))
	} else {
		err = ioutil.WriteFile(*outFile, []byte(outputBytes), 0600)
		if err != nil {
			log.Fatal(err)
		}
	}
}

{'fraction_non_alphanumeric': 0.17134192570128887, 'fraction_numerical': 0.012509476876421531, 'mean_word_length': 3.5736568457538995, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2578548', 'n_tokens_mistral': 1065, 'n_tokens_neox': 985, 'n_words': 266}