fsevent-stream
Stream-based FSEvents
API bindings.
Features
- Support directory-granular and file-granular events.
- Retrieve related file inode with
kFSEventStreamCreateFlagUseExtendedData
.
Example
use std::path::Path;
use std::time::Duration;
use fsevent_stream::ffi::{
kFSEventStreamCreateFlagFileEvents, kFSEventStreamCreateFlagNoDefer,
kFSEventStreamCreateFlagUseCFTypes, kFSEventStreamCreateFlagUseExtendedData,
kFSEventStreamEventIdSinceNow,
};
use fsevent_stream::stream::create_event_stream;
use futures_util::StreamExt;
let (stream, handler) = create_event_stream(
[Path::new(".")],
kFSEventStreamEventIdSinceNow,
Duration::ZERO,
kFSEventStreamCreateFlagNoDefer
| kFSEventStreamCreateFlagFileEvents
| kFSEventStreamCreateFlagUseExtendedData
| kFSEventStreamCreateFlagUseCFTypes,
)
.expect("stream to be created");
let mut stream = stream.into_flatten();
while let Some(event) = stream.next().await {
println!(
"[{}] path: {:?}({}), flags: {} ({:x})",
event.id,
event.path,
event.inode.unwrap_or(-1),
event.flags,
event.raw_flags
);
}
Runtime Support
Both tokio
and async-std
are supported via feature flags.
tokio
support is enabled by default. To enable async-std
support, disable default features and enable async-std
feature.
Acknowledgement
Some code in this project is adapted from the following projects:
License
This project is licensed under MIT License.