Last active
October 5, 2018 06:07
-
-
Save JoeUX/cc3584439ebd5fac66a5bf8a9620180b to your computer and use it in GitHub Desktop.
Rust example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn process(from: &Path, to: &Path) -> IoResult<()> { | |
// creates a new tempdir with the specified suffix | |
let tempdir = try!(TempDir::new("skylight")); | |
// open the input file | |
let mut from_file = try!(File::open(from)); | |
// create a temporary file inside the tempdir | |
let mut tempfile = | |
try!(File::create(&tempdir.path().join("tmp1"))); | |
// copy the input file into the tempfile | |
try!(io::util::copy(&mut from_file, &mut tempfile)); | |
// use an external program to process the tmpfile in place | |
// after processing, copy the tempfile into the output file | |
let mut out = try!(File::create(to)); | |
io::util::copy(&mut tempfile, &mut out) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment