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

package main 

import(
	"io/ioutil"
	"crypto/md5"
	"crypto/sha1"
	"fmt"
	"flag"
	"hash"
	"os"
)

func main() {
	inputFilePtr := flag.String("f", "", "path to the file to generate the hash for")
	inputHashPtr := flag.String("c", "", "the hash string to compare against")
	inputTypePtr := flag.String("t", "md5", "the hashing function to use (valid options are md5, sha1)")
	flag.Parse()

	// ensure a file has been entered.
	if len(*inputFilePtr) == 0 {
		fmt.Println("Need to enter a file to hash.")
		os.Exit(1)
	} 

	filepath := *inputFilePtr

	f,err := ioutil.ReadFile(filepath)
	if err != nil {
		fmt.Println("%s", err)
		os.Exit(2)
	}

	hashStr := *inputTypePtr

	hash := generateSum(hashStr)
	if hash == nil {
		fmt.Println("No such hashing function: ", hashStr)
		os.Exit(3)
	}
	hash.Write(f)

	sum := hash.Sum(nil)
	sumStr := fmt.Sprintf("%x", sum)

	if len(*inputHashPtr) != 0 {
		compareStr := *inputHashPtr
		if compareStr == sumStr {
			fmt.Println("They match!")
		} else {
			fmt.Println("They don't match!")
		}
		os.Exit(0)
	}

	fmt.Println(sumStr)
	os.Exit(0)
}

func generateSum(hashStr string) hash.Hash {
	switch {
		case hashStr == "md5":
			return md5.New()
		case hashStr == "sha1":
			return sha1.New()
	}
	return nil
}<commit_msg>Load file from stream, use log.Fatal() on error.<commit_after>// Copyright 2014 <NAME>. All rights reserved.  Use of this
// source code is governed by a MIT-style license that can be found in
// the LICENSE file.

package main

import(
    "io"
    "crypto/md5"
    "crypto/sha1"
    "fmt"
    "flag"
    "hash"
    "os"
    "log"
)

func main() {
    inputFilePtr := flag.String("f", "", "path to the file to generate the hash for")
    inputHashPtr := flag.String("c", "", "the hash string to compare against")
    inputTypePtr := flag.String("t", "md5", "the hashing function to use (valid options are md5, sha1)")
    flag.Parse()

    // ensure a file has been entered.
    if len(*inputFilePtr) == 0 {
        log.Fatal("Need to enter a file to hash.")
    }

    filepath := *inputFilePtr

    f,err := os.Open(filepath)
    if err != nil {
        log.Fatal(err)
    }
    defer f.Close()


    hashStr := *inputTypePtr

    hasher := generateSum(hashStr)
    if hasher == nil {
        log.Fatal("No such hashing function: ", hashStr)
    }

    _, err = io.Copy(hasher, f)

    if err != nil {
        log.Fatal(err)
    }

    sum := hasher.Sum(nil)
    sumStr := fmt.Sprintf("%x", sum)

    if len(*inputHashPtr) != 0 {
        compareStr := *inputHashPtr
        if compareStr == sumStr {
            fmt.Println("They match!")
        } else {
            fmt.Println("They don't match!")
        }
        os.Exit(0)
    }

    fmt.Println(sumStr)
    os.Exit(0)
}

func generateSum(hashStr string) hash.Hash {
    switch {
        case hashStr == "md5":
            return md5.New()
        case hashStr == "sha1":
            return sha1.New()
    }
    return nil
}
{'fraction_non_alphanumeric': 0.14612166076601224, 'fraction_numerical': 0.011908593498551657, 'mean_word_length': 2.6097560975609757, 'pattern_counts': {'":': 4, '<': 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': '5223570', 'n_tokens_mistral': 1145, 'n_tokens_neox': 1081, 'n_words': 314}