codec/mjpeg/lex.go: return error if io.EOF is encountered

This commit is contained in:
Saxon 2020-01-17 16:07:37 +10:30
parent a26777b697
commit e45f51a31f
1 changed files with 2 additions and 8 deletions

View File

@ -63,10 +63,7 @@ func Lex(dst io.Writer, src io.Reader, delay time.Duration) error {
return nil return nil
} }
if err != nil { if err != nil {
if err == io.EOF { return fmt.Errorf("can't read source: %w", err)
return nil
}
return err
} }
if !bytes.Equal(buf, []byte{0xff, 0xd8}) { if !bytes.Equal(buf, []byte{0xff, 0xd8}) {
return fmt.Errorf("parser: not MJPEG frame start: %#v", buf) return fmt.Errorf("parser: not MJPEG frame start: %#v", buf)
@ -75,10 +72,7 @@ func Lex(dst io.Writer, src io.Reader, delay time.Duration) error {
for { for {
b, err := r.ReadByte() b, err := r.ReadByte()
if err != nil { if err != nil {
if err == io.EOF { return fmt.Errorf("can't read byte: %w", err)
return nil
}
return err
} }
buf = append(buf, b) buf = append(buf, b)
if last == 0xff && b == 0xd9 { if last == 0xff && b == 0xd9 {