Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/chris-huxtable/atomic_write.cr
Extends `File` to provide `atomic_write()`.
https://github.com/chris-huxtable/atomic_write.cr
crystal crystal-language crystal-shards file file-writing files filesystem shards
Last synced: about 2 months ago
JSON representation
Extends `File` to provide `atomic_write()`.
- Host: GitHub
- URL: https://github.com/chris-huxtable/atomic_write.cr
- Owner: chris-huxtable
- License: isc
- Created: 2018-05-17T00:29:31.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-03-23T15:08:01.000Z (over 2 years ago)
- Last Synced: 2024-06-22T02:07:05.194Z (3 months ago)
- Topics: crystal, crystal-language, crystal-shards, file, file-writing, files, filesystem, shards
- Language: Crystal
- Homepage:
- Size: 41 KB
- Stars: 11
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-crystal - atomic_write.cr - Library for writing or apppending files atomically (Misc)
- awesome-crystal - atomic_write.cr - Library for writing or apppending files atomically (Misc)
README
# atomic_write.cr
[![Docs](https://img.shields.io/badge/docs-available-brightgreen.svg)](https://chris-huxtable.github.io/atomic_write.cr/)
[![GitHub release](https://img.shields.io/github/release/chris-huxtable/atomic_write.cr.svg)](https://github.com/chris-huxtable/atomic_write.cr/releases)
[![Crystal CI](https://github.com/chris-huxtable/atomic_write.cr/actions/workflows/crystal.yml/badge.svg)](https://github.com/chris-huxtable/atomic_write.cr/actions/workflows/crystal.yml)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.## Installation
Add this to your application's `shard.yml`:
```yaml
dependencies:
atomic_write:
github: chris-huxtable/atomic_write.cr
```## Usage
```crystal
require "atomic_write"
```Atomic write:
```crystal
File.atomic_write("some/path") { |fd| fd << "hello world" }
```Atomic append:
```crystal
File.atomic_write("some/path", append: true) { |fd| fd << "hello world" }
```Atomic copy:
```crystal
File.atomic_copy("some/src/path", "some/dst/path")
```Atomic replace:
```crystal
File.atomic_replace("some/src/path") { |src_fd, dst_fd| dst_fd << "hello" << src_fd.gets_to_end }
```## Contributing
1. Fork it ( https://github.com/chris-huxtable/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
- [Chris Huxtable](https://github.com/chris-huxtable) - creator, maintainer