]> Sergey Matveev's repositories - go-opus.git/commitdiff
Close readers if they implement io.Closer
authorHraban Luyat <hraban@0brg.net>
Thu, 9 Jul 2015 12:28:38 +0000 (12:28 +0000)
committerHraban Luyat <hraban@0brg.net>
Thu, 9 Jul 2015 12:28:38 +0000 (12:28 +0000)
stream.go
stream_test.go

index 07a57435b2d99112471251da673f379d92774930..70053df5c796797a5fcf898c14eeac5111b30409 100644 (file)
--- 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
 }
index 08c07fde8c4eb31f5cae58b84799498328cf54f6..f97089d1456bd6a21947e54ece255071b18e6f78 100644 (file)
@@ -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 */
+}