Skip to content

Commit

Permalink
Fix seek to end of stream (#73)
Browse files Browse the repository at this point in the history
* Add Seek testdata & fix out-of-range check

Contains one fixed & one still failing test.

* Comment out still failing testcase

* flac: use upper case for TODO for consistency with other comments

---------

Co-authored-by: Robin <mewmew@users.noreply.github.com>
  • Loading branch information
MarkKremer and mewmew authored Aug 11, 2024
1 parent fc83e3f commit 2c1c29d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion flac.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ func (stream *Stream) Seek(sampleNum uint64) (uint64, error) {

rs := stream.r.(io.ReadSeeker)

isBiggerThanStream := stream.Info.NSamples != 0 && sampleNum > stream.Info.NSamples
isBiggerThanStream := stream.Info.NSamples != 0 && sampleNum >= stream.Info.NSamples
if isBiggerThanStream || sampleNum < 0 {
return 0, fmt.Errorf("unable to seek to sample number %d", sampleNum)
}
Expand Down
2 changes: 2 additions & 0 deletions flac_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ func TestSeek(t *testing.T) {
{seek: 100, expected: 0},
{seek: 8192, expected: 8192},
{seek: 8191, expected: 4096},
//{seek: 40960 + 2723 - 1, expected: 40960}, // last sample // TODO: re-enable when it works. See https://github.com/mewkiz/flac/pull/73
{seek: 40960 + 2723, expected: 0, err: "unable to seek to sample number 43683"}, // one after last sample
}

stream, err := flac.NewSeek(f)
Expand Down

0 comments on commit 2c1c29d

Please sign in to comment.