audio/vorbis: bug fix: an int16Stream with io.Reader didn't work

Closes #3192
This commit is contained in:
Hajime Hoshi 2025-02-11 14:44:47 +09:00
parent 6cdc2a693b
commit 4df5d02c36
2 changed files with 9 additions and 14 deletions

View File

@ -113,14 +113,7 @@ func (s *i16Stream) Read(b []byte) (int, error) {
s.i16Reader = newInt16BytesReaderFromFloat32Reader(s.vorbisReader)
}
l := s.totalBytes() - s.posInBytes
if l > int64(len(b)) {
l = int64(len(b))
}
if l < 0 {
return 0, io.EOF
}
l := int64(len(b))
retry:
n, err := s.i16Reader.Read(b[:l])
if err != nil && err != io.EOF {
@ -130,12 +123,8 @@ retry:
// When l is too small, decoder's Read might return 0 for a while. Let's retry.
goto retry
}
s.posInBytes += int64(n)
if s.posInBytes == s.totalBytes() || err == io.EOF {
return n, io.EOF
}
return n, nil
return n, err
}
func (s *i16Stream) Seek(offset int64, whence int) (int64, error) {

View File

@ -138,7 +138,13 @@ func TestNonSeeker(t *testing.T) {
t.Errorf("s.SampleRate(): got: %d, want: %d", got, want)
}
// TODO: Check the result of io.ReadAll (#3192).
buf, err := io.ReadAll(s)
if err != nil {
t.Errorf("io.ReadAll: %v", err)
}
if len(buf) == 0 {
t.Errorf("len(buf): got: %d, want: > 0", len(buf))
}
}
func TestNonSeekerF32(t *testing.T) {