ProductPromotion
Logo

Elixir

made by https://0x3d.site

GitHub - falood/file_system: Filesystem monitor for elixir
Filesystem monitor for elixir. Contribute to falood/file_system development by creating an account on GitHub.
Visit Site

GitHub - falood/file_system: Filesystem monitor for elixir

GitHub - falood/file_system: Filesystem monitor for elixir

FileSystem

Module Version Hex Docs Total Download License Last Updated CI Linux CI MacOS CI Windows

An Elixir file change watcher wrapper based on FS, the native file system listener.

System Support

On MacOS 10.14, to compile mac_listener, run:

open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

On newer versions this file doesn't exist. But it still should work just fine as long as you have xcode installed.

Usage

Add file_system to the deps of your mix.exs

defmodule MyApp.Mixfile do
  use Mix.Project

  def project do
  ...
  end

  defp deps do
    [
      {:file_system, "~> 1.0", only: :test},
    ]
  end
  ...
end

Subscription API

You can spawn a worker and subscribe to events from it:

{:ok, pid} = FileSystem.start_link(dirs: ["/path/to/some/files"])
FileSystem.subscribe(pid)

or

{:ok, pid} = FileSystem.start_link(dirs: ["/path/to/some/files"], name: :my_monitor_name)
FileSystem.subscribe(:my_monitor_name)

The pid you subscribed from will now receive messages like:

{:file_event, worker_pid, {file_path, events}}

and

{:file_event, worker_pid, :stop}

Example Using GenServer

defmodule Watcher do
  use GenServer

  def start_link(args) do
    GenServer.start_link(__MODULE__, args)
  end

  def init(args) do
    {:ok, watcher_pid} = FileSystem.start_link(args)
    FileSystem.subscribe(watcher_pid)
    {:ok, %{watcher_pid: watcher_pid}}
  end

  def handle_info({:file_event, watcher_pid, {path, events}}, %{watcher_pid: watcher_pid} = state) do
    # Your own logic for path and events
    {:noreply, state}
  end

  def handle_info({:file_event, watcher_pid, :stop}, %{watcher_pid: watcher_pid} = state) do
    # Your own logic when monitor stop
    {:noreply, state}
  end
end

Backend Options

For each platform, you can pass extra options to the underlying listener process.

Each backend supports different extra options, check backend module documentation for more details.

Here is an example to get instant notifications on file changes for MacOS:

FileSystem.start_link(dirs: ["/path/to/some/files"], latency: 0, watch_root: true)

Articles
to learn more about the elixir concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about Elixir.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory