From: Hraban Luyat <hraban@0brg.net>
Date: Sat, 11 Jul 2015 05:59:28 +0000 (+0000)
Subject: Flush last good bytes before returning EOF
X-Git-Tag: v2.0.0~88
X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=22ae9de258a3252a974609e54dcce07e7c5d5d17;p=go-opus.git

Flush last good bytes before returning EOF
---

diff --git a/stream.go b/stream.go
index a59efb9..c73916f 100644
--- a/stream.go
+++ b/stream.go
@@ -31,7 +31,7 @@ func go_readproxy(p unsafe.Pointer, cbuf *C.uchar, cmaxbytes C.int) C.int {
 	// Don't bother cleaning up old data because that's not required by the
 	// io.Reader API.
 	n, err := stream.read.Read(stream.buf[:maxbytes])
-	if err != nil || n == 0 {
+	if (err != nil && err != io.EOF) || n == 0 {
 		return 0
 	}
 	C.memcpy(unsafe.Pointer(cbuf), unsafe.Pointer(&stream.buf[0]), C.size_t(n))
@@ -87,6 +87,10 @@ func (s *Stream) Init(read io.Reader) error {
 //
 // Read may successfully read less bytes than requested, but it will never read
 // exactly zero bytes succesfully if a non-zero buffer is supplied.
+//
+// The number of channels in the output data must be known in advance. It is
+// possible to extract this information from the stream itself, but I'm not
+// motivated to do that. Feel free to send a pull request.
 func (s *Stream) Read(pcm []int16) (int, error) {
 	if s.oggfile == nil {
 		return 0, fmt.Errorf("opus stream is uninitialized or already closed")