streamly-fsnotify: Folder watching as a Streamly stream.

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

Provides Streamly streams for both single-level and recursive folder watching. Also contains a principled and compositional system for filtering file system events.


[Skip to Readme]

Properties

Versions 1.0.0.0, 1.0.0.1, 1.0.0.1, 1.0.1.0, 1.1.0.0, 1.1.1.0
Change log CHANGELOG.md
Dependencies base (>=4.9 && <5), fsnotify (>=0.3.0.1 && <0.4.0.0), paths (>=0.2.0.0 && <0.3.0.0), semirings (>=0.5.2 && <0.6.0), streamly (>=0.7.0 && <0.8.0), text (>=1.2.4.0 && <1.3.0.0), time (>=1.1 && <2.0.0) [details]
License GPL-3.0-or-later
Copyright (C) Koz Ross 2019
Author Koz Ross
Maintainer koz.ross@retro-freedom.nz
Category Streamly
Home page https://notabug.org/koz.ross/streamly-fsnotify
Uploaded by koz_ross at 2019-12-08T23:02:40Z

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for streamly-fsnotify-1.0.0.1

[back to package description]

streamly-fsnotify

What's the deal with this library?

streamly is an undoubtedly awesome library - fast, flexible, and well-documented. File system watching is a natural fit for a streaming library, and this is exactly what streamly-notify provides you.

As an example, here is a program which watches /home/koz/c-project/ and any of its subdirectories for added or modified C source files (which we take to be anything with a .c extension). This program then writes that the event occurred, to what file, and when, forever.


{-# LANGUAGE LambdaCase #-}

import Streamly.FSNotify (EventPredicate,
                          hasExtension, is Directory, invert, isDeletion, conj,
                          watchTree)
import System.Path (FsPath, FileExt, fromFilePath)

import qualified Streamly.Prelude as SP

-- conj -> both must be true
-- invert -> true when the argument would be false and vice versa
isCSourceFile :: EventPredicate
isCSourceFile = hasExtension (FileExt "c") `conj` (invert isDirectory)

notDeletion :: EventPredicate
notDeletion = invert isDeletion

srcPath :: FsPath
srcPath = fromFilePath "/home/koz/c-project"

-- first value given by watchTree stops the watcher
-- we don't use it here, but if you want to, just call it
main :: IO ()
main = do (_, stream) <- watchTree srcPath (isCSourceFile `conj` notDeletion)
          SP.drain . SP.mapM go $ stream
  where go = \case (Added p t _) -> putStrLn ("Created: " ++ show p ++ " at " ++ show t)
                   (Modified p t _) -> putStrLn ("Modified: " ++ show p ++ " at " ++ show t)
                   _ -> pure ()

That seems pretty cool! What kind of features can I expect?

Sounds good? Can I use it?

We've test-built this library for GHCs 8.2.2 through 8.8.1 on GNU/Linux. In theory, streamly-fsnotify should work everywhere both streamly and fsnotify will, which includes older GHCs (7.10) and other OSes (such as Windows). However, we haven't tried it ourselves - let us know if you do!

License

This library is under the GNU General Public License, version 3 or later (SPDX code GPL-3.0-or-later). For more details, see the LICENSE.md file.