From: Hraban Luyat <hraban@0brg.net>
Date: Thu, 9 Jul 2015 12:28:38 +0000 (+0000)
Subject: Close readers if they implement io.Closer
X-Git-Tag: v2.0.0~94
X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=28902b9d11c9048b4f87ca591a84e7a5d656ee34;p=go-opus.git

Close readers if they implement io.Closer
---

diff --git a/stream.go b/stream.go
index 07a5743..70053df 100644
--- a/stream.go
+++ b/stream.go
@@ -131,5 +131,8 @@ func (s *Stream) Close() error {
 		return fmt.Errorf("opus stream is uninitialized or already closed")
 	}
 	C.op_free(s.oggfile)
+	if closer, ok := s.read.(io.Closer); ok {
+		return closer.Close()
+	}
 	return nil
 }
diff --git a/stream_test.go b/stream_test.go
index 08c07fd..f97089d 100644
--- a/stream_test.go
+++ b/stream_test.go
@@ -5,11 +5,12 @@
 package opus
 
 import (
+	"io"
 	"strings"
 	"testing"
 )
 
-func Test(t *testing.T) {
+func TestStream(t *testing.T) {
 	// Simple testing, no actual decoding
 	reader := strings.NewReader("hello")
 	_, err := NewStream(reader)
@@ -17,3 +18,7 @@ func Test(t *testing.T) {
 		t.Fatalf("Expected error while initializing illegal opus stream")
 	}
 }
+
+func TestCloser(t *testing.T) {
+	/* TODO: test if stream.Close() also closes the underlying reader */
+}