<commit_before>package glacier

import (
	"github.com/rdwilliamson/aws"
	"net/http"
)

var (
	defaultClient http.Client
)

// A Connection stores and reuses a connection to an Amazon region for a user.
type Connection struct {
	Client    http.Client
	Signature *aws.Signature
}

func NewConnection(secret, access string, r *aws.Region) *Connection {
	// TODO a go routine to create a new signature when the date changes?
	return &Connection{defaultClient, aws.NewSignature(secret, access,
		r, "glacier")}
}

// TODO method to log things such as x-amzn-RequestId

func toHex(x []byte) []byte {
	hex := "0123456789abcdef"
	z := make([]byte, 2*len(x))
	for i, v := range x {
		z[2*i] = hex[(v&0xf0)>>4]
		z[2*i+1] = hex[v&0x0f]
	}
	return z
}
<commit_msg>Reading and writing of a tree hash while I plan how to handle multipart uploads.<commit_after>package glacier

import (
	"encoding/gob"
	"fmt"
	"github.com/rdwilliamson/aws"
	"io"
	"net/http"
)

var (
	defaultClient http.Client
)

// A Connection stores and reuses a connection to an Amazon region for a user.
type Connection struct {
	Client    http.Client
	Signature *aws.Signature
}

func NewConnection(secret, access string, r *aws.Region) *Connection {
	// TODO a go routine to create a new signature when the date changes?
	return &Connection{defaultClient, aws.NewSignature(secret, access,
		r, "glacier")}
}

func CreateTreeHash(r io.Reader, w io.Writer) error {
	th, err := createTreeHash(r)
	if err != nil {
		return err
	}
	printTreeHash(th, 0)

	enc := gob.NewEncoder(w)
	err = enc.Encode(th)
	if err != nil {
		return err
	}

	return nil
}

func ReadTreeHash(r io.Reader) error {
	dec := gob.NewDecoder(r)
	var th treeHash
	err := dec.Decode(&th)
	if err != nil {
		return err
	}
	printTreeHash(&th, 0)
	return nil
}

func printTreeHash(th *treeHash, level int) {
	if th.Left == nil && th.Right == nil {
		fmt.Println("leaf", string(toHex(th.Hash[:])))
	} else {
		fmt.Println(level, string(toHex(th.Hash[:])))
		level++
		printTreeHash(th.Left, level)
		printTreeHash(th.Right, level)
	}
}

// TODO method to log things such as x-amzn-RequestId

func toHex(x []byte) []byte {
	hex := "0123456789abcdef"
	z := make([]byte, 2*len(x))
	for i, v := range x {
		z[2*i] = hex[(v&0xf0)>>4]
		z[2*i+1] = hex[v&0x0f]
	}
	return z
}

{'fraction_non_alphanumeric': 0.137117903930131, 'fraction_numerical': 0.017467248908296942, 'mean_word_length': 3.8952991452991452, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '7442367', 'n_tokens_mistral': 894, 'n_tokens_neox': 860, 'n_words': 250}