<commit_before>// Copyright 2014 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

package backups

import (
	"bytes"
	"encoding/json"
	"io"
	"io/ioutil"
	"net/http"

	"github.com/juju/errors"

	"github.com/juju/juju/api/base"
	"github.com/juju/juju/apiserver/params"
)

// Download implements the API method.
func (c *Client) Download(id string) (io.ReadCloser, error) {
	// Initialize the HTTP request.
	req, err := c.http.NewHTTPRequest("GET", "backups")
	if err != nil {
		return nil, errors.Trace(err)
	}

	// Serialize the args.
	req.Header.Set("Content-Type", "application/json")
	args := params.BackupsDownloadArgs{
		ID: id,
	}
	data, err := json.Marshal(&args)
	if err != nil {
		return nil, errors.Annotate(err, "while serializing args")
	}
	req.Body = ioutil.NopCloser(bytes.NewBuffer(data))

	// Send the request.
	resp, err := c.http.SendHTTPRequest(req)
	if err != nil {
		return nil, errors.Annotate(err, "while sending HTTP request")
	}

	// Handle the response.
	if resp.StatusCode != http.StatusOK {
		return nil, errors.Trace(base.HandleHTTPFailure(resp))
	}

	return resp.Body, nil<commit_msg>HandleHTTPFailure -> CheckHTTPResponse.<commit_after>// Copyright 2014 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

package backups

import (
	"bytes"
	"encoding/json"
	"io"
	"io/ioutil"
	"net/http"

	"github.com/juju/errors"

	"github.com/juju/juju/api/base"
	"github.com/juju/juju/apiserver/params"
)

// Download implements the API method.
func (c *Client) Download(id string) (io.ReadCloser, error) {
	// Initialize the HTTP request.
	req, err := c.http.NewHTTPRequest("GET", "backups")
	if err != nil {
		return nil, errors.Trace(err)
	}

	// Serialize the args.
	req.Header.Set("Content-Type", "application/json")
	args := params.BackupsDownloadArgs{
		ID: id,
	}
	data, err := json.Marshal(&args)
	if err != nil {
		return nil, errors.Annotate(err, "while serializing args")
	}
	req.Body = ioutil.NopCloser(bytes.NewBuffer(data))

	// Send the request.
	resp, err := c.http.SendHTTPRequest(req)
	if err != nil {
		return nil, errors.Annotate(err, "while sending HTTP request")
	}

	// Handle the response.
	if resp.StatusCode != http.StatusOK {
		return nil, errors.Trace(base.CheckHTTPResponse(resp))
	}

	return resp.Body, nil
{'fraction_non_alphanumeric': 0.14527320034692107, 'fraction_numerical': 0.004336513443191674, 'mean_word_length': 3.8773784355179703, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6238059', 'n_tokens_mistral': 871, 'n_tokens_neox': 832, 'n_words': 204}