Skip to content

Instantly share code, notes, and snippets.

@JoeUX
Last active October 5, 2018 06:07
Show Gist options
  • Save JoeUX/cc3584439ebd5fac66a5bf8a9620180b to your computer and use it in GitHub Desktop.
Save JoeUX/cc3584439ebd5fac66a5bf8a9620180b to your computer and use it in GitHub Desktop.
Rust example
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