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).
Currently this library polls the directories of interest recursively in certain intervals, but I will add OS-specific functionality to monitor the filesystem.
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 PollWatcher
- deltaDirWithCallbacks :: FilePath -> IO (CallbackWatcher PollWatcher)
- module System.Delta.Class
- class FileWatcher a where
- defaultWatcher :: FilePath -> IO a
- changedFiles :: a -> Event FileInfo
- newFiles :: a -> Event FilePath
- deletedFiles :: a -> Event FilePath
- cleanUpAndClose :: a -> IO ()
- mergeWatchers :: a -> a -> a
- watchPaths :: FileWatcher a => [FilePath] -> Maybe (IO a)
- module System.Delta.Callback
- data CallbackWatcher w
- data CallbackId
- withCallbacks :: FileWatcher a => a -> IO (CallbackWatcher a)
- withDeleteCallback :: FileWatcher a => CallbackWatcher a -> (FilePath -> IO ()) -> IO CallbackId
- withChangedCallback :: FileWatcher a => CallbackWatcher a -> (FileInfo -> IO ()) -> IO CallbackId
- withNewCallback :: FileWatcher a => CallbackWatcher a -> (FilePath -> IO ()) -> IO CallbackId
- unregisterCallback :: FileWatcher a => CallbackWatcher a -> CallbackId -> IO ()
- removeAllCallbacks :: FileWatcher a => CallbackWatcher a -> IO ()
- closeCallbackWatcher :: FileWatcher a => CallbackWatcher a -> IO ()
Documentation
module System.Delta.Base
module System.Delta.Poll
Important functions
deltaDir :: FilePath -> IO PollWatcher
Build a file watcher, this method will change later
deltaDirWithCallbacks :: FilePath -> IO (CallbackWatcher PollWatcher)
Build a file watcher that allows to register callbacks
FRP based interface
module System.Delta.Class
class FileWatcher a where
A class for watching a directory based on functional reactive programming At the core of this class are three event streams:
defaultWatcher :: FilePath -> IO a
Each type provides a default watcher for a pass
changedFiles :: a -> Event FileInfo
An event that gives some info on changed files (disjunct from deleted and new files)
newFiles :: a -> Event FilePath
An event that fires for each new file
deletedFiles :: a -> Event FilePath
An event that fires for each deleted path
cleanUpAndClose :: a -> IO ()
Free all possibly used resources. No event will fire after this.
mergeWatchers :: a -> a -> a
Merge two watchers that are watching different directories
watchPaths :: FileWatcher a => [FilePath] -> Maybe (IO a)
Create a watcher on all of the given paths
Callback based interface
module System.Delta.Callback
data CallbackWatcher w
Provides a callback based interface to an FRP base FileWatcher
withCallbacks :: FileWatcher a => a -> IO (CallbackWatcher a)
Wrap a file watcher in a datatype that allows adding callbacks
Adding callbacks
:: FileWatcher a | |
=> CallbackWatcher a | |
-> (FilePath -> IO ()) | An IO action on the deleted path |
-> IO CallbackId |
Add a callback that is executed when file deletion is detected
:: FileWatcher a | |
=> CallbackWatcher a | |
-> (FileInfo -> IO ()) | Action on changed file |
-> IO CallbackId |
Add a callback on a changed file
:: FileWatcher a | |
=> CallbackWatcher a | |
-> (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 :: FileWatcher a => CallbackWatcher a -> CallbackId -> IO ()
Unregister the given CallbackId from the FileWatcher does nothing if the CallbackId is not in the watcher
removeAllCallbacks :: FileWatcher a => CallbackWatcher a -> IO ()
Remove all callbacks form the watcher. They will not be called after this
closeCallbackWatcher :: FileWatcher a => CallbackWatcher a -> IO ()
Remove all callbacks and close the underlying FileWatcher