]> Sergey Matveev's repositories - meta4ra.git/commitdiff
Take Content-Length is no -size is specified
authorSergey Matveev <stargrave@stargrave.org>
Fri, 27 Feb 2026 08:56:11 +0000 (11:56 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Fri, 27 Feb 2026 08:56:11 +0000 (11:56 +0300)
cmd/dl.go

index 3f41275991d6180713dadbf4d276eb61d27e8a18..409769007579cc1572a1f529da1df6c07f529299 100644 (file)
--- a/cmd/dl.go
+++ b/cmd/dl.go
@@ -64,9 +64,17 @@ func runDl() {
        if resp.StatusCode != http.StatusOK {
                log.Fatalln("status code:", resp.Status)
        }
+       var sizeExpected uint64
+       if *size == 0 {
+               if resp.ContentLength > 0 {
+                       sizeExpected = uint64(resp.ContentLength)
+               }
+       } else {
+               sizeExpected = uint64(*size)
+       }
        var w io.Writer
        if *progress {
-               bar := Progress{w: os.Stdout, now: time.Now(), total: uint64(*size)}
+               bar := Progress{w: os.Stdout, now: time.Now(), total: sizeExpected}
                bar.next = bar.now.Add(ProgressPeriod)
                w = &bar
        } else {