Skip to content

A library that writes a copy of a watched file on write with optionally replacing bytes on write.

Notifications You must be signed in to change notification settings

EstebanBorai/file-copycat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

This crate is a WIP.

Usage

Create a new binary crate and reference this crate wherever it is:

[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

use file_copycat::watch;
use std::str::from_utf8;

fn main() {
    let replacer = |input: Vec<u8>| {
        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);
    }
}

About

A library that writes a copy of a watched file on write with optionally replacing bytes on write.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages