mkfifo.cr

A Crystal implementation of File.mkfifo

mkfifo

This small library monkey patches File to add two new class methods: fifo and fifo?.

I made this because:

  1. I need it for my hobby project
  2. I found this dicussion about it, so others need it too

It's basically a copy of Ruby's File.mkfifo, but I changed the permissions to match Crystal's default for new files.

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      mkfifo:
        github: tijn/mkfifo
    
  2. Run shards install

Usage

require "mkfifo"

path = File.tempname
File.mkfifo(path)
File.fifo?(path) # ==> true

# read from the fifo, for example
File.each_line(path) do |line|
  puts line
end

# or write to it:
File.open(path) do |fifo|
  fifo.puts("foo and bar")
end

Contributing

  1. Fork it (https://github.com/tijn/mkfifo/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

Alternatives

I just found fifo.cr which takes a different approach, that is arguably somewhat cleaner since it avoids monkey patching.

Repository

mkfifo.cr

Owner
Statistic
  • 1
  • 0
  • 0
  • 0
  • 0
  • almost 3 years ago
  • January 29, 2022
License

MIT License

Links
Synced at

Thu, 07 Nov 2024 09:22:45 GMT

Languages