<commit_before>package pull

import (
	"fmt"
	"io"
	"net/http"
	"os"
	"path"

	"github.com/mitchellh/ioprogress"
)

// NewRelease creates a new Release instance
func NewRelease(cache string) *Release {
	return &Release{CacheDir: cache}
}

// Release is a BOSH release with a configurable cache dir
type Release struct {
	CacheDir string
}

// Pull downloads the specified Release to the local cache dir
func (s *Release) Pull(url string) (filename string, err error) {

	name := path.Base(url)
	filename = s.CacheDir + "/" + name

	if _, err = os.Stat(filename); os.IsNotExist(err) {
		fmt.Println("Could not find release in local cache. Downloading now.")
		var out *os.File
		out, err = os.Create(filename)
		if err != nil {
			return
		}
		var resp *http.Response
		resp, err = http.Get(url)
		if err != nil {
			return
		}
		defer func() {
			if cerr := resp.Body.Close(); cerr != nil {
				err = cerr
			}
		}()

		progressR := &ioprogress.Reader{
			Reader: resp.Body,
			Size:   resp.ContentLength,
		}
		_, err = io.Copy(out, progressR)
	}
	return
}
<commit_msg>Extract release download function<commit_after>package pull

import (
	"fmt"
	"io"
	"net/http"
	"os"
	"path"

	"github.com/mitchellh/ioprogress"
)

// NewRelease creates a new Release instance
func NewRelease(cache string) *Release {
	return &Release{CacheDir: cache}
}

// Release is a BOSH release with a configurable cache dir
type Release struct {
	CacheDir string
}

// Pull downloads the specified Release to the local cache dir
func (s *Release) Pull(url string) (filename string, err error) {
	name := path.Base(url)
	filename = s.CacheDir + "/" + name

	if _, err = os.Stat(filename); os.IsNotExist(err) {
		fmt.Println("Could not find release in local cache. Downloading now.")
		err = s.download(url, filename)
	}
	return
}

func (s *Release) download(url, local string) (err error) {
	var out *os.File
	out, err = os.Create(local)
	if err != nil {
		return
	}
	var resp *http.Response
	resp, err = http.Get(url)
	if err != nil {
		return
	}
	defer func() {
		if cerr := resp.Body.Close(); cerr != nil {
			err = cerr
		}
	}()

	progressR := &ioprogress.Reader{
		Reader: resp.Body,
		Size:   resp.ContentLength,
	}
	_, err = io.Copy(out, progressR)
	return
}

{'fraction_non_alphanumeric': 0.12806782686300758, 'fraction_numerical': 0.0, 'mean_word_length': 3.404715127701375, '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': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5174471', 'n_tokens_mistral': 839, 'n_tokens_neox': 791, 'n_words': 241}