refactor: downloadBody 문서화 개선

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-13 02:56:10 +09:00
parent 208b2d3189
commit e1d0e6fed0

View File

@@ -128,6 +128,7 @@ func formatProgress(pct int, speedBytesPerSec float64, remaining float64) string
// downloadBody 응답 본문을 tmpFile에 쓰고 진행률을 갱신한다. // downloadBody 응답 본문을 tmpFile에 쓰고 진행률을 갱신한다.
// downloaded는 이어받기 시작 오프셋, total은 전체 크기(미확정이면 0). // downloaded는 이어받기 시작 오프셋, total은 전체 크기(미확정이면 0).
// tmpPath는 크기 초과 시 파일 삭제에만 사용된다.
// 완료 또는 오류 시 tmpFile을 닫는다. // 완료 또는 오류 시 tmpFile을 닫는다.
func downloadBody(resp *http.Response, tmpFile *os.File, tmpPath string, downloaded, total int64) error { func downloadBody(resp *http.Response, tmpFile *os.File, tmpPath string, downloaded, total int64) error {
buf := make([]byte, 32*1024) buf := make([]byte, 32*1024)
@@ -154,6 +155,7 @@ func downloadBody(resp *http.Response, tmpFile *os.File, tmpPath string, downloa
return fmt.Errorf("다운로드 크기가 제한을 초과했습니다") return fmt.Errorf("다운로드 크기가 제한을 초과했습니다")
} }
// 500ms마다 속도 계산 및 진행률 갱신
now := time.Now() now := time.Now()
if now.Sub(lastSpeedUpdate) >= 500*time.Millisecond { if now.Sub(lastSpeedUpdate) >= 500*time.Millisecond {
elapsed := now.Sub(lastSpeedUpdate).Seconds() elapsed := now.Sub(lastSpeedUpdate).Seconds()