From d428a8964adafc2503f9aa3c8f142c5d433bf965 Mon Sep 17 00:00:00 2001 From: Alex X Date: Fri, 17 May 2024 14:32:59 +0300 Subject: [PATCH] Fix writers for MJPEG and ASCII --- pkg/ascii/ascii.go | 8 +++++--- pkg/mjpeg/writer.go | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/pkg/ascii/ascii.go b/pkg/ascii/ascii.go index 986759cb..bb09b22a 100644 --- a/pkg/ascii/ascii.go +++ b/pkg/ascii/ascii.go @@ -136,11 +136,13 @@ func (a *writer) Write(p []byte) (n int, err error) { a.buf = append(a.buf, "\033[0m"...) - if n, err = a.wr.Write(a.buf); err == nil { - a.wr.(http.Flusher).Flush() + if _, err = a.wr.Write(a.buf); err != nil { + return 0, err } - return + a.wr.(http.Flusher).Flush() + + return len(p), nil } func gray(r, g, b uint32, k float32) uint8 { diff --git a/pkg/mjpeg/writer.go b/pkg/mjpeg/writer.go index c5393015..8845bf2c 100644 --- a/pkg/mjpeg/writer.go +++ b/pkg/mjpeg/writer.go @@ -28,9 +28,11 @@ func (w *writer) Write(p []byte) (n int, err error) { // Chrome bug: mjpeg image always shows the second to last image // https://bugs.chromium.org/p/chromium/issues/detail?id=527446 - if n, err = w.wr.Write(w.buf); err == nil { - w.wr.(http.Flusher).Flush() + if _, err = w.wr.Write(w.buf); err != nil { + return 0, err } - return + w.wr.(http.Flusher).Flush() + + return len(p), nil }