<commit_before>package s3resource

import (
	"fmt"
	"io"
	"os"
	"time"

	"github.com/concourse/s3gof3r"
	"github.com/mitchellh/goamz/aws"
	"github.com/mitchellh/goamz/s3"
)

//go:generate counterfeiter . S3Client

type S3Client interface {
	BucketFiles(bucketName string, prefixHint string) ([]string, error)

	UploadFile(bucketName string, remotePath string, localPath string) error
	DownloadFile(bucketName string, remotePath string, localPath string) error

	URL(bucketName string, remotePath string, private bool) string
}

type s3client struct {
	client       *s3.S3
	gopherClient *s3gof3r.S3
}

func NewS3Client(accessKey string, secretKey string, regionName string) (S3Client, error) {
	auth := aws.Auth{
		AccessKey: accessKey,
		SecretKey: secretKey,
	}

	authGopher := s3gof3r.Keys{
		AccessKey: accessKey,
		SecretKey: secretKey,
	}

	region, ok := aws.Regions[regionName]
	if !ok {
		return nil, fmt.Errorf("No such region '%s'", regionName)
	}

	return &s3client{
		client:       s3.New(auth, region),
		gopherClient: s3gof3r.New("", authGopher),
	}, nil
}

func (client *s3client) BucketFiles(bucketName string, prefixHint string) ([]string, error) {
	bucket := client.client.Bucket(bucketName)
	entries, err := client.getBucketContents(bucket, prefixHint)
	if err != nil {
		return []string{}, err
	}

	paths := make([]string, 0, len(*entries))<commit_msg>default region to us-east-1<commit_after>package s3resource

import (
	"fmt"
	"io"
	"os"
	"time"

	"github.com/concourse/s3gof3r"
	"github.com/mitchellh/goamz/aws"
	"github.com/mitchellh/goamz/s3"
)

//go:generate counterfeiter . S3Client

type S3Client interface {
	BucketFiles(bucketName string, prefixHint string) ([]string, error)

	UploadFile(bucketName string, remotePath string, localPath string) error
	DownloadFile(bucketName string, remotePath string, localPath string) error

	URL(bucketName string, remotePath string, private bool) string
}

type s3client struct {
	client       *s3.S3
	gopherClient *s3gof3r.S3
}

func NewS3Client(accessKey string, secretKey string, regionName string) (S3Client, error) {
	auth := aws.Auth{
		AccessKey: accessKey,
		SecretKey: secretKey,
	}

	authGopher := s3gof3r.Keys{
		AccessKey: accessKey,
		SecretKey: secretKey,
	}

	if len(regionName) == 0 {
		regionName = aws.USEast.Name
	}

	region, ok := aws.Regions[regionName]
	if !ok {
		return nil, fmt.Errorf("No such region '%s'", regionName)
	}

	return &s3client{
		client:       s3.New(auth, region),
		gopherClient: s3gof3r.New("", authGopher),
	}, nil
}

func (client *s3client) BucketFiles(bucketName string, prefixHint string) ([]string, error) {
	bucket := client.client.Bucket(bucketName)
	entries, err := client.getBucketContents(bucket, prefixHint)
	if err != nil {
		return []string{}, err
	}

	paths := make([]string, 0, len(*entries))
{'fraction_non_alphanumeric': 0.12526614620298085, 'fraction_numerical': 0.016323633782824698, 'mean_word_length': 4.776639344262295, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5468174', 'n_tokens_mistral': 1042, 'n_tokens_neox': 1013, 'n_words': 241}