Easily interface the filesystem with eventmachine.
Ruby
Switch branches/tags
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
.gitignore
.rspec
.rvmrc
Gemfile
Guardfile
LICENSE
README.md
Rakefile
em-fs.gemspec

README.md

EM::FS

EM::FS provides a simple interface to gain simple filesystem access in eventmachine via EM::SystemCommand.

EM::FileUtils attempts to mimic the behavoir of the filesystem API of the Ruby stdlib. In the background it invokes linux/unix system commands - like rsync, mkdir etc. - via the em-systemcommand gem.

Furthermore EM::Dir and EM::File provide abstractions to crawl directory structures via find command without blocking the reactor.

Installation

Add this line to your application's Gemfile:

gem 'em-fs'

And then execute:

$ bundle

Or install it yourself as:

$ gem install em-fs

Usage

EM::FS using rsync and find

To invoke bare commands you can either use EM::SystemCommand directly or the methods EM::FS.rsync and EM::FS.find.

EM::FileUtils for simple filesystem operations

The FileUtils methods from the Ruby Standard Library may block the eventmachine reactor. That´s why em-fs uses EM::SystemCommand to provide a similar non-blocking feature set.

EM.run do
  EM::FileUtils.cp 'some_file', 'some_copy' do |on|
    on.exit do |status|
      puts 'Copied!'
    end
  end
end

For a full list of methods, have a look at the documentation.

Abstraction via EM::Dir and EM::File

EM::Dir[] returns a EM::Dir::Glob object, containing the information for the find command. On this object you can invoke multiple methods to see the resulting filesystem objects:

EM::Dir['./**/*.*'].each do |stat|
  puts "Some stat: #{stat.inspect}"
end

EM::Dir['./**/*.lisp'].each_entry do |entry|
  puts "Some entry: #{entry}"
end

EM::Dir['./**/*.rb'].each_path do |path|
  puts "Some path: #{path}"
end

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request