From 2c1c29d99732866c0c87a863c0892089bafc16e2 Mon Sep 17 00:00:00 2001 From: Mark Kremer Date: Sun, 11 Aug 2024 21:46:04 +0200 Subject: [PATCH] Fix seek to end of stream (#73) * 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 --- flac.go | 2 +- flac_test.go | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) 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)