Copyright | (c) Christof Schramm 2015 |
---|---|
License | LGPL v2 |
Maintainer | Christof Schramm |
Stability | Experimental |
Safe Haskell | None |
Language | Haskell2010 |
Description
An umberella package for the delta library. This library can be used to monitor changed new deleted files in a given directory (or set of directories).
On non OS X systems this library polls the directories of interest recursively in certain intervals, but I will add OS-specific functionality to monitor the filesystem.
On OS X this library can use the File System Events API to detect changes without recursive directory traversal.
Examples
Create a watcher that prints a line if a new file is created in the monitored directory:
printNewFilePaths basePath = do watcher <- deltaDirWithCallbacks basePath withNewCallback watcher (\x -> putStrLn $ "new file: " ++ x)
- module System.Delta.Base
- module System.Delta.Poll
- deltaDir :: FilePath -> IO FileWatcher
- deltaDirWithCallbacks :: FilePath -> IO CallbackWatcher
- data FileWatcher = FileWatcher {
- newFiles :: Event FilePath
- deletedFiles :: Event FilePath
- changedFiles :: Event FilePath
- cleanUpAndClose :: IO ()
- data CallbackWatcher
- data CallbackId
- withCallbacks :: FileWatcher -> IO CallbackWatcher
- withDeleteCallback :: CallbackWatcher -> (FilePath -> IO ()) -> IO CallbackId
- withChangedCallback :: CallbackWatcher -> (FilePath -> IO ()) -> IO CallbackId
- withNewCallback :: CallbackWatcher -> (FilePath -> IO ()) -> IO CallbackId
- unregisterCallback :: CallbackWatcher -> CallbackId -> IO ()
- removeAllCallbacks :: CallbackWatcher -> IO ()
- closeCallbackWatcher :: CallbackWatcher -> IO ()
Documentation
module System.Delta.Base
module System.Delta.Poll
Important functions
deltaDir :: FilePath -> IO FileWatcher Source
Build a file watcher, the concrete implementation is operating system dependent.
- The default uses polling (
createPollWatcher
) - The watcher for OS X uses the FS Events API
createFSEventsWatcher
deltaDirWithCallbacks :: FilePath -> IO CallbackWatcher Source
Build a file watcher that allows to register callbacks
FRP based interface
data FileWatcher Source
A type for watching a directory based on functional reactive programming At the core of this class are three event streams:
FileWatcher | |
|
Callback based interface
data CallbackWatcher Source
Provides a callback based interface to an FRP base FileWatcher
withCallbacks :: FileWatcher -> IO CallbackWatcher Source
Wrap a file watcher in a datatype that allows adding callbacks
Adding callbacks
:: CallbackWatcher | |
-> (FilePath -> IO ()) | An IO action on the deleted path |
-> IO CallbackId |
Add a callback that is executed when file deletion is detected
:: CallbackWatcher | |
-> (FilePath -> IO ()) | Action on changed file |
-> IO CallbackId |
Add a callback on a changed file
:: CallbackWatcher | |
-> (FilePath -> IO ()) | An IO action on the new path |
-> IO CallbackId |
Add a callback that is executed when file creation is detected
Removing callbacks
unregisterCallback :: CallbackWatcher -> CallbackId -> IO () Source
Unregister the given CallbackId from the FileWatcher does nothing if the CallbackId is not in the watcher
removeAllCallbacks :: CallbackWatcher -> IO () Source
Remove all callbacks form the watcher. They will not be called after this
closeCallbackWatcher :: CallbackWatcher -> IO () Source
Remove all callbacks and close the underlying FileWatcher