Watch for file changes in a directory with a unified API on Linux and macOS.
Overvie
Detecting file changes is an OS-specific task, and the implementation differs on each major platform. While Linux uses
sys/inotify, macOS lacks this functionality and provide FSEventStream. Even though there are many examples available
for specific platforms, the interfaces still differ.
To address this, we have created the FileMonitor package. We have included code from various sources, which were not
actively maintained, to provide a reliable and consistent interface for detecting file changes in a directory across
all supported platforms.
Features
FileMonitor focuses on monitoring file changes within a given directory. It offers the following features:
Detection of file creations
Detection of file modifications
Detection of file deletions
All events are propagated through a delegate function using a switchable enum type.
Installation
FileMonitor can be easily installed using the Swift Package Manager. Simply add the following line to your dependencies
in your Package.swift file:
You can find a command-line application example in Sources/FileMonitorExample.
Compatibility
FileMonitor is compatible with Swift 5.7+ on macOS and Linux platforms.
[x] MacOS
[x] Linux
[] Windows
Contributing
Thank you for considering contributing to the FileMonitor Swift package! Contributions are welcome and greatly
appreciated.
If you encounter any bugs or have ideas for new features, please open an issue on the GitHub repository. When opening
an issue, please provide as much detail as possible, including steps to reproduce the issue or a clear description of
the new feature.
Pull Requests (PRs) are also welcome! If you have implemented a bug fix or added a new feature, follow these steps to
submit a PR:
Fork the repository and create your branch from main.
Make your changes, ensuring that you follow the code style and conventions used in the package.
Write tests to cover your changes, if applicable.
Ensure that all existing tests pass.
Update the documentation and README.md if necessary.
Commit your changes with a descriptive commit message.
Push your branch to your forked repository.
Open a PR on the main repository, providing a detailed description of your changes.
Please note that all contributions will be reviewed by the maintainers, who may provide feedback or request modifications before merging the changes.
Credits
This package builds on the shoulders of giants. We took existing code and cleaned it up, providing a unified interface
that looks the same across all target machines.
FileMonitor
Watch for file changes in a directory with a unified API on Linux and macOS.
Overvie
Detecting file changes is an OS-specific task, and the implementation differs on each major platform. While Linux uses sys/inotify, macOS lacks this functionality and provide
FSEventStream
. Even though there are many examples available for specific platforms, the interfaces still differ.To address this, we have created the FileMonitor package. We have included code from various sources, which were not actively maintained, to provide a reliable and consistent interface for detecting file changes in a directory across all supported platforms.
Features
FileMonitor focuses on monitoring file changes within a given directory. It offers the following features:
All events are propagated through a delegate function using a switchable enum type.
Installation
FileMonitor can be easily installed using the Swift Package Manager. Simply add the following line to your dependencies in your Package.swift file:
Don’t forget to add the product “FileMonitor” as a dependency for your target:
Usage
To use FileMonitor, follow this example:
You can find a command-line application example in Sources/FileMonitorExample.
Compatibility
FileMonitor is compatible with Swift 5.7+ on macOS and Linux platforms.
[x] MacOS [x] Linux [] Windows
Contributing
Thank you for considering contributing to the FileMonitor Swift package! Contributions are welcome and greatly appreciated.
If you encounter any bugs or have ideas for new features, please open an issue on the GitHub repository. When opening an issue, please provide as much detail as possible, including steps to reproduce the issue or a clear description of the new feature.
Pull Requests (PRs) are also welcome! If you have implemented a bug fix or added a new feature, follow these steps to submit a PR:
Fork the repository and create your branch from main.
Make your changes, ensuring that you follow the code style and conventions used in the package.
Write tests to cover your changes, if applicable.
Ensure that all existing tests pass.
Update the documentation and README.md if necessary.
Commit your changes with a descriptive commit message.
Push your branch to your forked repository.
Open a PR on the main repository, providing a detailed description of your changes.
Please note that all contributions will be reviewed by the maintainers, who may provide feedback or request modifications before merging the changes.
Credits
This package builds on the shoulders of giants. We took existing code and cleaned it up, providing a unified interface that looks the same across all target machines.
This software is heavily inspired by
LICENSE
The FileMonitor Swift package is released under the MIT License.