func (s *Splice) Copy(dst io.Writer, src io.Reader) (n int64, err error) {
	s.Lock()
	defer s.Unlock()
	var (
		written int64
		srcFd   int
		dstFd   int
	)
	if f, ok := src.(FDer); !ok {
		filer, ok := src.(Filer)
		if !ok {
			return -1, ErrNoFD
		}
		f, err := filer.File()
		if err != nil {
			return -1, err
		}
		srcFd = int(f.Fd())
	} else {
		srcFd = int(f.Fd())
	}
	if fder, ok := dst.(FDer); ok {
		dstFd = int(fder.Fd())
	} else {
		filer, ok := dst.(Filer)
		if !ok {
			return -1, ErrNoFD
		}
		f, err := filer.File()
		if err != nil {
			return -1, err
		}
		dstFd = int(f.Fd())
	}
	for {
		w, err := spliceFct(srcFd, nil, s.pipe[1], nil, s.bufferSize, s.flags)
		if err != nil {
			return written, err
		}
		if w == 0 {
			break
		}
		w, err = spliceFct(s.pipe[0], nil, dstFd, nil, int(w), s.flags)
		if err != nil {
			return written + int64(w), err
		}
		written += int64(w)
	}
	return written, nil
}
Copy effectively perform the splice operation.
package gosplice
import (
	"errors"
	"io"
	"os"
	"sync"
	"syscall"
)
const (
	SpliceFMore     = 0x01
	SpliceFNonblock = 0x02
	SpliceFMove     = 0x03
)
var ErrNoFD = errors.New("The requested stream does not have Fd() method")
var (
	pipeFct   = syscall.Pipe
	spliceFct = syscall.Splice
)
type Splice struct {
	sync.Mutex
	pipe       []int
	bufferSize int
	flags      int
}
type Filer interface {
	File() (*os.File, error)
}
type FDer interface {
	Fd() uintptr
}
func (s *Splice) SetBufferSize(size int) {
	s.bufferSize = size
}
func (s *Splice) SetFlags(flags int) {
	s.flags = flags
}