From 28902b9d11c9048b4f87ca591a84e7a5d656ee34 Mon Sep 17 00:00:00 2001 From: Hraban Luyat Date: Thu, 9 Jul 2015 12:28:38 +0000 Subject: [PATCH] Close readers if they implement io.Closer --- stream.go | 3 +++ stream_test.go | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) 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 */ +} -- 2.48.1