Extends File
to provide atomic_write()
, atomic_replace()
.
An atomic write creates a new file at a temporary path. It then writes the new file contents to that file. Lastly it renames it to the original path. This dramatically reduces the opportunity for file corruption.
Add this to your application's shard.yml
:
dependencies:
atomic_write:
github: chris-huxtable/atomic_write.cr
require "atomic_write"
Atomic write:
File.atomic_write("some/path") { |fd| fd << "hello world" }
Atomic append:
File.atomic_write("some/path", append: true) { |fd| fd << "hello world" }
Atomic copy:
File.atomic_copy("some/src/path", "some/dst/path")
Atomic replace:
File.atomic_replace("some/src/path") { |src_fd, dst_fd| dst_fd << "hello" << src_fd.gets_to_end }
- Fork it ( https://github.com/chris-huxtable/atomic_write.cr/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
- Chris Huxtable - creator, maintainer