schollz / schollz/progressbar

Progress bar moves down during download process

Open
#165 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
4.7k
Forks
258
Avg merge
13h 31m
Merged PRs (30d)
1

Description

Progress bar moves down during download process
package main

import (
	"archive/zip"
	"bytes"
	"fmt"
	"github.com/debfig/bindview-cli/Tools"
	"github.com/schollz/progressbar/v3"
	"io"
	"net/http"
)

// DownloadUrl 下载地址
var DownloadUrl string = "https://github.com/bronze-ding/bindview-Template/archive/refs/heads/master.zip"

// DownloadFile 文件缓存区
var DownloadFile bytes.Buffer

func main() {

	// 获取命令行输入
	state, str := Tools.GetCmd()
	if state != 1 {
		return
	}

	req, _ := http.NewRequest("GET", DownloadUrl, nil)
	resp, _ := http.DefaultClient.Do(req)
	defer resp.Body.Close()

	bar := progressbar.DefaultBytes(
		resp.ContentLength,
		"正在下载模板压缩包 (.zip)",
	)

	io.Copy(io.MultiWriter(&DownloadFile, bar), resp.Body)

	ZipData, err := io.ReadAll(&DownloadFile)
	if err != nil {
		fmt.Println(err)
		return
	}

	ZipReader, _ := zip.NewReader(bytes.NewReader(ZipData), int64(len(ZipData)))

	// 解 .zip 压缩
	if err = Tools.Unzip("", ZipReader); err != nil {
		fmt.Println(err)
		return
	}

	// 文件重命名
	Tools.NewFileName(&str)

	// 输出命令提示
	Tools.CommandList(str)
}

屏幕截图 2023-08-13 111610

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the report with the supplied Go example, starting at progressbar.DefaultBytes and the io.MultiWriter download path. Trace how progress updates are rendered during the download and use the screenshot and reported symptom to define done: the progress bar should remain in its intended position instead of moving down.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.