From 73cd0e435d323d643b181867533dc214e24d3679 Mon Sep 17 00:00:00 2001 From: Craig Swank Date: Mon, 26 Feb 2018 11:43:09 -0700 Subject: [PATCH 1/2] Add Position and Len for flac d.stream.Info.NSamples is uint64 so calling int() on it could result in an overflow. I have no idea how likely that is, but if it happens then Position() will return -1. --- flac/decode.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/flac/decode.go b/flac/decode.go index 61422f6..eff378e 100644 --- a/flac/decode.go +++ b/flac/decode.go @@ -41,6 +41,7 @@ type decoder struct { rc io.ReadCloser stream *flac.Stream buf [][2]float64 + pos int err error } @@ -64,6 +65,7 @@ func (d *decoder) Stream(samples [][2]float64) (n int, ok bool) { n++ } d.buf = d.buf[j:] + d.pos += n return n, true } @@ -128,11 +130,11 @@ func (d *decoder) Err() error { } func (d *decoder) Len() int { - panic("not yet implemented") + return int(d.stream.Info.NSamples) } func (d *decoder) Position() int { - panic("not yet implemented") + return d.pos } func (d *decoder) Seek(p int) error { From 7bb960101a4bdb18e46a1b479a31ca84299d583d Mon Sep 17 00:00:00 2001 From: Craig Swank Date: Mon, 26 Feb 2018 17:13:04 -0700 Subject: [PATCH 2/2] update flac.pos on EOF error --- flac/decode.go | 1 + 1 file changed, 1 insertion(+) diff --git a/flac/decode.go b/flac/decode.go index eff378e..081d86b 100644 --- a/flac/decode.go +++ b/flac/decode.go @@ -56,6 +56,7 @@ func (d *decoder) Stream(samples [][2]float64) (n int, ok bool) { // refill buffer. if err := d.refill(); err != nil { d.err = err + d.pos += n return n, n > 0 } j = 0