diff --git a/flac.go b/flac.go index 030090d..d96f53e 100644 --- a/flac.go +++ b/flac.go @@ -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) } diff --git a/flac_test.go b/flac_test.go index d373a4d..0783caf 100644 --- a/flac_test.go +++ b/flac_test.go @@ -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)