From 74ae761a498757d7377d4b8c7a761e8a670fa7a7 Mon Sep 17 00:00:00 2001 From: Yoshida Hiroshi <yoshida@shiguredo.jp> Date: Thu, 7 Nov 2024 12:54:17 +0900 Subject: [PATCH] =?UTF-8?q?reader=20=E5=8F=96=E5=BE=97=E7=AE=87=E6=89=80?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- handler.go | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/handler.go b/handler.go index d2dca31..f9675b1 100644 --- a/handler.go +++ b/handler.go @@ -351,30 +351,25 @@ func opus2ogg(ctx context.Context, opusReader io.Reader, oggWriter io.Writer, sa return err } + var r io.Reader + if c.AudioStreamingHeader { + r, err = readPacketWithHeader(opusReader) + if err != nil { + return err + } + } else { + r = opusReader + } + for { buf := make([]byte, FrameSize) var n int - if c.AudioStreamingHeader { - r, err := readPacketWithHeader(opusReader) - if err != nil { - return err - } - - n, err = r.Read(buf) - if err != nil { - if w, ok := oggWriter.(*io.PipeWriter); ok { - w.CloseWithError(err) - } - return err - } - } else { - n, err = opusReader.Read(buf) - if err != nil { - if w, ok := oggWriter.(*io.PipeWriter); ok { - w.CloseWithError(err) - } - return err + n, err = r.Read(buf) + if err != nil { + if w, ok := oggWriter.(*io.PipeWriter); ok { + w.CloseWithError(err) } + return err } if n > 0 {