mirror of
https://github.com/asticode/go-astiav.git
synced 2025-10-05 16:16:50 +08:00
Support for io.EOF to C.AVERROR_EOF mapping (#73)
* Support for io.EOF to C.AVERROR_EOF mapping * Requested changes
This commit is contained in:
@@ -6,6 +6,7 @@ import "C"
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"sync"
|
"sync"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
@@ -241,6 +242,8 @@ func goAstiavIOContextReadFunc(opaque unsafe.Pointer, buf *C.uint8_t, bufSize C.
|
|||||||
var e Error
|
var e Error
|
||||||
if errors.As(err, &e) {
|
if errors.As(err, &e) {
|
||||||
return C.int(e)
|
return C.int(e)
|
||||||
|
} else if errors.Is(err, io.EOF) {
|
||||||
|
return C.AVERROR_EOF
|
||||||
}
|
}
|
||||||
return C.AVERROR_UNKNOWN
|
return C.AVERROR_UNKNOWN
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package astiav
|
package astiav
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -9,6 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestIOContext(t *testing.T) {
|
func TestIOContext(t *testing.T) {
|
||||||
|
t.Run("read write seek", func(t *testing.T) {
|
||||||
var seeked bool
|
var seeked bool
|
||||||
rb := []byte("read")
|
rb := []byte("read")
|
||||||
wb := []byte("write")
|
wb := []byte("write")
|
||||||
@@ -37,6 +39,19 @@ func TestIOContext(t *testing.T) {
|
|||||||
c.Write(wb)
|
c.Write(wb)
|
||||||
c.Flush()
|
c.Flush()
|
||||||
require.Equal(t, wb, written)
|
require.Equal(t, wb, written)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("io.EOF is mapped to AVERROR_EOF when reading", func(t *testing.T) {
|
||||||
|
c, err := AllocIOContext(8, false, func(b []byte) (int, error) {
|
||||||
|
return 0, io.EOF
|
||||||
|
}, nil, nil)
|
||||||
|
require.NoError(t, err)
|
||||||
|
defer c.Free()
|
||||||
|
b := make([]byte, 100)
|
||||||
|
n, err := c.Read(b)
|
||||||
|
require.ErrorIs(t, err, ErrEof)
|
||||||
|
require.Equal(t, 0, n)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOpenIOContext(t *testing.T) {
|
func TestOpenIOContext(t *testing.T) {
|
||||||
|
Reference in New Issue
Block a user