atomic_write

Library for writing or apppending files atomically shards crystal-shards filesystem file files file-writing
0.1.0 released

file_atomic_write.cr

Extends/Overrides File to provide atomic_write() and atomic_append().

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.

Installation

Add this to your application's shard.yml:

dependencies:
  file_atomic_write:
    github: chris-huxtable/file_atomic_write.cr

Usage

require "file_atomic_write"

Atomic write:

File.atomic_write("some/path") { |fd| fd << "hello world" }

Atomic append:

File.atomic_append("some/path") { |fd| fd << "hello world" }

Contributing

  1. Fork it ( https://github.com/chris-huxtable/file_atomic_write.cr/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

atomic_write:
  github: chris-huxtable/atomic_write.cr
  version: ~> 0.1.0
License ISC
Crystal 0.24.2

Authors

Dependencies 0

Development Dependencies 0

Dependents 0

Last synced .
search fire star recently