You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: download-with-progressbar.go
    path of file: ./repos/pterm/putils
    
    the code of the file until where you have to start completion: package putils

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

	"github.com/pterm/pterm"
)

// progressbarWriter counts the number of bytes written to it and adds those to a progressbar.
type progressbarWriter struct {
	Total uint64
	pb    *pterm.ProgressbarPrinter
}

func (w *progressbarWriter) Write(p []byte) (int, error) {
	n := len(p)
	w.Total += uint64(n)
	w.pb.Add(len(p))
	re
    
func DownloadFileWithProgressbar(progressbar *pterm.ProgressbarPrinter, outputPath, url string, mode os.FileMode) error {
	path := filepath.Clean(outputPath)
	out, err := os.Create(path)
	if err != nil {
		return fmt.Errorf("could not create download path: %w", err)
	}

	resp, err := http.Get(url) //nolint:gosec
	if err != nil {
		out.Close()
		return fmt.Errorf("error while downloading file: %w", err)
	}
	defer resp.Body.Close()

	counter := &progressbarWriter{}
	fileSize, err := strconv.Atoi(resp.Header.Get("Content-Length"))
	if err != nil {
		return fmt.Errorf("could not determine file size: %w", err)
	}

	counter.pb, _ = progressbar.WithTotal(fileSize).Start()
	if _, err = io.Copy(out, io.TeeReader(resp.Body, counter)); err != nil {
		out.Close()
		return err
	}

	err = os.Chmod(path, mode)
	if err != nil {
		return fmt.Errorf("could not chmod file: %w", err)
	}

	out.Close()
	return nil
}