func (es *EventStream) Flush(sync bool) {
	if sync {
		C.FSEventStreamFlushSync(es.stream)
	} else {
		C.FSEventStreamFlushAsync(es.stream)
	}
}
Flush events that have occurred but haven't been delivered.
package fsevents
import "C"
import (
	"path/filepath"
	"runtime"
	"sync"
	"syscall"
	"time"
	"unsafe"
)
const EventIDSinceNow = uint64(C.kFSEventStreamEventIdSinceNow + (1 << 64))
type CreateFlags uint32
const (
	useCFTypes CreateFlags = 1 << iota
	NoDefer
	WatchRoot
	IgnoreSelf
	FileEvents
)
type EventFlags uint32
const (
	MustScanSubDirs EventFlags = 1 << iota
	UserDropped
	KernelDropped
	EventIDsWrapped
	HistoryDone
	RootChanged
	Mount
	Unmount
	ItemCreated
	ItemRemoved
	ItemInodeMetaMod
	ItemRenamed
	ItemModified
	ItemFinderInfoMod
	ItemChangeOwner
	ItemXattrMod
	ItemIsFile
	ItemIsDir
	ItemIsSymlink
)
type Event struct {
	Path  string
	Flags EventFlags
	ID    uint64
}
func fsevtCallback(stream C.FSEventStreamRef, info uintptr, numEvents C.size_t, paths **C.char, flags *C.FSEventStreamEventFlags, ids *C.FSEventStreamEventId) {
	events := make([]Event, int(numEvents))
	es := registry.Get(info)
	if es == nil {
		return
	}
	for i := 0; i < int(numEvents); i++ {
		cpaths := uintptr(unsafe.Pointer(paths)) + (uintptr(i) * unsafe.Sizeof(*paths))
		cpath := *(**C.char)(unsafe.Pointer(cpaths))
		cflags := uintptr(unsafe.Pointer(flags)) + (uintptr(i) * unsafe.Sizeof(*flags))
		cflag := *(*C.FSEventStreamEventFlags)(unsafe.Pointer(cflags))
		cids := uintptr(unsafe.Pointer(ids)) + (uintptr(i) * unsafe.Sizeof(*ids))
		cid := *(*C.FSEventStreamEventId)(unsafe.Pointer(cids))
		events[i] = Event{Path: C.GoString(cpath), Flags: EventFlags(cflag), ID: uint64(cid)}
		es.EventID = uint64(cid)
	}
	es.Events <- events
}
func LatestEventID() uint64 {
	return uint64(C.FSEventsGetCurrentEventId())
}
func DeviceForPath(path string) (int32, error) {
	stat := syscall.Stat_t{}
	if err := syscall.Lstat(path, &stat); err != nil {
		return 0, err
	}
	return stat.Dev, nil
}
func EventIDForDeviceBeforeTime(dev int32, before time.Time) uint64 {
	tm := C.CFAbsoluteTime(before.Unix())
	return uint64(C.FSEventsGetLastEventIdForDeviceBeforeTime(C.dev_t(dev), tm))
}
type EventStream struct {
	stream       C.FSEventStreamRef
	rlref        C.CFRunLoopRef
	hasFinalizer bool
	registryID   uintptr
	Events  chan []Event
	Paths   []string
	Flags   CreateFlags
	EventID uint64
	Resume  bool
	Latency time.Duration
	Device  int32
}
type eventStreamRegistry struct {
	sync.Mutex
	m map[uintptr]*EventStream
	i uintptr
}
var registry = eventStreamRegistry{m: map[uintptr]*EventStream{}}
func (r *eventStreamRegistry) Add(e *EventStream) uintptr {
	r.Lock()
	defer r.Unlock()
	r.i++
	r.m[r.i] = e
	return r.i
}
func (r *eventStreamRegistry) Get(i uintptr) *EventStream {
	r.Lock()
	defer r.Unlock()
	return r.m[i]
}
func (r *eventStreamRegistry) Delete(i uintptr) {
	r.Lock()
	defer r.Unlock()
	delete(r.m, i)
}
func finalizer(es *EventStream) {
	es.Stop()
}
func (es *EventStream) Start() {
	cPaths := C.ArrayCreateMutable(C.int(len(es.Paths)))
	defer C.CFRelease(C.CFTypeRef(cPaths))
	for _, p := range es.Paths {
		p, _ = filepath.Abs(p)
		cpath := C.CString(p)
		defer C.free(unsafe.Pointer(cpath))
		str := C.CFStringCreateWithCString(nil, cpath, C.kCFStringEncodingUTF8)
		C.CFArrayAppendValue(cPaths, unsafe.Pointer(str))
	}
	since := C.FSEventStreamEventId(EventIDSinceNow)
	if es.Resume {
		since = C.FSEventStreamEventId(es.EventID)
	}
	if es.Events == nil {
		es.Events = make(chan []Event)
	}
	es.registryID = registry.Add(es)
	context := C.FSEventStreamContext{}
	info := C.uintptr_t(es.registryID)
	latency := C.CFTimeInterval(float64(es.Latency) / float64(time.Second))
	if es.Device != 0 {
		es.stream = C.EventStreamCreateRelativeToDevice(&context, info, C.dev_t(es.Device), cPaths, since, latency, C.FSEventStreamCreateFlags(es.Flags))
	} else {
		es.stream = C.EventStreamCreate(&context, info, cPaths, since, latency, C.FSEventStreamCreateFlags(es.Flags))
	}
	go func() {
		runtime.LockOSThread()
		es.rlref = C.CFRunLoopGetCurrent()
		C.FSEventStreamScheduleWithRunLoop(es.stream, es.rlref, C.kCFRunLoopDefaultMode)
		C.FSEventStreamStart(es.stream)
		C.CFRunLoopRun()
	}()
	if !es.hasFinalizer {
		runtime.SetFinalizer(es, finalizer)
		es.hasFinalizer = true
	}
}