]> git.djapps.eu Git - pkg/ggml/sources/whisper.cpp/commitdiff
go : handle EOF correctly in model download (#3671)
authorAlan <redacted>
Mon, 16 Mar 2026 11:44:18 +0000 (12:44 +0100)
committerGitHub <redacted>
Mon, 16 Mar 2026 11:44:18 +0000 (13:44 +0200)
bindings/go/examples/go-model-download/main.go

index 728c6df53d426e52531ee04e29d0fc3aec13cdf9..e72262eb7cbb33408b05bd9a1ec7d689d47aa366 100644 (file)
@@ -282,13 +282,20 @@ func Download(ctx context.Context, p io.Writer, model, out string) (string, erro
                default:
                        // Read body
                        n, err := resp.Body.Read(data)
+                       if n > 0 {
+                               if m, err := w.Write(data[:n]); err != nil {
+                                       return path, err
+                               } else {
+                                       count += int64(m)
+                               }
+                       }
+
                        if err != nil {
-                               DownloadReport(p, pct, count, resp.ContentLength)
-                               return path, err
-                       } else if m, err := w.Write(data[:n]); err != nil {
+                               if err == io.EOF {
+                                       DownloadReport(p, pct, count, resp.ContentLength)
+                                       return path, nil
+                               }
                                return path, err
-                       } else {
-                               count += int64(m)
                        }
                }
        }