func (bw *BufferedWritev) Flush() (nw int, err error) {
	nw, err = bw.flush()
	return
}
Flush writes the contents of buffer to underlying file handle and resets buffer.
This must be called at the end of writing before closing the underlying file, or data will be lost.
package vectorio
import (
	"errors"
	"net"
	"os"
	"sync"
	"syscall"
)
const defaultBufSize = 1024
type BufferedWritev struct {
	buf  []syscall.Iovec
	Lock *sync.Mutex
	fd   uintptr
}
func NewBufferedWritev(targetIn interface{}) (bw *BufferedWritev, err error) {
	switch target := targetIn.(type) {
	case *net.TCPConn:
		var f *os.File
		f, err = target.File()
		if err != nil {
			return
		}
		bw, err = NewBufferedWritev(f)
	case *os.File:
		bw, err = NewBufferedWritev(uintptr(target.Fd()))
	case uintptr:
		bw = &BufferedWritev{buf: make([]syscall.Iovec, 0, defaultBufSize), Lock: new(sync.Mutex), fd: target}
	default:
		err = errors.New("NewBufferedWritev called with invalid type")
	}
	return
}
func (bw *BufferedWritev) Write(p []byte) (nw int, err error) {
	nw, err = bw.WriteIovec(syscall.Iovec{&p[0], uint64(len(p))})
	return
}
func (bw *BufferedWritev) WriteIovec(iov syscall.Iovec) (nw int, err error) {
	bw.buf = append(bw.buf, iov)
	if len(bw.buf) == cap(bw.buf) {
		nw, err = bw.flush()
	}
	return
}