File tree Expand file tree Collapse file tree 1 file changed +13
-11
lines changed Expand file tree Collapse file tree 1 file changed +13
-11
lines changed Original file line number Diff line number Diff line change 44 "context"
55 "errors"
66 "fmt"
7+ "io"
78 "log/slog"
89 "sync"
910 "sync/atomic"
@@ -258,6 +259,9 @@ func (r *streamReader) Read(p []byte) (int, error) {
258259 if err != nil {
259260 return 0 , err
260261 }
262+ if len (msg .Data ) == 0 {
263+ return 0 , io .EOF
264+ }
261265 n := copy (p , msg .Data )
262266 r .buf = msg .Data [n :]
263267 return n , nil
@@ -270,18 +274,16 @@ func (r *streamReader) ReadByte() (byte, error) {
270274 r .buf = r .buf [1 :]
271275 return b , nil
272276 }
273- for {
274- slog .Debug ("receiving next byte chunk" )
275- msg , err := r .sub .NextMsgWithContext (r .ctx )
276- if err != nil {
277- return 0 , err
278- }
279- if len (msg .Data ) == 0 {
280- continue
281- }
282- r .buf = msg .Data [1 :]
283- return msg .Data [0 ], nil
277+ slog .Debug ("receiving next byte chunk" )
278+ msg , err := r .sub .NextMsgWithContext (r .ctx )
279+ if err != nil {
280+ return 0 , err
281+ }
282+ if len (msg .Data ) == 0 {
283+ return 0 , io .EOF
284284 }
285+ r .buf = msg .Data [1 :]
286+ return msg .Data [0 ], nil
285287}
286288
287289func (r * streamReader ) Close () (err error ) {
You can’t perform that action at this time.
0 commit comments