https://github.com/leoborai/file-copycat
A library that writes a copy of a watched file on write with optionally replacing bytes on write.
https://github.com/leoborai/file-copycat
copycat cow fs rust watcher
Last synced: 4 months ago
JSON representation
A library that writes a copy of a watched file on write with optionally replacing bytes on write.
- Host: GitHub
- URL: https://github.com/leoborai/file-copycat
- Owner: LeoBorai
- Created: 2021-10-07T21:45:24.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-10-07T21:50:27.000Z (over 3 years ago)
- Last Synced: 2025-02-28T20:58:57.561Z (4 months ago)
- Topics: copycat, cow, fs, rust, watcher
- Language: Rust
- Homepage:
- Size: 1000 Bytes
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
This crate is a WIP.
## Usage
Create a new binary crate and reference this crate wherever it is:
```toml
[package]
name = "test-file-copycat"
version = "0.1.0"
edition = "2018"# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
file-copycat = { path = "relative/path/to/the/crate" }
```Create two files, one is the input file you want to watch changes for
(`./testfile.txt`). The other is the output file you want to write on
(`./outputfile.txt`).Then paste the following code into the `main.rs` file
```rust
use file_copycat::watch;
use std::str::from_utf8;fn main() {
let replacer = |input: Vec| {
let mut utf8 = from_utf8(&input).unwrap();
let replaced = utf8.replace("hello", "goodbye");replaced.as_bytes().to_vec()
};if let Err(err) = watch("./testfile.txt", "./outputfile.txt", Box::new(replacer)) {
println!("{:?}", err);
}
}
```